Skip to content

Commit

Permalink
feat: Add customised env var and feature flags
Browse files Browse the repository at this point in the history
This change adds 3 new features:
 - The ability to enable feature flags with the .Values.features key
 - The ability to add extra environment variables to the container env
 - The ability to completely override env variables (not recommended)

Closes CrunchyData#262
  • Loading branch information
jaitaiwan committed Sep 18, 2024
1 parent 9fec499 commit 4c64a95
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
38 changes: 38 additions & 0 deletions helm/install/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,41 @@ imagePullSecrets:
value: {{ $object.image | quote }}
{{- end }}
{{- end }}


{{- define "install.defaultEnv" -}}
- name: CRUNCHY_DEBUG
value: {{ .Values.debug | ne false | quote }}
- name: PGO_NAMESPACE
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
{{- if .Values.singleNamespace }}
- name: PGO_TARGET_NAMESPACE
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
{{- end }}
{{- if .Values.workers }}
- name: PGO_WORKERS
value: {{ .Values.workers | quote }}
{{- end }}
{{- include "install.relatedImages" . }}
{{- if .Values.disable_check_for_upgrades }}
- name: CHECK_FOR_UPGRADES
value: "false"
{{- end }}
{{- if .Values.features }}
{{- $value := .Values.features }}
- name: PGO_FEATURE_GATES
{{- $out := "" -}}
{{- if eq (kindOf $value) "slice" }}
{{- range $val := $value -}}
{{- $out = (print $out $val "=true" ",") -}}
{{- end }}
{{- else if eq (kindOf $value) "map" -}}
{{- range $key, $val := $value -}}
{{- $out = (print $out $key "=" $val ",") -}}
{{- end }}
{{- end }}
value: "{{ trimSuffix "," $out }}"
{{- end }}
{{- end }}{{/* define */}}


21 changes: 6 additions & 15 deletions helm/install/templates/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,13 @@ spec:
- name: operator
image: {{ required ".Values.controllerImages.cluster is required" .Values.controllerImages.cluster | quote }}
env:
- name: CRUNCHY_DEBUG
value: {{ .Values.debug | ne false | quote }}
- name: PGO_NAMESPACE
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
{{- if .Values.singleNamespace }}
- name: PGO_TARGET_NAMESPACE
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
{{- if .Values.envOverride }}
{{- toYaml .Values.envOverride | nindent 10 }}
{{- else -}}
{{- include "install.defaultEnv" . | nindent 10 }}
{{- end }}
{{- if .Values.workers }}
- name: PGO_WORKERS
value: {{ .Values.workers | quote }}
{{- end }}
{{- include "install.relatedImages" . | indent 8 }}
{{- if .Values.disable_check_for_upgrades }}
- name: CHECK_FOR_UPGRADES
value: "false"
{{- if .Values.extraEnv }}
{{- toYaml .Values.extraEnv | nindent 10 }}
{{- end }}
{{- if .Values.resources.controller }}
resources:
Expand Down
32 changes: 32 additions & 0 deletions helm/install/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,35 @@ resources:
# postgres-operator.crunchydata.com, will cause an error
# customPodLabels:
# example.com: custom-label

# Enable feature gates for PGO
# features:
# - AutoGrowVolumes
# - Feature2
# - Feature3
#
# Alternatively, explicitly set the value for the flags
# features:
# AutoGrowVolumes: true
# Feature2: false
# Feature3: somevalue

# Define extra environment variables for the chart, which will get added to the container's env
# extraEnv:
# - name: MY_VAR
# value: "myvalue"
# - name: MY_CONFIGMAP_VAR
# valueFrom:
# configMapKeyRef:
# name: s3-settings
# key: bucket
# - name: MY_SECRET_VAR
# valueFrom:
# secretKeyRef:
# name: s3-secret
# key: key

# Override environment variables entirely !!DANGEROUS!!
# envOverride:
# - name: PG_DEBUG
# value: "true"

0 comments on commit 4c64a95

Please sign in to comment.