Skip to content

Commit b13fdd0

Browse files
committed
add explicit cr and crb
1 parent c51782a commit b13fdd0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

helm_chart/templates/operator-roles-webhook.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
{{/* This cluster role and binding is necessary to allow the operator to automatically register ValidatingWebhookConfiguration. */}}
33
{{- if and .Values.operator.webhook.registerConfiguration .Values.operator.webhook.installClusterRole }}
4-
{{- $webhookClusterRoleName := printf "%s-%s-webhook" .Values.operator.name (include "mongodb-kubernetes-operator.namespace" .) }}
4+
{{- $webhookClusterRoleName := printf "%s-%s-webhook-cr" .Values.operator.name (include "mongodb-kubernetes-operator.namespace" .) }}
5+
{{- $webhookClusterRoleBindingName := printf "%s-%s-webhook-crb" .Values.operator.name (include "mongodb-kubernetes-operator.namespace" .) }}
56
{{- if not (lookup "rbac.authorization.k8s.io/v1" "ClusterRole" "" $webhookClusterRoleName) }}
67
---
78
kind: ClusterRole
@@ -35,7 +36,7 @@ rules:
3536
kind: ClusterRoleBinding
3637
apiVersion: rbac.authorization.k8s.io/v1
3738
metadata:
38-
name: {{ .Values.operator.name }}-{{ include "mongodb-kubernetes-operator.namespace" . }}-webhook-binding
39+
name: {{ $webhookClusterRoleBindingName }}
3940
roleRef:
4041
apiGroup: rbac.authorization.k8s.io
4142
kind: ClusterRole

helm_chart/tests/webhook_clusterrole_test.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
suite: test webhook consistent clusterrole and binding namecomm
1+
suite: test webhook consistent clusterrole and binding
22
templates:
33
- operator-roles-webhook.yaml
44
tests:
@@ -15,14 +15,17 @@ tests:
1515
- isKind:
1616
of: ClusterRoleBinding
1717
documentIndex: 1
18-
# The key fix: both should use the same dynamic name
1918
- equal:
2019
path: metadata.name
21-
value: mongodb-kubernetes-operator-NAMESPACE-webhook
20+
value: mongodb-kubernetes-operator-NAMESPACE-webhook-cr
2221
documentIndex: 0
22+
- equal:
23+
path: metadata.name
24+
value: mongodb-kubernetes-operator-NAMESPACE-webhook-crb
25+
documentIndex: 1
2326
- equal:
2427
path: roleRef.name
25-
value: mongodb-kubernetes-operator-NAMESPACE-webhook
28+
value: mongodb-kubernetes-operator-NAMESPACE-webhook-cr
2629
documentIndex: 1
2730

2831
# Test that different installations get unique names (prevents conflicts)
@@ -35,12 +38,15 @@ tests:
3538
release:
3639
namespace: custom-ns
3740
asserts:
38-
# Verify the naming pattern: {operator.name}-{namespace}-webhook
3941
- equal:
4042
path: metadata.name
41-
value: my-operator-custom-ns-webhook
43+
value: my-operator-custom-ns-webhook-cr
4244
documentIndex: 0
45+
- equal:
46+
path: metadata.name
47+
value: my-operator-custom-ns-webhook-crb
48+
documentIndex: 1
4349
- equal:
4450
path: roleRef.name
45-
value: my-operator-custom-ns-webhook
51+
value: my-operator-custom-ns-webhook-cr
4652
documentIndex: 1

0 commit comments

Comments
 (0)