Skip to content

Commit

Permalink
fix: 🐛 use k8s version for hpa api version
Browse files Browse the repository at this point in the history
  • Loading branch information
dddomin3 committed Jun 2, 2023
1 parent c29e3fd commit ab06c48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 51 deletions.
8 changes: 2 additions & 6 deletions traefik/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
{{- fail "ERROR: maxReplicas is required on HPA" }}
{{- end }}

{{- if .Capabilities.APIVersions.Has "autoscaling/v2" }}
{{- if semverCompare ">=1.23.0-0" .Capabilities.KubeVersion.Version }}
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 "ERROR: You must have at least autoscaling/v2beta1 to use HorizontalPodAutoscaler" }}
apiVersion: autoscaling/v2beta2
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
Expand Down
52 changes: 7 additions & 45 deletions traefik/tests/hpa-config_test.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,33 @@
suite: HPA configuration
templates:
- hpa.yaml
capabilities:
majorVersion: 1
minorVersion: 23
tests:
- it: should use autoscaling/v2 when available
capabilities:
apiVersions:
- autoscaling/v2
- it: should use autoscaling/v2 when k8s >= 1.23
values:
- ./values/hpa.yaml
asserts:
- isAPIVersion:
of: autoscaling/v2
- it: should use autoscaling/v2beta2 otherwise
- it: should use autoscaling/v2beta2 when k8s < 1.23
capabilities:
apiVersions:
- autoscaling/v2beta2
majorVersion: 1
minorVersion: 22
values:
- ./values/hpa.yaml
asserts:
- isAPIVersion:
of: autoscaling/v2beta2
- it: should use autoscaling/v2beta1
capabilities:
apiVersions:
- autoscaling/v2beta1
values:
- ./values/hpa.yaml
asserts:
- isAPIVersion:
of: autoscaling/v2beta1
- it: should prefer to use autoscaling/v2 when available
capabilities:
apiVersions:
- autoscaling/v2beta2
- autoscaling/v2beta1
- autoscaling/v1
- autoscaling/v2
values:
- ./values/hpa.yaml
asserts:
- isAPIVersion:
of: autoscaling/v2
- it: should fail without maxReplicas
capabilities:
apiVersions:
- autoscaling/v2
set:
autoscaling:
enabled: true
asserts:
- failedTemplate:
errorMessage: "maxReplicas is required on HPA"
- it: should fail without autoscaling/v2 capabilities
capabilities:
apiVersions:
- autoscaling/v1
set:
autoscaling:
enabled: true
maxReplicas: 3
asserts:
- failedTemplate:
errorMessage: "You must have at least autoscaling/v2beta1 to use HorizontalPodAutoscaler"
- it: should not contains metrics nor behavior when they are not set
capabilities:
apiVersions:
- autoscaling/v2
set:
autoscaling:
enabled: true
Expand Down

0 comments on commit ab06c48

Please sign in to comment.