Skip to content

Commit 6809163

Browse files
authored
Merge pull request #4 from GitGuardian/add-cluster-role-binding-config
Support disabling the creation of a ClusterRole and ClusterRoleBinding
2 parents a2e8d16 + ecb716b commit 6809163

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

charts/nhi-explorer/templates/clusterrole.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.clusterRole.create -}}
12
---
23
apiVersion: rbac.authorization.k8s.io/v1
34
kind: ClusterRole
@@ -12,3 +13,4 @@ rules:
1213
- apiGroups: [""]
1314
resources: ["secrets"]
1415
verbs: ["get", "list"]
16+
{{- end }}

charts/nhi-explorer/templates/clusterrolebinding.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if and .Values.serviceAccount.create .Values.clusterRole.create -}}
12
---
23
apiVersion: rbac.authorization.k8s.io/v1
34
kind: ClusterRoleBinding
@@ -13,3 +14,4 @@ roleRef:
1314
kind: ClusterRole
1415
name: {{ include "nhi-explorer.fullname" . }}
1516
apiGroup: rbac.authorization.k8s.io
17+
{{- end }}

charts/nhi-explorer/tests/clusterrole_test.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ templates:
77
- clusterrole.yaml
88
tests:
99
- it: "renders the ClusterRole with correct rules"
10+
set:
11+
clusterRole.create: true
1012
asserts:
1113
- isKind:
1214
of: ClusterRole
1315
- matchRegex:
1416
path: metadata.name
1517
pattern: -nhi-explorer$
18+
- it: "does not create a ClusterRole"
19+
set:
20+
clusterRole.create: false
21+
asserts:
22+
- hasDocuments:
23+
count: 0

charts/nhi-explorer/tests/clusterrolebinding_test.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,25 @@ values:
55
- ../test_values.yaml
66
templates:
77
- clusterrolebinding.yaml
8+
set:
9+
clusterRole.create: true
10+
serviceAccount.create: true
811
tests:
912
- it: should have the correct kind for ClusterRoleBinding
1013
asserts:
1114
- isAPIVersion:
1215
of: rbac.authorization.k8s.io/v1
16+
- it: "does not create a ClusterRoleBinding if clusterRole.create is false"
17+
set:
18+
clusterRole.create: false
19+
serviceAccount.create: true
20+
asserts:
21+
- hasDocuments:
22+
count: 0
23+
- it: "does not create a ClusterRoleBinding if serviceAccount.create is false"
24+
set:
25+
clusterRole.create: true
26+
serviceAccount.create: false
27+
asserts:
28+
- hasDocuments:
29+
count: 0

charts/nhi-explorer/values.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ serviceAccount:
4242
# If not set and create is true, a name is generated using the fullname template
4343
name: ''
4444

45+
clusterRole:
46+
# Specifies whether a clusterRole should be created with permissions to fetch k8s resources
47+
create: false
48+
name: ''
49+
4550
# This is for setting Kubernetes Annotations to a Pod.
4651
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
4752
podAnnotations: {}

0 commit comments

Comments
 (0)