Skip to content

Commit

Permalink
Better handling of PATH env var with initConfig (#401)
Browse files Browse the repository at this point in the history
* πŸ‘” add new exclusion for PATH env

* ⬆️ bump chart

* ⬆️ bump chart minor

* ✨ Add new PATH envvar logic

* βœ… Add test for new logic

* πŸ“ update doc
  • Loading branch information
vmdude committed Jul 2, 2024
1 parent e984db5 commit a72f86c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/atlantis/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
appVersion: v0.28.3
description: A Helm chart for Atlantis https://www.runatlantis.io
name: atlantis
version: 5.2.1
version: 5.3.0
keywords:
- terraform
home: https://www.runatlantis.io
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extraManifests:
| extraArgs | list | `[]` | Optionally specify extra arguments for the Atlantis pod. Check values.yaml for examples. |
| extraContainers | list | `[]` | Optionally specify extra containers for the Atlantis pod. Check values.yaml for examples. |
| extraManifests | list | `[]` | Optionally specify additional manifests to be created. Check values.yaml for examples. |
| extraPath | string | `""` | Additional path (`:` separated) that will be appended to the system `PATH` environment variable. |
| extraVolumeMounts | list | `[]` | Optionally specify additional volume mounts for the container. Check values.yaml for examples. |
| extraVolumes | list | `[]` | Optionally specify additional volumes for the pod. Check values.yaml for examples. |
| fullnameOverride | string | `""` | Provide a name to substitute for the full names of resources. |
Expand Down
13 changes: 13 additions & 0 deletions charts/atlantis/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,16 @@ heritage: {{ .Release.Service }}
{{ toYaml .Values.commonLabels }}
{{- end }}
{{- end -}}

{{/*
Define PATH environment variable that will be used system-wide.
*/}}
{{- define "atlantis.pathEnvironmentVariable" -}}
{{- if .Values.extraPath }}
{{- printf "%s:" .Values.extraPath -}}
{{- end -}}
{{- if .Values.initConfig.sharedDir }}
{{- printf "%s:" .Values.initConfig.sharedDir -}}
{{- end -}}
{{- printf "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" }}
{{- end -}}
4 changes: 2 additions & 2 deletions charts/atlantis/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ spec:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
- name: PATH
value: {{ template "atlantis.pathEnvironmentVariable" . }}
{{- range $key, $value := .Values.environment }}
- name: {{ $key }}
value: {{ $value | quote }}
Expand Down Expand Up @@ -485,8 +487,6 @@ spec:
value: {{ .Values.aws.directory }}/config
{{- end }}
{{- if .Values.initConfig.enabled }}
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:{{ .Values.initConfig.sharedDir }}
- name: INIT_SHARED_DIR
value: {{ .Values.initConfig.sharedDir }}
{{- end }}
Expand Down
57 changes: 57 additions & 0 deletions charts/atlantis/tests/statefulset_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ tests:
- equal:
path: spec.template.spec.containers[0].env
value:
- name: PATH
value: /plugins:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: ATLANTIS_DATA_DIR
value: /atlantis-data
- name: ATLANTIS_REPO_ALLOWLIST
Expand Down Expand Up @@ -895,3 +897,58 @@ tests:
- equal:
path: spec.template.spec.terminationGracePeriodSeconds
value: 30
- it: extraPath
template: statefulset.yaml
set:
extraPath: "/foo:/bar"
asserts:
- equal:
path: spec.template.spec.containers[0].env
value:
- name: PATH
value: /foo:/bar:/plugins:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: ATLANTIS_DATA_DIR
value: /atlantis-data
- name: ATLANTIS_REPO_ALLOWLIST
value: <replace-me>
- name: ATLANTIS_PORT
value: "4141"
- name: ATLANTIS_ATLANTIS_URL
value: http://
- it: sharedDirPath
template: statefulset.yaml
set:
initConfig.sharedDir: "/home/atlantis"
asserts:
- equal:
path: spec.template.spec.containers[0].env
value:
- name: PATH
value: /home/atlantis:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: ATLANTIS_DATA_DIR
value: /atlantis-data
- name: ATLANTIS_REPO_ALLOWLIST
value: <replace-me>
- name: ATLANTIS_PORT
value: "4141"
- name: ATLANTIS_ATLANTIS_URL
value: http://
- it: extraPathWithSharedDirPath
template: statefulset.yaml
set:
initConfig.sharedDir: "/home/atlantis"
extraPath: "/foo:/bar"
asserts:
- equal:
path: spec.template.spec.containers[0].env
value:
- name: PATH
value: /foo:/bar:/home/atlantis:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: ATLANTIS_DATA_DIR
value: /atlantis-data
- name: ATLANTIS_REPO_ALLOWLIST
value: <replace-me>
- name: ATLANTIS_PORT
value: "4141"
- name: ATLANTIS_ATLANTIS_URL
value: http://
4 changes: 4 additions & 0 deletions charts/atlantis/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@
"type": "string",
"description": "Name of a Secret for Atlantis' HTTPS certificate containing the following data items `tls.crt` with the public certificate and `tls.key` with the private key."
},
"extraPath": {
"type": "string",
"description": "Additional paths that will be appended to the system `PATH` environment variable. These paths should be separated with `:` to match system notation."
},
"environment": {
"type": "object",
"description": "Map of environment variables for the container.",
Expand Down
3 changes: 3 additions & 0 deletions charts/atlantis/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ enableKubernetesBackend: false
# -- TLS Secret Name for Atlantis pod.
tlsSecretName: ""

# -- Additional path (`:` separated) that will be appended to the system `PATH` environment variable.
extraPath: ""

# -- Environtment values to add to the Atlantis pod.
# Check values.yaml for examples.
environment: {}
Expand Down

0 comments on commit a72f86c

Please sign in to comment.