diff --git a/hacks/values/oathkeeper.yaml b/hacks/values/oathkeeper.yaml index 5cb86d55b..038a215ca 100644 --- a/hacks/values/oathkeeper.yaml +++ b/hacks/values/oathkeeper.yaml @@ -63,6 +63,21 @@ deployment: behavior: scaleDown: stabilizationWindowSeconds: 60 + extraMetrics: + - type: ContainerResource + containerResource: + name: cpu + container: sidecar + target: + type: Utilization + averageUtilization: 80 + - type: ContainerResource + containerResource: + name: memory + container: sidecar + target: + type: Utilization + averageUtilization: 80 strategy: type: RollingUpdate rollingUpdate: diff --git a/helm/charts/oathkeeper/templates/hpa-controller.yaml b/helm/charts/oathkeeper/templates/hpa-controller.yaml index b80f4a2ae..6c81cb543 100644 --- a/helm/charts/oathkeeper/templates/hpa-controller.yaml +++ b/helm/charts/oathkeeper/templates/hpa-controller.yaml @@ -1,4 +1,5 @@ {{- if .Values.deployment.autoscaling.enabled }} +{{- $kubeVersion := .Capabilities.KubeVersion.GitVersion -}} apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: @@ -20,17 +21,34 @@ spec: maxReplicas: {{ .Values.deployment.autoscaling.maxReplicas }} metrics: {{- with .Values.deployment.autoscaling.targetMemory }} + {{- if and (and (not (empty $kubeVersion)) (semverCompare ">=1.30-0" $kubeVersion) (not (empty $.Values.deployment.autoscaling.extraMetrics))) }} + - type: ContainerResource + containerResource: + name: memory + container: {{ $.Chart.Name }} + {{- else }} - type: Resource resource: name: memory + {{- end }} target: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.deployment.autoscaling.targetCPU}} + {{- if and (and (not (empty $kubeVersion)) (semverCompare ">=1.30-0" $kubeVersion) (not (empty $.Values.deployment.autoscaling.extraMetrics))) }} + - type: ContainerResource + containerResource: + name: cpu + container: {{ $.Chart.Name }} + {{- else }} - type: Resource resource: name: cpu + {{- end }} target: {{- toYaml . | nindent 8 }} {{- end }} + {{- if and (and (not (empty $kubeVersion)) (semverCompare ">=1.30-0" $kubeVersion) (not (empty $.Values.deployment.autoscaling.extraMetrics))) }} + {{- toYaml .Values.deployment.autoscaling.extraMetrics | nindent 2}} + {{- end }} {{- end }} diff --git a/helm/charts/oathkeeper/values.yaml b/helm/charts/oathkeeper/values.yaml index 333f14ba2..13bb42f64 100644 --- a/helm/charts/oathkeeper/values.yaml +++ b/helm/charts/oathkeeper/values.yaml @@ -374,6 +374,9 @@ deployment: # -- Set custom behavior # https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#configurable-scaling-behavior behavior: {} + # -- Add extraContainer container resource metrics + # https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#container-resource-metrics + extraMetrics: [] # -- Configure node affinity affinity: {}