Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(Helm chart): Add env vars into pods #4196

Merged
merged 13 commits into from
Dec 2, 2024
2 changes: 2 additions & 0 deletions contrib/charts/dragonfly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ helm upgrade --install dragonfly oci://ghcr.io/dragonflydb/dragonfly/helm/dragon
| replicaCount | int | `1` | Number of replicas to deploy |
| resources.limits | object | `{}` | The resource limits for the containers |
| resources.requests | object | `{}` | The requested resources for the containers |
| env | list | `[]` | Extra environment variables |
| envFrom | list | `[]` | Extra environment variables from K8s objects |
| securityContext | object | `{}` | Set securityContext for containers |
| service.annotations | object | `{}` | Extra annotations for the service |
| service.lablels | object | `{}` | Extra labels for the service |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
# 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.25.4"
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/extra-manifests.yaml
apiVersion: v1
kind: Secret
metadata:
name: my-secret
stringData:
password: password
username: username
type: Opaque
---
# Source: dragonfly/templates/extra-manifests.yaml
apiVersion: v1
data:
configKey1: configValue1
configKey2: configValue2
kind: ConfigMap
metadata:
name: my-configmap
---
# 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.25.4"
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.25.4"
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.25.4"
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_requirepass
valueFrom:
secretKeyRef:
name: dfly-password
key: password
- name: ENV_VAR43
value: value1
- name: ENV_VAR323
value: value2
envFrom:
- configMapRef:
name: my-configmap
- secretRef:
name: my-secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
extraObjects:
- apiVersion: v1
kind: Secret
metadata:
name: dfly-password
stringData:
password: foobar
- apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
data:
configKey1: configValue1
configKey2: configValue2
- apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
stringData:
username: username
password: password

env:
- name: ENV_VAR43
value: value1
- name: ENV_VAR323
value: value2

envFrom:
- configMapRef:
name: my-configmap
- secretRef:
name: my-secret

passwordFromSecret:
enable: true
existingSecret:
name: dfly-password
key: password
123 changes: 123 additions & 0 deletions contrib/charts/dragonfly/ci/extraenv-values.golden.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
# 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.25.4"
app.kubernetes.io/managed-by: Helm
---
# Source: dragonfly/templates/extra-manifests.yaml
apiVersion: v1
kind: Secret
metadata:
name: my-secret
stringData:
password: password
username: username
type: Opaque
---
# Source: dragonfly/templates/extra-manifests.yaml
apiVersion: v1
data:
configKey1: configValue1
configKey2: configValue2
kind: ConfigMap
metadata:
name: my-configmap
---
# 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.25.4"
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.25.4"
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.25.4"
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: ENV_VAR43
value: value1
- name: ENV_VAR323
value: value2
envFrom:
- configMapRef:
name: my-configmap
- secretRef:
name: my-secret
28 changes: 28 additions & 0 deletions contrib/charts/dragonfly/ci/extraenv-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extraObjects:
- apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
data:
configKey1: configValue1
configKey2: configValue2
- apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
stringData:
username: username
password: password

env:
- name: ENV_VAR43
value: value1
- name: ENV_VAR323
value: value2

envFrom:
- configMapRef:
name: my-configmap
- secretRef:
name: my-secret
11 changes: 10 additions & 1 deletion contrib/charts/dragonfly/templates/_pod.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ containers:
{{- toYaml . | trim | nindent 6 }}
{{- end }}
{{- include "dragonfly.volumemounts" . | trim | nindent 4 }}
{{- if or .Values.passwordFromSecret.enable .Values.env }}
env:
{{- 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 }}
Expand All @@ -114,6 +115,14 @@ containers:
name: {{ tpl .Values.passwordFromSecret.existingSecret.name $ }}
key: {{ .Values.passwordFromSecret.existingSecret.key }}
{{- end }}
{{- with .Values.env }}
{{- toYaml . | trim | nindent 6 }}
{{- end }}
{{- end }}
{{- with .Values.envFrom }}
envFrom:
{{- toYaml . | trim | nindent 6 }}
{{- end }}

{{- if or (.Values.tls.enabled) (.Values.extraVolumes) }}
volumes:
Expand Down
6 changes: 6 additions & 0 deletions contrib/charts/dragonfly/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ resources:
# cpu: 100m
# memory: 128Mi

# -- extra environment variables
env: []

# -- extra environment variables from K8s objects
envFrom: []

# -- Priority class name for pod assignment
priorityClassName: ""

Expand Down
Loading