chore(common): tweak/expand VPA test suite (#34626)
**Description** <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ⚒️ Fixes # <!--(issue)--> **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code - [ ] 📜 Documentation Changes **🧪 How Has This Been Tested?** <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> **📃 Notes:** <!-- Please enter any other relevant information here --> **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made changes to the documentation - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):`, `chore(chart-name):`, `docs(chart-name):` or `fix(docs):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._
This commit is contained in:
@@ -0,0 +1,181 @@
|
|||||||
|
suite: vpa spec test
|
||||||
|
templates:
|
||||||
|
- common.yaml
|
||||||
|
release:
|
||||||
|
name: test-release-name
|
||||||
|
namespace: test-release-namespace
|
||||||
|
tests:
|
||||||
|
- it: should create vpa
|
||||||
|
set:
|
||||||
|
workload: &workload
|
||||||
|
workload-name:
|
||||||
|
enabled: true
|
||||||
|
primary: true
|
||||||
|
type: Deployment
|
||||||
|
podSpec: {}
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
asserts:
|
||||||
|
- documentIndex: &vpaDoc 1
|
||||||
|
isKind:
|
||||||
|
of: VerticalPodAutoscaler
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
isAPIVersion:
|
||||||
|
of: autoscaling.k8s.io/v1
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
isSubset:
|
||||||
|
path: spec
|
||||||
|
content:
|
||||||
|
targetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: test-release-name-common-test
|
||||||
|
updatePolicy:
|
||||||
|
updateMode: Auto
|
||||||
|
|
||||||
|
- it: should create vpa with targetSelector
|
||||||
|
set:
|
||||||
|
workload:
|
||||||
|
workload-name:
|
||||||
|
enabled: true
|
||||||
|
primary: true
|
||||||
|
type: Deployment
|
||||||
|
podSpec: {}
|
||||||
|
workload-name-2:
|
||||||
|
enabled: true
|
||||||
|
type: Deployment
|
||||||
|
podSpec: {}
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
targetSelector:
|
||||||
|
- workload-name-2
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 3 # 2 Deployments, 1 VPA
|
||||||
|
- documentIndex: &vpaDoc 2
|
||||||
|
isKind:
|
||||||
|
of: VerticalPodAutoscaler
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
isAPIVersion:
|
||||||
|
of: autoscaling.k8s.io/v1
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
isSubset:
|
||||||
|
path: spec
|
||||||
|
content:
|
||||||
|
targetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: test-release-name-common-test-workload-name-2
|
||||||
|
updatePolicy:
|
||||||
|
updateMode: Auto
|
||||||
|
|
||||||
|
- it: should create vpa with options
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
updatePolicy:
|
||||||
|
minReplicas: 2
|
||||||
|
evictionRequirements:
|
||||||
|
- resources: ["cpu"]
|
||||||
|
changeRequirement: TargetHigherThanRequests
|
||||||
|
- resources: ["memory"]
|
||||||
|
changeRequirement: TargetLowerThanRequests
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
controlledResources: ["cpu", "memory"]
|
||||||
|
controlledValues: RequestsAndLimits
|
||||||
|
minAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1000Mi
|
||||||
|
maxAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1000Mi
|
||||||
|
asserts:
|
||||||
|
- documentIndex: &vpaDoc 1
|
||||||
|
isKind:
|
||||||
|
of: VerticalPodAutoscaler
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
isAPIVersion:
|
||||||
|
of: autoscaling.k8s.io/v1
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
equal:
|
||||||
|
path: spec.updatePolicy
|
||||||
|
value:
|
||||||
|
updateMode: Auto
|
||||||
|
minReplicas: 2
|
||||||
|
evictionRequirements:
|
||||||
|
- changeRequirement: TargetHigherThanRequests
|
||||||
|
resources: ["cpu"]
|
||||||
|
- changeRequirement: TargetLowerThanRequests
|
||||||
|
resources: ["memory"]
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
equal:
|
||||||
|
path: spec.resourcePolicy
|
||||||
|
value:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
controlledResources: ["cpu", "memory"]
|
||||||
|
controlledValues: RequestsAndLimits
|
||||||
|
minAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1000Mi
|
||||||
|
maxAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1000Mi
|
||||||
|
- it: should create vpa with containerPolicies options ignored when mode is Off
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
updatePolicy:
|
||||||
|
minReplicas: 2
|
||||||
|
evictionRequirements:
|
||||||
|
- resources: ["cpu"]
|
||||||
|
changeRequirement: TargetHigherThanRequests
|
||||||
|
- resources: ["memory"]
|
||||||
|
changeRequirement: TargetLowerThanRequests
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: "Off"
|
||||||
|
controlledResources: ["cpu", "memory"]
|
||||||
|
controlledValues: RequestsAndLimits
|
||||||
|
minAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1000Mi
|
||||||
|
maxAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1000Mi
|
||||||
|
asserts:
|
||||||
|
- documentIndex: &vpaDoc 1
|
||||||
|
isKind:
|
||||||
|
of: VerticalPodAutoscaler
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
isAPIVersion:
|
||||||
|
of: autoscaling.k8s.io/v1
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
equal:
|
||||||
|
path: spec.updatePolicy
|
||||||
|
value:
|
||||||
|
updateMode: Auto
|
||||||
|
minReplicas: 2
|
||||||
|
evictionRequirements:
|
||||||
|
- changeRequirement: TargetHigherThanRequests
|
||||||
|
resources: ["cpu"]
|
||||||
|
- changeRequirement: TargetLowerThanRequests
|
||||||
|
resources: ["memory"]
|
||||||
|
- documentIndex: *vpaDoc
|
||||||
|
equal:
|
||||||
|
path: spec.resourcePolicy
|
||||||
|
value:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: "Off"
|
||||||
@@ -61,7 +61,7 @@ tests:
|
|||||||
updatePolicy: "not a dict"
|
updatePolicy: "not a dict"
|
||||||
asserts:
|
asserts:
|
||||||
- failedTemplate:
|
- failedTemplate:
|
||||||
errorMessage: Vertical Pod Autoscaler - Expected [updatePolicy] to be a dictionary, but got [string]
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.updatePolicy] to be a dictionary, but got [string]
|
||||||
|
|
||||||
- it: should fail with updatePolicy.updateMode not valid
|
- it: should fail with updatePolicy.updateMode not valid
|
||||||
set:
|
set:
|
||||||
@@ -154,3 +154,186 @@ tests:
|
|||||||
asserts:
|
asserts:
|
||||||
- failedTemplate:
|
- failedTemplate:
|
||||||
errorMessage: Vertical Pod Autoscaler - Value [some-change-requirement] on [vpa.vpa-name.updatePolicy.evictionRequirements.0.changeRequirement] is not valid. Must be one of [TargetHigherThanRequests, TargetLowerThanRequests]
|
errorMessage: Vertical Pod Autoscaler - Value [some-change-requirement] on [vpa.vpa-name.updatePolicy.evictionRequirements.0.changeRequirement] is not valid. Must be one of [TargetHigherThanRequests, TargetLowerThanRequests]
|
||||||
|
|
||||||
|
- it: should fail with resourcePolicy.containerPolicies not a list
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies: not-a-list
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Value on [vpa.vpa-name.resourcePolicy.containerPolicies] must be a list, but got [string]
|
||||||
|
|
||||||
|
- it: should fail with resourcePolicy.containerPolicies item not a dict
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- item
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0] to be a dictionary, but got [string]
|
||||||
|
|
||||||
|
- it: should fail with invalid resourcePolicy.containerPolicies.#.containerName
|
||||||
|
set:
|
||||||
|
workload:
|
||||||
|
workload-name:
|
||||||
|
enabled: true
|
||||||
|
primary: true
|
||||||
|
type: Deployment
|
||||||
|
podSpec:
|
||||||
|
containers:
|
||||||
|
some-container:
|
||||||
|
enabled: true
|
||||||
|
primary: true
|
||||||
|
probes: &probes
|
||||||
|
readiness:
|
||||||
|
enabled: false
|
||||||
|
liveness:
|
||||||
|
enabled: false
|
||||||
|
startup:
|
||||||
|
enabled: false
|
||||||
|
some-other-container:
|
||||||
|
enabled: true
|
||||||
|
probes: *probes
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.containerName] is not valid. Must be one of [some-container, some-other-container, *]
|
||||||
|
|
||||||
|
- it: should fail with invalid resourcePolicy.containerPolicies.#.mode
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.mode] is not valid. Must be one of [Auto, Off]
|
||||||
|
|
||||||
|
- it: should fail with resourcePolicy.containerPolicies.controlledResources not a list
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
controlledResources: not-a-list
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.controlledResources] to be a list, but got [string]
|
||||||
|
|
||||||
|
- it: should fail with invalid item in resourcePolicy.containerPolicies.#.controlledResources
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
controlledResources:
|
||||||
|
- invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.controlledResources.0] is not valid. Must be one of [cpu, memory]
|
||||||
|
|
||||||
|
- it: should fail with invalid value in resourcePolicy.containerPolicies.#.controlledValues
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
controlledValues: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.controlledValues] is not valid. Must be one of [RequestsAndLimits, RequestsOnly]
|
||||||
|
|
||||||
|
- it: should fail with invalid cpu in minAllowed
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
minAllowed:
|
||||||
|
cpu: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.minAllowed.cpu] to have one of the following formats [(Plain Integer - eg. 1), (Float - eg. 0.5), (Milicpu - eg. 500m)], but got [invalid]
|
||||||
|
|
||||||
|
- it: should fail with invalid memory in minAllowed
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
minAllowed:
|
||||||
|
cpu: 1
|
||||||
|
memory: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.minAllowed.memory] to have one of the following formats [(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)], but got [invalid]
|
||||||
|
|
||||||
|
- it: should fail with invalid cpu in maxAllowed
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
maxAllowed:
|
||||||
|
cpu: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.maxAllowed.cpu] to have one of the following formats [(Plain Integer - eg. 1), (Float - eg. 0.5), (Milicpu - eg. 500m)], but got [invalid]
|
||||||
|
|
||||||
|
- it: should fail with invalid memory in maxAllowed
|
||||||
|
set:
|
||||||
|
workload: *workload
|
||||||
|
vpa:
|
||||||
|
vpa-name:
|
||||||
|
enabled: true
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
- containerName: "*"
|
||||||
|
mode: Auto
|
||||||
|
maxAllowed:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: invalid
|
||||||
|
asserts:
|
||||||
|
- failedTemplate:
|
||||||
|
errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.maxAllowed.memory] to have one of the following formats [(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)], but got [invalid]
|
||||||
|
|||||||
@@ -39,7 +39,39 @@ spec:
|
|||||||
{{- range $req := $objectData.updatePolicy.evictionRequirements }}
|
{{- range $req := $objectData.updatePolicy.evictionRequirements }}
|
||||||
- resources: {{ $req.resources | toJson }}
|
- resources: {{ $req.resources | toJson }}
|
||||||
changeRequirement: {{ $req.changeRequirement }}
|
changeRequirement: {{ $req.changeRequirement }}
|
||||||
{{- end }}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- if and $objectData.resourcePolicy $objectData.resourcePolicy.containerPolicies }}
|
||||||
|
resourcePolicy:
|
||||||
|
containerPolicies:
|
||||||
|
{{- range $cPol := $objectData.resourcePolicy.containerPolicies }}
|
||||||
|
- containerName: {{ $cPol.containerName | quote }}
|
||||||
|
mode: {{ $cPol.mode }}
|
||||||
|
{{- if eq $cPol.mode "Off" -}}{{- continue -}}{{- end }}
|
||||||
|
controlledValues: {{ $cPol.controlledValues | default "RequestsAndLimits" }}
|
||||||
|
{{- if $cPol.controlledResources }}
|
||||||
|
controlledResources: {{ $cPol.controlledResources | toJson }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- with $cPol.minAllowed -}}
|
||||||
|
{{- include "tc.v1.common.class.vpa.resources" (dict "item" "minAllowed" "resources" $cPol.minAllowed) | nindent 8 -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- with $cPol.maxAllowed -}}
|
||||||
|
{{- include "tc.v1.common.class.vpa.resources" (dict "item" "maxAllowed" "resources" $cPol.maxAllowed) | nindent 8 -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "tc.v1.common.class.vpa.resources" -}}
|
||||||
|
{{- $item := .item -}}
|
||||||
|
{{- $resources := .resources -}}
|
||||||
|
|
||||||
|
{{ $item }}:
|
||||||
|
{{- with $resources.cpu }}
|
||||||
|
cpu: {{ . }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- with $resources.memory }}
|
||||||
|
memory: {{ . }}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -46,6 +46,25 @@ limits:
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
|
||||||
|
{{- define "tc.v1.common.lib.resources.validation.data" -}}
|
||||||
|
{{/* CPU: https://regex101.com/r/D4HouI/1 */}}
|
||||||
|
{{/* MEM: https://regex101.com/r/NNPV2D/1 */}}
|
||||||
|
{{- $regex := (dict
|
||||||
|
"cpu" "^(0\\.[1-9]|[1-9][0-9]*)(\\.[0-9]|m?)$"
|
||||||
|
"memory" "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$"
|
||||||
|
) -}}
|
||||||
|
|
||||||
|
{{- $errorMsg := (dict
|
||||||
|
"cpu" "(Plain Integer - eg. 1), (Float - eg. 0.5), (Milicpu - eg. 500m)"
|
||||||
|
"memory" "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)"
|
||||||
|
) -}}
|
||||||
|
|
||||||
|
{{- $data := (dict "regex" $regex "errorMsg" $errorMsg) -}}
|
||||||
|
|
||||||
|
{{- $data | toJson -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
{{/* Validates resources to match a pattern */}}
|
{{/* Validates resources to match a pattern */}}
|
||||||
{{/* Call this template:
|
{{/* Call this template:
|
||||||
{{ include "tc.v1.common.lib.container.resources.validation" (dict "resources" $resources) }}
|
{{ include "tc.v1.common.lib.container.resources.validation" (dict "resources" $resources) }}
|
||||||
@@ -54,14 +73,9 @@ resources: The resources object
|
|||||||
*/}}
|
*/}}
|
||||||
{{- define "tc.v1.common.lib.container.resources.validation" -}}
|
{{- define "tc.v1.common.lib.container.resources.validation" -}}
|
||||||
{{- $resources := .resources -}}
|
{{- $resources := .resources -}}
|
||||||
{{/* CPU: https://regex101.com/r/D4HouI/1 */}}
|
{{- $data := (include "tc.v1.common.lib.resources.validation.data" .) | fromJson -}}
|
||||||
{{/* MEM: https://regex101.com/r/NNPV2D/1 */}}
|
{{- $regex := $data.regex -}}
|
||||||
{{- $regex := (dict
|
{{- $errorMsg := $data.errorMsg -}}
|
||||||
"cpu" "^(0\\.[1-9]|[1-9][0-9]*)(\\.[0-9]|m?)$"
|
|
||||||
"memory" "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$") -}}
|
|
||||||
{{- $errorMsg := (dict
|
|
||||||
"cpu" "(Plain Integer - eg. 1), (Float - eg. 0.5), (Milicpu - eg. 500m)"
|
|
||||||
"memory" "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)") -}}
|
|
||||||
|
|
||||||
{{- $resourceTypes := (list "cpu" "memory") -}}
|
{{- $resourceTypes := (list "cpu" "memory") -}}
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,12 @@
|
|||||||
{{- $updPolicy := $objectData.updatePolicy -}}
|
{{- $updPolicy := $objectData.updatePolicy -}}
|
||||||
{{- if $updPolicy -}}
|
{{- if $updPolicy -}}
|
||||||
{{- if not (kindIs "map" $updPolicy) -}}
|
{{- if not (kindIs "map" $updPolicy) -}}
|
||||||
{{- fail (printf "Vertical Pod Autoscaler - Expected [updatePolicy] to be a dictionary, but got [%s]" (kindOf $updPolicy)) -}}
|
{{- fail (printf "Vertical Pod Autoscaler - Expected [vpa.%s.updatePolicy] to be a dictionary, but got [%s]" $objectData.vpaName (kindOf $updPolicy)) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- if $updPolicy.updateMode -}}
|
{{- $validModes := list "Auto" "Off" "Initial" "Recreate" -}}
|
||||||
{{- $validModes := list "Auto" "Off" "Initial" "Recreate" -}}
|
{{- if and $updPolicy.updateMode (not (mustHas $updPolicy.updateMode $validModes)) -}}
|
||||||
{{- if not (mustHas $updPolicy.updateMode $validModes) -}}
|
{{- fail (printf "Vertical Pod Autoscaler - Value [%s] on [vpa.%s.updatePolicy.updateMode] is not valid. Must be one of [%s]" $updPolicy.updateMode $objectData.vpaName (join ", " $validModes)) -}}
|
||||||
{{- fail (printf "Vertical Pod Autoscaler - Value [%s] on [vpa.%s.updatePolicy.updateMode] is not valid. Must be one of [%s]" $updPolicy.updateMode $objectData.vpaName (join ", " $validModes)) -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- if and $updPolicy.minReplicas (le ($updPolicy.minReplicas | int) 0) -}}
|
{{- if and $updPolicy.minReplicas (le ($updPolicy.minReplicas | int) 0) -}}
|
||||||
@@ -50,6 +48,68 @@
|
|||||||
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $resPolicy := $objectData.resourcePolicy -}}
|
||||||
|
{{- if and $resPolicy $resPolicy.containerPolicies -}}
|
||||||
|
{{- if not (kindIs "slice" $resPolicy.containerPolicies) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Value on [vpa.%s.resourcePolicy.containerPolicies] must be a list, but got [%s]" $objectData.vpaName (kindOf $resPolicy.containerPolicies)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $validModes := (list "Auto" "Off") -}}
|
||||||
|
{{- range $idx, $cPol := $resPolicy.containerPolicies -}}
|
||||||
|
{{- if not (kindIs "map" $cPol) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Expected [vpa.%s.resourcePolicy.containerPolicies.%d] to be a dictionary, but got [%s]" $objectData.vpaName $idx (kindOf $cPol)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $validContainers := mustAppend $objectData.containerNames "*" -}}
|
||||||
|
{{- if not (mustHas $cPol.containerName $validContainers) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Value [%s] on [vpa.%s.resourcePolicy.containerPolicies.%d.containerName] is not valid. Must be one of [%s]" $cPol.containerName $objectData.vpaName $idx (join ", " $validContainers)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- if and $cPol.mode (not (mustHas $cPol.mode $validModes)) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Value [%s] on [vpa.%s.resourcePolicy.containerPolicies.%d.mode] is not valid. Must be one of [%s]" $cPol.mode $objectData.vpaName $idx (join ", " $validModes)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- if $cPol.controlledResources -}}
|
||||||
|
{{- if not (kindIs "slice" $cPol.controlledResources) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Expected [vpa.%s.resourcePolicy.containerPolicies.%d.controlledResources] to be a list, but got [%s]" $objectData.vpaName $idx (kindOf $cPol.controlledResources)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $validRes := (list "cpu" "memory") -}}
|
||||||
|
{{- range $x, $r := $cPol.controlledResources -}}
|
||||||
|
{{- if not (mustHas $r $validRes) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Value [%s] on [vpa.%s.resourcePolicy.containerPolicies.%d.controlledResources.%d] is not valid. Must be one of [%s]" $r $objectData.vpaName $idx $x (join ", " $validRes)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- if $cPol.controlledValues -}}
|
||||||
|
{{- $validVals := (list "RequestsAndLimits" "RequestsOnly") -}}
|
||||||
|
{{- if not (mustHas $cPol.controlledValues $validVals) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Value [%s] on [vpa.%s.resourcePolicy.containerPolicies.%d.controlledValues] is not valid. Must be one of [%s]" $cPol.controlledValues $objectData.vpaName $idx (join ", " $validVals)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $data := (include "tc.v1.common.lib.resources.validation.data" .) | fromJson -}}
|
||||||
|
{{- $regex := $data.regex -}}
|
||||||
|
{{- $errorMsg := $data.errorMsg -}}
|
||||||
|
|
||||||
|
{{- $items := (list "minAllowed" "maxAllowed") -}}
|
||||||
|
{{- range $item := $items -}}
|
||||||
|
{{- if not (get $cPol $item) -}}{{- continue -}}{{- end -}}
|
||||||
|
|
||||||
|
{{- if not (kindIs "map" (get $cPol $item)) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Expected [vpa.%s.resourcePolicy.containerPolicies.%d.%s] to be a dictionary, but got [%s]" $objectData.vpaName $idx $item (kindOf (get $cPol $item))) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- range $k, $v := (get $cPol $item) -}}
|
||||||
|
{{- if not (mustRegexMatch (get $regex $k) (toString $v)) -}}
|
||||||
|
{{- fail (printf "Vertical Pod Autoscaler - Expected [vpa.%s.resourcePolicy.containerPolicies.%d.%s.%s] to have one of the following formats [%s], but got [%s]" $objectData.vpaName $idx $item $k (get $errorMsg $k) $v) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -15,18 +15,29 @@
|
|||||||
|
|
||||||
{{- $objectData := (mustDeepCopy $vpa) -}}
|
{{- $objectData := (mustDeepCopy $vpa) -}}
|
||||||
{{- $_ := set $objectData "vpaName" $name -}}
|
{{- $_ := set $objectData "vpaName" $name -}}
|
||||||
{{- include "tc.v1.common.lib.vpa.validation" (dict "objectData" $objectData "rootCtx" $) -}}
|
|
||||||
{{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $name) -}}
|
{{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $name) -}}
|
||||||
|
|
||||||
{{- range $workloadName, $workload := $.Values.workload -}}
|
{{- range $workloadName, $workload := $.Values.workload -}}
|
||||||
|
|
||||||
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
|
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
|
||||||
"rootCtx" $ "objectData" $workload
|
"rootCtx" $ "objectData" $workload
|
||||||
"name" $name "caller" "vpa"
|
"name" $name "caller" "Vertical Pod Autoscaler"
|
||||||
"key" "workload")) -}}
|
"key" "workload")) -}}
|
||||||
|
|
||||||
{{- if ne $enabled "true" -}}{{- continue -}}{{- end -}}
|
{{- if ne $enabled "true" -}}{{- continue -}}{{- end -}}
|
||||||
|
|
||||||
|
{{- $containerNames := list -}}
|
||||||
|
{{- range $cName, $c := $workload.podSpec.containers -}}
|
||||||
|
{{- $enabledContainer := (include "tc.v1.common.lib.util.enabled" (dict
|
||||||
|
"rootCtx" $ "objectData" $c
|
||||||
|
"name" $cName "caller" "Vertical Pod Autoscaler"
|
||||||
|
"key" "workload.podSpec.containers")) -}}
|
||||||
|
{{- if ne $enabledContainer "true" -}}{{- continue -}}{{- end -}}
|
||||||
|
{{- $containerNames = mustAppend $containerNames $cName -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $_ := set $objectData "containerNames" $containerNames -}}
|
||||||
|
{{- include "tc.v1.common.lib.vpa.validation" (dict "objectData" $objectData "rootCtx" $) -}}
|
||||||
|
|
||||||
{{/* Create a copy of the workload */}}
|
{{/* Create a copy of the workload */}}
|
||||||
{{- $_ := set $objectData "workload" (mustDeepCopy $workload) -}}
|
{{- $_ := set $objectData "workload" (mustDeepCopy $workload) -}}
|
||||||
|
|
||||||
@@ -46,7 +57,7 @@
|
|||||||
{{/* Short name is the one that defined on the chart, used on selectors */}}
|
{{/* Short name is the one that defined on the chart, used on selectors */}}
|
||||||
{{- $_ := set $objectData "shortName" $workloadName -}}
|
{{- $_ := set $objectData "shortName" $workloadName -}}
|
||||||
|
|
||||||
{{- if or (not $objectData.targetSelector) (hasKey $objectData.targetSelector $workloadName) -}}
|
{{- if or (not $objectData.targetSelector) (mustHas $workloadName $objectData.targetSelector) -}}
|
||||||
{{/* Call class to create the object */}}
|
{{/* Call class to create the object */}}
|
||||||
{{- $types := (list "Deployment" "StatefulSet" "DaemonSet") -}}
|
{{- $types := (list "Deployment" "StatefulSet" "DaemonSet") -}}
|
||||||
{{- if (mustHas $objectData.workload.type $types) -}}
|
{{- if (mustHas $objectData.workload.type $types) -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user