Skip to content

Commit 65dc09d

Browse files
authored
Add the ability to configure environment variables in the deployment (#601)
1 parent bc1da1f commit 65dc09d

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: '`Helm Chart`: Add the ability to configure environment variables for the Operator Deployment via `operator.env`.'
3+
time: 2025-04-29T13:57:41.925639+02:00
4+
custom:
5+
PR: "601"

charts/hcp-terraform-operator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ For a more detailed explanation, please refer to the [FAQ](../../docs/faq.md#gen
203203
| kubeRbacProxy.resources.requests.memory | string | `"64Mi"` | Guaranteed minimum amount of memory to be used by a container. |
204204
| kubeRbacProxy.securityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"seccompProfile":{"type":"RuntimeDefault"}}` | Container security context. More information in [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/). |
205205
| operator.affinity | object | `{}` | Kubernetes Affinity. More information: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity |
206+
| operator.env | object | `{}` | Environment variables. |
206207
| operator.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy. |
207208
| operator.image.repository | string | `"hashicorp/hcp-terraform-operator"` | Image repository. |
208209
| operator.image.tag | string | `""` | Image tag. Defaults to `.Chart.AppVersion`. |

charts/hcp-terraform-operator/templates/deployment.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ spec:
4949
- --namespace={{ . }}
5050
{{- end }}
5151
{{- $envVars := dict }}
52+
{{- if .Values.operator.env }}
53+
{{- range $key, $value := .Values.operator.env }}
54+
{{- $_ := set $envVars $key $value }}
55+
{{- end }}
56+
{{- end }}
5257
{{- if .Values.operator.tfeAddress }}
5358
{{- $_ := set $envVars "TFE_ADDRESS" .Values.operator.tfeAddress }}
5459
{{- end }}
@@ -60,7 +65,7 @@ spec:
6065
{{- range $ek, $ev := $envVars }}
6166
- name: {{ $ek }}
6267
value: "{{ $ev -}}"
63-
{{ end }}
68+
{{- end }}
6469
{{- end }}
6570
command:
6671
- /manager

charts/hcp-terraform-operator/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ operator:
3737
cpu: 50m
3838
# -- Guaranteed minimum amount of memory to be used by a container.
3939
memory: 64Mi
40+
# Usage example:
41+
# env:
42+
# HTTP_PROXY: http://proxy:3128
43+
# -- Environment variables.
44+
env: {}
4045

4146
# -- Container security context. More information in [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/).
4247
securityContext:

charts/test/unit/deployment_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,25 @@ func TestDeploymentOperatorSkipTLSVerify(t *testing.T) {
474474
assert.Equal(t, dd, deployment)
475475
}
476476

477+
func TestDeploymentOperatorEnv(t *testing.T) {
478+
options := &helm.Options{
479+
SetValues: map[string]string{
480+
"operator.env.HTTP_PROXY": "http://proxy:3128",
481+
},
482+
Version: helmChartVersion,
483+
}
484+
deployment := renderDeploymentManifest(t, options)
485+
dd := defaultDeployment()
486+
dd.Spec.Template.Spec.Containers[0].Env = []corev1.EnvVar{
487+
{
488+
Name: "HTTP_PROXY",
489+
Value: "http://proxy:3128",
490+
},
491+
}
492+
493+
assert.Equal(t, dd, deployment)
494+
}
495+
477496
func TestDeploymentKubeRbacProxyImage(t *testing.T) {
478497
options := &helm.Options{
479498
SetValues: map[string]string{

0 commit comments

Comments
 (0)