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