Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple HPA versions #65

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ tilt_config.json
localdev/terraform/gitlab/project.url
*.tgz
*.DS_Store
kubechecks
/kubechecks
davidwin93 marked this conversation as resolved.
Show resolved Hide resolved
localdev/terraform/github/project.url
24 changes: 23 additions & 1 deletion charts/kubechecks/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{{- if .Values.autoscaling.create }}
apiVersion: autoscaling/v2beta1
{{ $apiVersion := "" }}
{{- if .Capabilities.APIVersions.Has "autoscaling/v2" }}
{{ $apiVersion = "autoscaling/v2" }}
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta2" }}
{{ $apiVersion = "autoscaling/v2beta2" }}
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta1" }}
{{ $apiVersion = "autoscaling/v2beta1" }}
{{- else }}
{{ fail "server has no support for autoscaling" }}
{{- end }}
apiVersion: {{ $apiVersion }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "kubechecks.fullname" . }}
Expand All @@ -17,12 +27,24 @@ spec:
- type: Resource
resource:
name: cpu
{{- if or (eq $apiVersion "autoscaling/v2") (eq $apiVersion "autoscaling/v2beta2") }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- else }}
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
{{- if or (eq $apiVersion "autoscaling/v2") (eq $apiVersion "autoscaling/v2beta2") }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- else }}
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
{{- end }}
121 changes: 121 additions & 0 deletions charts/kubechecks/tests/autoscaling_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
suite: autoscaling tests

templates:
- hpa.yaml

tests:
- it: can have v2beta1
set:
autoscaling:
create: true
targetCPUUtilizationPercentage: 10
targetMemoryUtilizationPercentage: 15
capabilities:
apiVersions:
- autoscaling/v2beta1
asserts:
- equal:
path: apiVersion
value: autoscaling/v2beta1
- equal:
path: spec.metrics[0]
value:
type: Resource
resource:
name: cpu
targetAverageUtilization: 10
- equal:
path: spec.metrics[1]
value:
type: Resource
resource:
name: memory
targetAverageUtilization: 15

- it: can have v2beta2
set:
autoscaling:
create: true
targetCPUUtilizationPercentage: 10
targetMemoryUtilizationPercentage: 15
capabilities:
apiVersions:
- autoscaling/v2beta2
asserts:
- equal:
path: apiVersion
value: autoscaling/v2beta2
- equal:
path: spec.metrics[0]
value:
type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 10
- equal:
path: spec.metrics[1]
value:
type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 15

- it: can have v2
set:
autoscaling:
create: true
targetCPUUtilizationPercentage: 10
targetMemoryUtilizationPercentage: 15
capabilities:
apiVersions:
- autoscaling/v2
asserts:
- equal:
path: apiVersion
value: autoscaling/v2
- equal:
path: spec.metrics[0]
value:
type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 10
- equal:
path: spec.metrics[1]
value:
type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 15

- it: prefers v2
set:
autoscaling:
create: true
capabilities:
apiVersions:
- autoscaling/v2beta1
- autoscaling/v2beta2
- autoscaling/v2
asserts:
- equal:
path: apiVersion
value: autoscaling/v2
- it: renders nothing with no support
set:
autoscaling:
create: true
capabilities:
apiVersions:
- autoscaling/vFake
asserts:
- failedTemplate:
errorMessage: server has no support for autoscaling