github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/registry/autoscale.cue (about)

     1  import "strconv"
     2  
     3  autoscale: {
     4  	type: "trait"
     5  	annotations: {}
     6  	labels: {}
     7  	description: "Automatically scales workloads by resource utilization metrics or cron triggers."
     8  	attributes: {
     9  		podDisruptive: true
    10  		appliesToWorkloads: ["deployments.apps"]
    11  		workloadRefPath: "spec.workloadRef"
    12  		definitionRef: name: "autoscalers.standard.oam.dev"
    13  		extension: install: helm: {
    14  			repo:    "kedacore"
    15  			name:    "keda"
    16  			url:     "https://kedacore.github.io/charts"
    17  			version: "2.0.0-rc3"
    18  		}
    19  	}
    20  }
    21  template: {
    22  	outputs: autoscaler: {{
    23  		apiVersion: "standard.oam.dev/v1alpha1"
    24  		kind:       "Autoscaler"
    25  		spec: {
    26  			minReplicas: parameter.min
    27  			maxReplicas: parameter.max
    28  			if parameter["cpuPercent"] != _|_ && parameter["cron"] != _|_ {
    29  				triggers: [cpuScaler, cronScaler]
    30  			}
    31  			if parameter["cpuPercent"] != _|_ && parameter["cron"] == _|_ {
    32  				triggers: [cpuScaler]
    33  			}
    34  			if parameter["cpuPercent"] == _|_ && parameter["cron"] != _|_ {
    35  				triggers: [cronScaler]
    36  			}
    37  		}
    38  	}}
    39  	cpuScaler: {
    40  		type: "cpu"
    41  		condition: {
    42  			type: "Utilization"
    43  			if parameter["cpuPercent"] != _|_ {
    44  				// Temporarily use `strconv` for type converting. This bug will be fixed in kubevela#585
    45  				value: strconv.FormatInt(parameter.cpuPercent, 10)
    46  			}
    47  		}
    48  	}
    49  	cronScaler: {
    50  		type: "cron"
    51  		if parameter["cron"] != _|_ && parameter.cron["replicas"] != _|_ {
    52  			condition: {
    53  				startAt:  parameter.cron.startAt
    54  				duration: parameter.cron.duration
    55  				days:     parameter.cron.days
    56  				replicas: strconv.FormatInt(parameter.cron.replicas, 10)
    57  				timezone: parameter.cron.timezone
    58  			}
    59  		}
    60  	}
    61  	parameter: {
    62  		// +usage=Minimal replicas of the workload
    63  		min: int
    64  		// +usage=Maximal replicas of the workload
    65  		max: int
    66  		// +usage=Specify the value for CPU utilization, like 80, which means 80%
    67  		// +alias=cpu-percent
    68  		cpuPercent?: int
    69  		// +usage=Cron type auto-scaling. Just for `appfile`, not available for Cli usage
    70  		cron?: {
    71  			// +usage=The time to start scaling, like `08:00`
    72  			startAt: string
    73  			// +usage=For how long the scaling will last
    74  			duration: string
    75  			// +usage=Several workdays or weekends, like "Monday, Tuesday"
    76  			days: string
    77  			// +usage=The target replicas to be scaled to
    78  			replicas: int
    79  			// +usage=Timezone, like "America/Los_Angeles"
    80  			timezone: string
    81  		}
    82  	}
    83  }