Skip to content

Commit

Permalink
fix(chart): explicitly set namespace based on release (#435)
Browse files Browse the repository at this point in the history
On `helm install` or `upgrade`, the `--namespace` flag is respected
regardless. However, when using this chart for static templating, the
`--namespace` flag is ignored because the templates do not explicitly
set `.metadata.namespace` to `.Release.Namespace`, making it cumbersome
to customize the namespace.

Signed-off-by: valorl <[email protected]>
  • Loading branch information
valorl authored Nov 5, 2024
1 parent 8bcff6a commit 329b842
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 1 deletion.
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.30.0
description: A Helm chart for Atlantis https://www.runatlantis.io
name: atlantis
version: 5.9.0
version: 5.9.1
keywords:
- terraform
home: https://www.runatlantis.io
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/configmap-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/configmap-gitconfig-init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "atlantis.fullname" . }}-gitconfig-init
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/configmap-init-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "atlantis.fullname" . }}-init-config
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/configmap-repo-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "atlantis.fullname" . }}-repo-config
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ apiVersion: {{ $apiVersion }}
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- if .Values.ingress.labels }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- if or .Values.service.annotations .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ template "atlantis.fullname" . }}-data
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.apiSecretName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.fullname" . }}-aws
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-basic-auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.fullname" . }}-basic-auth
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-gitconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.fullname" . }}-gitconfig
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-netrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.fullname" . }}-netrc
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.fullname" . }}-redis
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-service-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ $name }}
namespace: {{ $.Release.Namespace }}
labels:
component: service-account-secret
{{- include "atlantis.labels" $ | nindent 4 }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/secret-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "atlantis.fullname" . }}-webhook
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- if or .Values.service.annotations .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "atlantis.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- if or .Values.serviceAccount.annotations .Values.extraAnnotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.servicemonitor.additionalLabels }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "atlantis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.statefulSet.labels }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "atlantis.fullname" . }}-tests
namespace: {{ .Release.Namespace }}
data:
tests.bats: |-
setup() {
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/tests/test-atlantis-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-ui-test"
namespace: {{ .Release.Namespace }}
annotations:
helm.sh/hook: test
{{- with .Values.test.annotations }}
Expand Down
1 change: 1 addition & 0 deletions charts/atlantis/templates/webhook-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ apiVersion: {{ $apiVersion }}
kind: Ingress
metadata:
name: {{ $fullName }}-secondary
namespace: {{ .Release.Namespace }}
labels:
{{- include "atlantis.labels" . | nindent 4 }}
{{- with .Values.webhook_ingress.labels }}
Expand Down
47 changes: 47 additions & 0 deletions charts/atlantis/tests/misc_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
suite: test miscellaneous cases
templates:
- "*.yaml"
chart:
appVersion: test-appVersion
release:
name: my-release
namespace: my-namespace
tests:
- it: ensure namespaces are specified in all resources
set:
config: "dummy"
gitconfigReadOnly: false
gitconfig: "dummy"
initConfig:
enabled: true
repoConfig: "dummy"
podMonitor:
enabled: true
servicemonitor:
enabled: true
enableKubernetesBackend: true
api:
secret: "dummy"
aws:
config: "dummy"
basicAuth:
username: "dummy"
password: "dummy"
netrc: "dummy"
redis:
password: "dummy"
serviceAccountSecrets:
credentials: "dummy"
webhook_ingress:
enabled: true
extraManifests:
- apiVersion: v1
kind: Pod
metadata:
name: dummy
namespace: "my-namespace"

asserts:
- equal:
path: metadata.namespace
value: my-namespace

0 comments on commit 329b842

Please sign in to comment.