From 9c245d4e65135635d6724579d1e9876fe99f02a9 Mon Sep 17 00:00:00 2001 From: Daniel Nachtrub Date: Thu, 14 Jul 2022 15:02:52 +0200 Subject: [PATCH] feat(argo-cd): Added apiVersion switch for autoscaling resources (#1375) * Added apiVersion switch for autoscaling Signed-off-by: dn * bumped chart version added changelog Signed-off-by: dn * updated docs with helm-docs 1.9.1 Signed-off-by: dn * added new line end of file (lint issue) Signed-off-by: dn * replaced linebreaks in chart.yaml with LF Signed-off-by: dn * Apply changes from code review Signed-off-by: Marco Kilchhofer Co-authored-by: Marco Kilchhofer --- charts/argo-cd/Chart.yaml | 4 ++-- charts/argo-cd/README.md | 1 + charts/argo-cd/templates/_helpers.tpl | 13 +++++++++++++ .../argo-cd/templates/argocd-repo-server/hpa.yaml | 14 +++++++++++++- charts/argo-cd/templates/argocd-server/hpa.yaml | 14 +++++++++++++- charts/argo-cd/values.yaml | 2 ++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/charts/argo-cd/Chart.yaml b/charts/argo-cd/Chart.yaml index 5159c240..3a78cafc 100644 --- a/charts/argo-cd/Chart.yaml +++ b/charts/argo-cd/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: v2.4.6 description: A Helm chart for Argo CD, a declarative, GitOps continuous delivery tool for Kubernetes. name: argo-cd -version: 4.9.13 +version: 4.9.14 home: https://github.com/argoproj/argo-helm icon: https://argo-cd.readthedocs.io/en/stable/assets/logo.png keywords: @@ -21,4 +21,4 @@ dependencies: condition: redis-ha.enabled annotations: artifacthub.io/changes: | - - [Changed]: Update to app version 2.4.6" + - [Changed]: Autoscaling now uses autoscaling/v2 apiVersion on kubernetes >= 1.23 diff --git a/charts/argo-cd/README.md b/charts/argo-cd/README.md index 4b604dbb..475bf8c1 100644 --- a/charts/argo-cd/README.md +++ b/charts/argo-cd/README.md @@ -213,6 +213,7 @@ NAME: my-release | Key | Type | Default | Description | |-----|------|---------|-------------| +| apiVersionOverrides.autoscaling | string | `""` | String to override apiVersion of autoscaling rendered by this helm chart | | apiVersionOverrides.certmanager | string | `""` | String to override apiVersion of certmanager resources rendered by this helm chart | | apiVersionOverrides.ingress | string | `""` | String to override apiVersion of ingresses rendered by this helm chart | | configs.clusterCredentials | list | `[]` (See [values.yaml]) | Provide one or multiple [external cluster credentials] | diff --git a/charts/argo-cd/templates/_helpers.tpl b/charts/argo-cd/templates/_helpers.tpl index 71d91b20..cf761118 100644 --- a/charts/argo-cd/templates/_helpers.tpl +++ b/charts/argo-cd/templates/_helpers.tpl @@ -219,6 +219,19 @@ Return the appropriate apiVersion for ingress {{- end -}} {{- end -}} +{{/* +Return the appropriate apiVersion for autoscaling +*/}} +{{- define "argo-cd.autoscaling.apiVersion" -}} +{{- if .Values.apiVersionOverrides.autoscaling -}} +{{- print .Values.apiVersionOverrides.autoscaling -}} +{{- else if semverCompare "<1.23-0" (include "argo-cd.kubeVersion" $) -}} +{{- print "autoscaling/v2beta1" -}} +{{- else -}} +{{- print "autoscaling/v2" -}} +{{- end -}} +{{- end -}} + {{/* Return the target Kubernetes version */}} diff --git a/charts/argo-cd/templates/argocd-repo-server/hpa.yaml b/charts/argo-cd/templates/argocd-repo-server/hpa.yaml index 65e379dd..2d179ca4 100644 --- a/charts/argo-cd/templates/argocd-repo-server/hpa.yaml +++ b/charts/argo-cd/templates/argocd-repo-server/hpa.yaml @@ -1,5 +1,5 @@ {{- if .Values.repoServer.autoscaling.enabled }} -apiVersion: autoscaling/v2beta1 +apiVersion: {{ include "argo-cd.autoscaling.apiVersion" . }} kind: HorizontalPodAutoscaler metadata: labels: @@ -17,12 +17,24 @@ spec: - type: Resource resource: name: memory + {{- if eq (include "argo-cd.autoscaling.apiVersion" $) "autoscaling/v2beta1" }} targetAverageUtilization: {{ . }} + {{- else }} + target: + averageUtilization: {{ . }} + type: Utilization + {{- end }} {{- end }} {{- with .Values.repoServer.autoscaling.targetCPUUtilizationPercentage }} - type: Resource resource: name: cpu + {{- if eq (include "argo-cd.autoscaling.apiVersion" $) "autoscaling/v2beta1" }} targetAverageUtilization: {{ . }} + {{- else }} + target: + averageUtilization: {{ . }} + type: Utilization + {{- end }} {{- end }} {{- end }} diff --git a/charts/argo-cd/templates/argocd-server/hpa.yaml b/charts/argo-cd/templates/argocd-server/hpa.yaml index e079a7e2..6fd444ec 100644 --- a/charts/argo-cd/templates/argocd-server/hpa.yaml +++ b/charts/argo-cd/templates/argocd-server/hpa.yaml @@ -1,5 +1,5 @@ {{- if .Values.server.autoscaling.enabled }} -apiVersion: autoscaling/v2beta1 +apiVersion: {{ include "argo-cd.autoscaling.apiVersion" . }} kind: HorizontalPodAutoscaler metadata: labels: @@ -17,12 +17,24 @@ spec: - type: Resource resource: name: memory + {{- if eq (include "argo-cd.autoscaling.apiVersion" $) "autoscaling/v2beta1" }} targetAverageUtilization: {{ . }} + {{- else }} + target: + averageUtilization: {{ . }} + type: Utilization + {{- end }} {{- end }} {{- with .Values.server.autoscaling.targetCPUUtilizationPercentage }} - type: Resource resource: name: cpu + {{- if eq (include "argo-cd.autoscaling.apiVersion" $) "autoscaling/v2beta1" }} targetAverageUtilization: {{ . }} + {{- else }} + target: + averageUtilization: {{ . }} + type: Utilization + {{- end }} {{- end }} {{- end }} diff --git a/charts/argo-cd/values.yaml b/charts/argo-cd/values.yaml index e7b96125..541586ec 100755 --- a/charts/argo-cd/values.yaml +++ b/charts/argo-cd/values.yaml @@ -53,6 +53,8 @@ apiVersionOverrides: certmanager: "" # cert-manager.io/v1 # -- String to override apiVersion of ingresses rendered by this helm chart ingress: "" # networking.k8s.io/v1beta1 + # -- String to override apiVersion of autoscaling rendered by this helm chart + autoscaling: "" # autoscaling/v2 # -- Create clusterroles that extend existing clusterroles to interact with argo-cd crds ## Ref: https://kubernetes.io/docs/reference/access-authn-authz/rbac/#aggregated-clusterroles