-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agent): create a clusterrolebinding if the clusterrole cluster-m…
…onitoring-view exists
- Loading branch information
1 parent
195499c
commit 097b41d
Showing
4 changed files
with
72 additions
and
1 deletion.
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
17 changes: 17 additions & 0 deletions
17
charts/agent/templates/clusterrolebinding-cluster-monitoring-view.yaml
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,17 @@ | ||
{{- $clusterRole := lookup "rbac.authorization.k8s.io/v1" "ClusterRole" "" "cluster-monitoring-view" -}} | ||
{{- if and .Values.rbac.create $clusterRole }} | ||
kind: ClusterRoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: {{ template "agent.fullname" .}}-cluster-monitoring-view | ||
labels: | ||
{{ include "agent.labels" . | indent 4 }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ template "agent.serviceAccountName" .}} | ||
namespace: {{ include "agent.namespace" . }} | ||
roleRef: | ||
kind: ClusterRole | ||
name: cluster-monitoring-view | ||
apiGroup: rbac.authorization.k8s.io | ||
{{- end }} |
46 changes: 46 additions & 0 deletions
46
charts/agent/tests/clusterrolebinding-cluster-monitoring-view-exist_test.yaml
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,46 @@ | ||
suite: Agent Cluster Role Binding cluster-monitoring-view (exist) | ||
templates: | ||
- templates/clusterrolebinding-cluster-monitoring-view.yaml | ||
kubernetesProvider: | ||
scheme: | ||
"rbac.authorization.k8s.io/v1/ClusterRole": | ||
gvr: | ||
group: "rbac.authorization.k8s.io" | ||
version: "v1" | ||
resource: "clusterroles" | ||
namespaced: false | ||
objects: | ||
- apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: cluster-monitoring-view | ||
|
||
tests: | ||
- it: Does not create the ClusterRoleBinding if rbac.create is false | ||
set: | ||
rbac: | ||
create: false | ||
asserts: | ||
- hasDocuments: | ||
count: 0 | ||
|
||
- it: Does create the ClusterRoleBinding if the ClusterRole exists | ||
asserts: | ||
- hasDocuments: | ||
count: 1 | ||
- containsDocument: | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
name: RELEASE-NAME-agent-cluster-monitoring-view | ||
- contains: | ||
path: subjects | ||
content: | ||
kind: ServiceAccount | ||
namespace: NAMESPACE | ||
name: RELEASE-NAME-agent | ||
- equal: | ||
path: roleRef | ||
value: | ||
kind: ClusterRole | ||
name: cluster-monitoring-view | ||
apiGroup: rbac.authorization.k8s.io |
8 changes: 8 additions & 0 deletions
8
charts/agent/tests/clusterrolebinding-cluster-monitoring-view-not-exist_test.yaml
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,8 @@ | ||
suite: Agent Cluster Role Binding cluster-monitoring-view (not exist) | ||
templates: | ||
- templates/clusterrolebinding-cluster-monitoring-view.yaml | ||
tests: | ||
- it: Does not create the ClusterRoleBinding if the ClusterRole does not exist | ||
asserts: | ||
- hasDocuments: | ||
count: 0 |