Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Ensure rules is always set.
Browse files Browse the repository at this point in the history
Fixes #178. The rules key must always be set, even if it's to be empty.
  • Loading branch information
lkysow committed Jun 7, 2019
1 parent 6fa9be9 commit 37bf1fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion templates/client-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ metadata:
release: {{ .Release.Name }}
{{- if (or .Values.global.enablePodSecurityPolicies .Values.global.bootstrapACLs) }}
rules:
{{- end }}
{{- if .Values.global.enablePodSecurityPolicies }}
- apiGroups: ["policy"]
resources: ["podsecuritypolicies"]
Expand All @@ -28,4 +27,7 @@ rules:
verbs:
- get
{{- end }}
{{- else}}
rules: []
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/server-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ rules:
- {{ template "consul.fullname" . }}-server
verbs:
- use
{{- else }}
rules: []
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions test/unit/client-clusterrole.bats
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ load _helpers
[ "${actual}" = "true" ]
}

# The rules key must always be set (#178).
@test "client/ClusterRole: rules empty with client.enabled=true" {
cd `chart_dir`
local actual=$(helm template \
-x templates/client-clusterrole.yaml \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq '.rules' | tee /dev/stderr)
[ "${actual}" = "[]" ]
}

#--------------------------------------------------------------------
# global.enablePodSecurityPolicies

Expand Down
11 changes: 11 additions & 0 deletions test/unit/server-clusterrole.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ load _helpers
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

# The rules key must always be set (#178).
@test "server/ClusterRole: rules empty with server.enabled=true" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-clusterrole.yaml \
--set 'server.enabled=true' \
. | tee /dev/stderr |
yq '.rules' | tee /dev/stderr)
[ "${actual}" = "[]" ]
}

0 comments on commit 37bf1fd

Please sign in to comment.