From e11c57c7818ab9ec291f470e74f75f05dba87263 Mon Sep 17 00:00:00 2001 From: Gunnar Scherf Date: Fri, 15 Sep 2023 12:06:13 +0200 Subject: [PATCH] Use autoscaling/v2 api version if kubernetes version >= 1.23 Signed-off-by: Gunnar Scherf --- charts/keycloak/templates/hpa.yaml | 8 ++++++-- charts/keycloak/values.yaml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/charts/keycloak/templates/hpa.yaml b/charts/keycloak/templates/hpa.yaml index c772b769..024e1414 100644 --- a/charts/keycloak/templates/hpa.yaml +++ b/charts/keycloak/templates/hpa.yaml @@ -1,5 +1,9 @@ {{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2beta2 +{{- $apiVersion := "autoscaling/v2beta2" -}} +{{- if semverCompare ">= v1.23.0-0" .Capabilities.KubeVersion.Version -}} + {{- $apiVersion = "autoscaling/v2" -}} +{{- end }} +apiVersion: {{ $apiVersion }} kind: HorizontalPodAutoscaler metadata: name: {{ include "keycloak.fullname" . }} @@ -15,7 +19,7 @@ spec: name: {{ include "keycloak.fullname" . }} minReplicas: {{ .Values.autoscaling.minReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: + metrics: {{- toYaml .Values.autoscaling.metrics | nindent 4 }} behavior: {{- toYaml .Values.autoscaling.behavior | nindent 4 }} diff --git a/charts/keycloak/values.yaml b/charts/keycloak/values.yaml index 1ea8e58b..811a938d 100644 --- a/charts/keycloak/values.yaml +++ b/charts/keycloak/values.yaml @@ -466,7 +466,7 @@ prometheusRule: # severity: warning autoscaling: - # If `true`, a autoscaling/v2beta2 HorizontalPodAutoscaler resource is created (requires Kubernetes 1.18 or above) + # If `true`, a autoscaling/v2beta2 or autoscaling/v2 HorizontalPodAutoscaler resource is created (requires Kubernetes 1.18 or 1.23 or above) # Autoscaling seems to be most reliable when using KUBE_PING service discovery (see README for details) # This disables the `replicas` field in the StatefulSet enabled: false