From 071a4d99ff45e0f08240003ea234ccaf09518a0b Mon Sep 17 00:00:00 2001 From: Nir Shidlansik Date: Tue, 6 Jun 2023 13:30:10 +0300 Subject: [PATCH] support passing in release name up to 53 chars --- charts/chart/Chart.yaml | 4 +-- charts/chart/templates/_helpers.tpl | 34 +++++++++++++++++++++- charts/chart/templates/configmap.yaml | 4 +-- charts/chart/templates/cronjob.yaml | 12 ++++---- charts/chart/templates/pre-delete-job.yaml | 4 +-- charts/chart/templates/secret.yaml | 4 +-- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/charts/chart/Chart.yaml b/charts/chart/Chart.yaml index dd16178..881ea69 100644 --- a/charts/chart/Chart.yaml +++ b/charts/chart/Chart.yaml @@ -3,5 +3,5 @@ name: firefly-k8s-collector home: https://github.com/gofireflyio/k8s-collector description: Firefly's Kubernetes Collector type: application -version: 1.4.4 -appVersion: "1.4.4" +version: 1.4.5 +appVersion: "1.4.5" diff --git a/charts/chart/templates/_helpers.tpl b/charts/chart/templates/_helpers.tpl index 695576b..8ef2162 100644 --- a/charts/chart/templates/_helpers.tpl +++ b/charts/chart/templates/_helpers.tpl @@ -2,6 +2,38 @@ {{- if .Values.existingFireFlyCredentialsSecret -}} {{- printf "%s" .Values.existingFireFlyCredentialsSecret }} {{- else -}} -{{- printf "%s-credentials" .Release.Name -}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 63 (len "-credentials")) | int) | trimSuffix "-") "credentials" }} +{{- end -}} +{{- end -}} + +{{- define "fireFlyCollectorCrojobName"}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 52 (len "-cronjob")) | int) | trimSuffix "-") "cronjob" }} +{{- end -}} + +{{- define "fireFlyCollectorContaierName"}} +{{- (.Release.Name | trunc 63 | trimSuffix "-") }} +{{- end -}} + +{{- define "fireFlyArgocdContainerName"}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 53 (len "-argocd")) | int) | trimSuffix "-") "argocd" }} +{{- end -}} + +{{- define "fireFlyArgoConfigMap"}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 63 (len "-argocd-config")) | int) | trimSuffix "-") "argocd-config" }} +{{- end -}} + +{{- define "fireFlyCollectorConfigMap"}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 63 (len "-config")) | int) | trimSuffix "-") "config" }} +{{- end -}} + +{{- define "fireFlyCollectorOffBoarderJob"}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 53 (len "-collector-off-boarder")) | int) | trimSuffix "-") "collector-off-boarder" }} +{{- end -}} + +{{- define "fireFlyArgocdCredentials" -}} +{{- if .Values.argocd.secretNameOverride -}} +{{- printf "%s" .Values.argocd.secretNameOverride }} +{{- else -}} +{{- printf "%s-%s" (.Release.Name | trunc ((sub 63 (len "-argocd-credentials")) | int) | trimSuffix "-") "argocd-credentials" }} {{- end -}} {{- end -}} diff --git a/charts/chart/templates/configmap.yaml b/charts/chart/templates/configmap.yaml index b9bc07d..e11b166 100644 --- a/charts/chart/templates/configmap.yaml +++ b/charts/chart/templates/configmap.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Release.Name }}-argocd-config + name: {{ template "fireFlyArgoConfigMap" .}} data: "crawler.json": {{ .Values.argocd.metadata | toJson | quote }} {{- end }} @@ -10,7 +10,7 @@ data: apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Release.Name }}-config + name: {{ template "fireFlyCollectorConfigMap" .}} data: {{ if .Values.apiEndpoint }} endpoint: {{ quote .Values.apiEndpoint }} diff --git a/charts/chart/templates/cronjob.yaml b/charts/chart/templates/cronjob.yaml index 2a25a88..c347131 100644 --- a/charts/chart/templates/cronjob.yaml +++ b/charts/chart/templates/cronjob.yaml @@ -5,7 +5,7 @@ apiVersion: batch/v1beta1 {{- end }} kind: CronJob metadata: - name: {{ .Release.Name }}-cronjob + name: {{ template "fireFlyCollectorCrojobName" . }} spec: schedule: "{{ .Values.schedule }}" concurrencyPolicy: "Forbid" @@ -17,7 +17,7 @@ spec: runAsNonRoot: true serviceAccountName: {{ .Values.serviceAccount.name }} containers: - - name: {{ .Release.Name }} + - name: {{ template "fireFlyCollectorContaierName" . }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: @@ -44,7 +44,7 @@ spec: cpu: {{ .Values.resources.limits.cpu }} memory: {{ .Values.resources.limits.memory }} {{ if .Values.argocd.enabled }} - - name: {{ .Release.Name }}-argocd + - name: {{ template "fireFlyArgocdContainerName" . }} image: "{{ .Values.argocd.image.repository }}:{{ .Values.argocd.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.argocd.image.pullPolicy }} env: @@ -72,7 +72,7 @@ spec: value: {{ quote .Values.argocd.saveToRemoteBucket}} envFrom: - secretRef: - name: {{ .Values.argocd.secretNameOverride | default (printf "%s-argocd-credentials" .Release.Name) }} + name: {{ template "fireFlyArgocdCredentials" .}} volumeMounts: - name: argocd-config-volume mountPath: "{{ .Values.argocd.crawlerLocalPath }}/crawler.json" @@ -90,10 +90,10 @@ spec: volumes: - name: config-volume configMap: - name: {{ .Release.Name }}-config + name: {{ template "fireFlyCollectorConfigMap" .}} {{if .Values.argocd.enabled }} - name: argocd-config-volume configMap: - name: {{ .Release.Name }}-argocd-config + name: {{ template "fireFlyArgoConfigMap" .}} {{ end }} restartPolicy: OnFailure diff --git a/charts/chart/templates/pre-delete-job.yaml b/charts/chart/templates/pre-delete-job.yaml index ada70bd..e6a7b1c 100644 --- a/charts/chart/templates/pre-delete-job.yaml +++ b/charts/chart/templates/pre-delete-job.yaml @@ -5,7 +5,7 @@ apiVersion: batch/v1beta1 {{- end }} kind: Job metadata: - name: "{{ .Release.Name }}-collector-off-boarder" + name: {{ template "fireFlyCollectorOffBoarderJob" . }} annotations: # This is what defines this resource as a hook. Without this line, the # job is considered part of the release. @@ -15,7 +15,7 @@ spec: backoffLimit: 2 template: metadata: - name: "{{ .Release.Name }}" + name: "off-boarder" spec: restartPolicy: OnFailure containers: diff --git a/charts/chart/templates/secret.yaml b/charts/chart/templates/secret.yaml index dcde795..1dca597 100644 --- a/charts/chart/templates/secret.yaml +++ b/charts/chart/templates/secret.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Secret metadata: - name: {{ .Values.argocd.secretNameOverride | default (printf "%s-argocd-credentials" .Release.Name) }} + name: {{ template "fireFlyArgocdCredentials" .}} type: Opaque data: IACATHON_ARGOCD_TOKEN: {{ .Values.argocd.token | b64enc }} @@ -12,7 +12,7 @@ data: apiVersion: v1 kind: Secret metadata: - name: {{ .Release.Name }}-credentials + name: {{ template "fireFlyCredentialsSecret" .}} type: Opaque data: accessKey: {{ .Values.accessKey | b64enc }}