From 951b0897e6be38a3b67ef7ed30713b0bf0b7e429 Mon Sep 17 00:00:00 2001 From: Michael Primeaux Date: Tue, 6 Feb 2024 02:12:05 -0600 Subject: [PATCH] bug: DFLY_PASSWORD environment variable deprecation (#2539) * If the image.tag version is equal to 14.0.0 or greater then specify the DFLY_requirepass environment variable. Otherwise use the DFLY_PASSWORD environment variable. Signed-off-by: Michael Primeaux * Corrected version logic and added golden test Signed-off-by: Michael Primeaux * Updated golden file for TLS + image.tag Signed-off-by: Michael Primeaux * fix CI for chart linting test * rename new test specific to password * use v1.13.0 * update golden chart --------- Signed-off-by: Michael Primeaux Signed-off-by: Michael Primeaux Co-authored-by: Tarun Pothulapati --- .../ci/password-old-env-values.golden.yaml | 108 ++++++++++++++++++ .../dragonfly/ci/password-old-env-values.yaml | 16 +++ .../ci/passwordsecret-values.golden.yaml | 2 +- ...ersistence-and-existing-secret.golden.yaml | 2 +- .../dragonfly/ci/tls-values.golden.yaml | 2 +- contrib/charts/dragonfly/templates/_pod.tpl | 10 ++ go.work.sum | 2 + 7 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 contrib/charts/dragonfly/ci/password-old-env-values.golden.yaml create mode 100644 contrib/charts/dragonfly/ci/password-old-env-values.yaml create mode 100644 go.work.sum diff --git a/contrib/charts/dragonfly/ci/password-old-env-values.golden.yaml b/contrib/charts/dragonfly/ci/password-old-env-values.golden.yaml new file mode 100644 index 000000000000..c6c71d4b3075 --- /dev/null +++ b/contrib/charts/dragonfly/ci/password-old-env-values.golden.yaml @@ -0,0 +1,108 @@ +--- +# Source: dragonfly/templates/serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: test-dragonfly + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.14.2" + app.kubernetes.io/managed-by: Helm +--- +# Source: dragonfly/templates/extra-manifests.yaml +apiVersion: v1 +kind: Secret +metadata: + name: dfly-password +stringData: + password: foobar +--- +# Source: dragonfly/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: test-dragonfly + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.14.2" + app.kubernetes.io/managed-by: Helm +spec: + type: ClusterIP + ports: + - port: 6379 + targetPort: dragonfly + protocol: TCP + name: dragonfly + selector: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test +--- +# Source: dragonfly/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-dragonfly + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.14.2" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + template: + metadata: + annotations: + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + spec: + serviceAccountName: test-dragonfly + containers: + - name: dragonfly + image: "docker.dragonflydb.io/dragonflydb/dragonfly:v1.13.0" + imagePullPolicy: IfNotPresent + ports: + - name: dragonfly + containerPort: 6379 + protocol: TCP + livenessProbe: + exec: + command: + - /bin/sh + - /usr/local/bin/healthcheck.sh + failureThreshold: 3 + initialDelaySeconds: 10 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - /bin/sh + - /usr/local/bin/healthcheck.sh + failureThreshold: 3 + initialDelaySeconds: 10 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + args: + - "--alsologtostderr" + resources: + limits: {} + requests: {} + + env: + - name: DFLY_PASSWORD + valueFrom: + secretKeyRef: + name: dfly-password + key: password diff --git a/contrib/charts/dragonfly/ci/password-old-env-values.yaml b/contrib/charts/dragonfly/ci/password-old-env-values.yaml new file mode 100644 index 000000000000..ce1e77475799 --- /dev/null +++ b/contrib/charts/dragonfly/ci/password-old-env-values.yaml @@ -0,0 +1,16 @@ +image: + tag: "v1.13.0" + +extraObjects: + - apiVersion: v1 + kind: Secret + metadata: + name: dfly-password + stringData: + password: foobar + +passwordFromSecret: + enable: true + existingSecret: + name: dfly-password + key: password diff --git a/contrib/charts/dragonfly/ci/passwordsecret-values.golden.yaml b/contrib/charts/dragonfly/ci/passwordsecret-values.golden.yaml index 3e332473ef8c..0a4b22b7de58 100644 --- a/contrib/charts/dragonfly/ci/passwordsecret-values.golden.yaml +++ b/contrib/charts/dragonfly/ci/passwordsecret-values.golden.yaml @@ -101,7 +101,7 @@ spec: requests: {} env: - - name: DFLY_PASSWORD + - name: DFLY_requirepass valueFrom: secretKeyRef: name: dfly-password diff --git a/contrib/charts/dragonfly/ci/persistence-and-existing-secret.golden.yaml b/contrib/charts/dragonfly/ci/persistence-and-existing-secret.golden.yaml index fa4d7ff0f434..fb1377a7d0e6 100644 --- a/contrib/charts/dragonfly/ci/persistence-and-existing-secret.golden.yaml +++ b/contrib/charts/dragonfly/ci/persistence-and-existing-secret.golden.yaml @@ -104,7 +104,7 @@ spec: - mountPath: /data name: "test-data" env: - - name: DFLY_PASSWORD + - name: DFLY_requirepass valueFrom: secretKeyRef: name: dfly-password diff --git a/contrib/charts/dragonfly/ci/tls-values.golden.yaml b/contrib/charts/dragonfly/ci/tls-values.golden.yaml index ec17b3700aca..021f5147f053 100644 --- a/contrib/charts/dragonfly/ci/tls-values.golden.yaml +++ b/contrib/charts/dragonfly/ci/tls-values.golden.yaml @@ -123,7 +123,7 @@ spec: - mountPath: /etc/dragonfly/tls name: tls env: - - name: DFLY_PASSWORD + - name: DFLY_requirepass valueFrom: secretKeyRef: name: dfly-password diff --git a/contrib/charts/dragonfly/templates/_pod.tpl b/contrib/charts/dragonfly/templates/_pod.tpl index aba120b0aa40..40b870f0e5f1 100644 --- a/contrib/charts/dragonfly/templates/_pod.tpl +++ b/contrib/charts/dragonfly/templates/_pod.tpl @@ -90,8 +90,18 @@ containers: {{- end }} {{- include "dragonfly.volumemounts" . | trim | nindent 4 }} {{- if .Values.passwordFromSecret.enable }} + {{- $appVersion := .Chart.AppVersion | trimPrefix "v" }} + {{- $imageTag := .Values.image.tag | trimPrefix "v" }} + {{- $effectiveVersion := $appVersion }} + {{- if and $imageTag (ne $imageTag "") }} + {{- $effectiveVersion = $imageTag }} + {{- end }} env: + {{- if semverCompare ">=1.14.0" $effectiveVersion }} + - name: DFLY_requirepass + {{- else }} - name: DFLY_PASSWORD + {{- end }} valueFrom: secretKeyRef: name: {{ .Values.passwordFromSecret.existingSecret.name }} diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 000000000000..bc790f0c335a --- /dev/null +++ b/go.work.sum @@ -0,0 +1,2 @@ +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=