forked from hashicorp/consul-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes hashicorp#20
- Loading branch information
Showing
5 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{- $rbacEnabled := (or (and (ne (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled) (and (eq (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled)) }} | ||
{{- $syncEnabled := (or (and (ne (.Values.syncCatalog.enabled | toString) "-") .Values.syncCatalog.enabled) (and (eq (.Values.syncCatalog.enabled | toString) "-") .Values.global.enabled)) }} | ||
{{- if (and $rbacEnabled $syncEnabled) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: consul:sync | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: consul:sync | ||
subjects: | ||
- kind: Group | ||
name: system:serviceaccounts:{{ .Release.Namespace }} | ||
apiGroup: rbac.authorization.k8s.io | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{{- $rbacEnabled := (or (and (ne (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled) (and (eq (.Values.rbac.enabled | toString) "-") .Values.rbac.enabled)) }} | ||
{{- $syncEnabled := (or (and (ne (.Values.syncCatalog.enabled | toString) "-") .Values.syncCatalog.enabled) (and (eq (.Values.syncCatalog.enabled | toString) "-") .Values.global.enabled)) }} | ||
{{- if (and $rbacEnabled $syncEnabled) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: consul:sync | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- services | ||
- endpoints | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- update | ||
- patch | ||
- delete | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "sync/ClusterRoleBinding: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: enable with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: disable with syncCatalog.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'syncCatalog.enabled=false' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: disable with rbac.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRoleBinding: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role-binding.yaml \ | ||
--set 'global.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "sync/ClusterRole: disabled by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRole: enable with global.enabled false" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -s 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "sync/ClusterRole: disable with syncCatalog.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'syncCatalog.enabled=false' \ | ||
--set 'rbac.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRole: disable with rbac.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'syncCatalog.enabled=true' \ | ||
--set 'rbac.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "sync/ClusterRole: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-x templates/sync-cluster-role.yaml \ | ||
--set 'global.enabled=false' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters