github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/hpa.cue (about)

     1  hpa: {
     2  	type: "trait"
     3  	annotations: {}
     4  	labels: {}
     5  	description: "Configure k8s HPA for Deployment or Statefulsets"
     6  	attributes: {
     7  		podDisruptive: false
     8  		appliesToWorkloads: ["deployments.apps", "statefulsets.apps"]
     9  	}
    10  }
    11  template: {
    12  	outputs: hpa: {
    13  		if context.clusterVersion.minor < 23 {
    14  			apiVersion: "autoscaling/v2beta2"
    15  		}
    16  		if context.clusterVersion.minor >= 23 {
    17  			apiVersion: "autoscaling/v2"
    18  		}
    19  		kind: "HorizontalPodAutoscaler"
    20  		metadata: name: context.name
    21  		spec: {
    22  			scaleTargetRef: {
    23  				apiVersion: parameter.targetAPIVersion
    24  				kind:       parameter.targetKind
    25  				name:       context.name
    26  			}
    27  			minReplicas: parameter.min
    28  			maxReplicas: parameter.max
    29  			metrics: [
    30  				{
    31  					type: "Resource"
    32  					resource: {
    33  						name: "cpu"
    34  						target: {
    35  							type: parameter.cpu.type
    36  							if parameter.cpu.type == "Utilization" {
    37  								averageUtilization: parameter.cpu.value
    38  							}
    39  							if parameter.cpu.type == "AverageValue" {
    40  								averageValue: parameter.cpu.value
    41  							}
    42  						}
    43  					}
    44  				},
    45  				if parameter.mem != _|_ {
    46  					{
    47  						type: "Resource"
    48  						resource: {
    49  							name: "memory"
    50  							target: {
    51  								type: parameter.mem.type
    52  								if parameter.mem.type == "Utilization" {
    53  									averageUtilization: parameter.mem.value
    54  								}
    55  								if parameter.mem.type == "AverageValue" {
    56  									averageValue: parameter.mem.value
    57  								}
    58  							}
    59  						}
    60  					}
    61  				},
    62  				if parameter.podCustomMetrics != _|_ for m in parameter.podCustomMetrics {
    63  					type: "Pods"
    64  					pods: {
    65  						metric: {
    66  							name: m.name
    67  						}
    68  						target: {
    69  							type:         "AverageValue"
    70  							averageValue: m.value
    71  						}
    72  					}
    73  				},
    74  			]
    75  		}
    76  	}
    77  	parameter: {
    78  		// +usage=Specify the minimal number of replicas to which the autoscaler can scale down
    79  		min: *1 | int
    80  		// +usage=Specify the maximum number of of replicas to which the autoscaler can scale up
    81  		max: *10 | int
    82  		// +usage=Specify the apiVersion of scale target
    83  		targetAPIVersion: *"apps/v1" | string
    84  		// +usage=Specify the kind of scale target
    85  		targetKind: *"Deployment" | string
    86  		cpu: {
    87  			// +usage=Specify resource metrics in terms of percentage("Utilization") or direct value("AverageValue")
    88  			type: *"Utilization" | "AverageValue"
    89  			// +usage=Specify the value of CPU utilization or averageValue
    90  			value: *50 | int
    91  		}
    92  		mem?: {
    93  			// +usage=Specify resource metrics in terms of percentage("Utilization") or direct value("AverageValue")
    94  			type: *"Utilization" | "AverageValue"
    95  			// +usage=Specify  the value of MEM utilization or averageValue
    96  			value: *50 | int
    97  		}
    98  		// +usage=Specify custom metrics of pod type
    99  		podCustomMetrics?: [...{
   100  			// +usage=Specify name of custom metrics
   101  			name: string
   102  			// +usage=Specify target value of custom metrics
   103  			value: string
   104  		}]
   105  	}
   106  }