Skip to content

Commit 329b842

Browse files
authored
fix(chart): explicitly set namespace based on release (#435)
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]>
1 parent 8bcff6a commit 329b842

26 files changed

+72
-1
lines changed

Diff for: charts/atlantis/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: v1
33
appVersion: v0.30.0
44
description: A Helm chart for Atlantis https://www.runatlantis.io
55
name: atlantis
6-
version: 5.9.0
6+
version: 5.9.1
77
keywords:
88
- terraform
99
home: https://www.runatlantis.io

Diff for: charts/atlantis/templates/configmap-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: ConfigMap
44
metadata:
55
name: {{ template "atlantis.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/configmap-gitconfig-init.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: ConfigMap
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-gitconfig-init
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/configmap-init-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: ConfigMap
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-init-config
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/configmap-repo-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: ConfigMap
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-repo-config
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/ingress.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ apiVersion: {{ $apiVersion }}
1818
kind: Ingress
1919
metadata:
2020
name: {{ $fullName }}
21+
namespace: {{ .Release.Namespace }}
2122
labels:
2223
{{- include "atlantis.labels" . | nindent 4 }}
2324
{{- if .Values.ingress.labels }}

Diff for: charts/atlantis/templates/podmonitor.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: monitoring.googleapis.com/v1
33
kind: PodMonitoring
44
metadata:
55
name: {{ template "atlantis.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- if or .Values.service.annotations .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/pvc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: PersistentVolumeClaim
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-data
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/role.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
33
kind: Role
44
metadata:
55
name: {{ template "atlantis.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/rolebinding.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
33
kind: RoleBinding
44
metadata:
55
name: {{ template "atlantis.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-api.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.apiSecretName" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-aws.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-aws
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-basic-auth.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-basic-auth
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-gitconfig.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-gitconfig
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-netrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-netrc
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-redis.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-redis
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/secret-service-account.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ apiVersion: v1
44
kind: Secret
55
metadata:
66
name: {{ $name }}
7+
namespace: {{ $.Release.Namespace }}
78
labels:
89
component: service-account-secret
910
{{- include "atlantis.labels" $ | nindent 4 }}

Diff for: charts/atlantis/templates/secret-webhook.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-webhook
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
name: {{ template "atlantis.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
56
labels:
67
{{- include "atlantis.labels" . | nindent 4 }}
78
{{- if or .Values.service.annotations .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/serviceaccount.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: ServiceAccount
44
metadata:
55
name: {{ template "atlantis.serviceAccountName" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- if or .Values.serviceAccount.annotations .Values.extraAnnotations }}

Diff for: charts/atlantis/templates/servicemonitor.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: monitoring.coreos.com/v1
33
kind: ServiceMonitor
44
metadata:
55
name: {{ template "atlantis.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "atlantis.labels" . | nindent 4 }}
89
{{- with .Values.servicemonitor.additionalLabels }}

Diff for: charts/atlantis/templates/statefulset.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: apps/v1
22
kind: StatefulSet
33
metadata:
44
name: {{ template "atlantis.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
56
labels:
67
{{- include "atlantis.labels" . | nindent 4 }}
78
{{- with .Values.statefulSet.labels }}

Diff for: charts/atlantis/templates/tests/test-atlantis-configmap.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: ConfigMap
44
metadata:
55
name: {{ template "atlantis.fullname" . }}-tests
6+
namespace: {{ .Release.Namespace }}
67
data:
78
tests.bats: |-
89
setup() {

Diff for: charts/atlantis/templates/tests/test-atlantis-pod.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Pod
44
metadata:
55
name: "{{ .Release.Name }}-ui-test"
6+
namespace: {{ .Release.Namespace }}
67
annotations:
78
helm.sh/hook: test
89
{{- with .Values.test.annotations }}

Diff for: charts/atlantis/templates/webhook-ingress.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ apiVersion: {{ $apiVersion }}
1818
kind: Ingress
1919
metadata:
2020
name: {{ $fullName }}-secondary
21+
namespace: {{ .Release.Namespace }}
2122
labels:
2223
{{- include "atlantis.labels" . | nindent 4 }}
2324
{{- with .Values.webhook_ingress.labels }}

Diff for: charts/atlantis/tests/misc_test.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
suite: test miscellaneous cases
2+
templates:
3+
- "*.yaml"
4+
chart:
5+
appVersion: test-appVersion
6+
release:
7+
name: my-release
8+
namespace: my-namespace
9+
tests:
10+
- it: ensure namespaces are specified in all resources
11+
set:
12+
config: "dummy"
13+
gitconfigReadOnly: false
14+
gitconfig: "dummy"
15+
initConfig:
16+
enabled: true
17+
repoConfig: "dummy"
18+
podMonitor:
19+
enabled: true
20+
servicemonitor:
21+
enabled: true
22+
enableKubernetesBackend: true
23+
api:
24+
secret: "dummy"
25+
aws:
26+
config: "dummy"
27+
basicAuth:
28+
username: "dummy"
29+
password: "dummy"
30+
netrc: "dummy"
31+
redis:
32+
password: "dummy"
33+
serviceAccountSecrets:
34+
credentials: "dummy"
35+
webhook_ingress:
36+
enabled: true
37+
extraManifests:
38+
- apiVersion: v1
39+
kind: Pod
40+
metadata:
41+
name: dummy
42+
namespace: "my-namespace"
43+
44+
asserts:
45+
- equal:
46+
path: metadata.namespace
47+
value: my-namespace

0 commit comments

Comments
 (0)