You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by gy...@apache.org on 2022/08/29 10:10:39 UTC

[flink-kubernetes-operator] 02/02: [FLINK-28734][helm] Add option to bind rolebinding to clusterrole

This is an automated email from the ASF dual-hosted git repository.

gyfora pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-kubernetes-operator.git

commit 8edfc0592c962dcc538fe3d1f0acd4c3f716e537
Author: Marton Balassi <ma...@apple.com>
AuthorDate: Thu Jul 28 17:19:55 2022 +0200

    [FLINK-28734][helm] Add option to bind rolebinding to clusterrole
---
 .../kubernetes/operator/FlinkOperatorITCase.java      |  2 +-
 helm/flink-kubernetes-operator/templates/_helpers.tpl | 19 +++++++++++++++----
 .../templates/flink-operator.yaml                     |  4 ++--
 helm/flink-kubernetes-operator/templates/rbac.yaml    |  4 ++--
 helm/flink-kubernetes-operator/templates/webhook.yaml |  6 +++---
 5 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/FlinkOperatorITCase.java b/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/FlinkOperatorITCase.java
index 4902ca78..aa0e07d8 100644
--- a/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/FlinkOperatorITCase.java
+++ b/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/FlinkOperatorITCase.java
@@ -49,7 +49,7 @@ public class FlinkOperatorITCase {
 
     private static final String TEST_NAMESPACE = "flink-operator-test";
     private static final String SERVICE_ACCOUNT = "flink-operator";
-    private static final String CLUSTER_ROLE_BINDING = "flink-operator-cluster-role-binding";
+    private static final String CLUSTER_ROLE_BINDING = "flink-operator-role-binding";
     private static final String FLINK_VERSION = "1.15.1";
     private static final String IMAGE = String.format("flink:%s", FLINK_VERSION);
     private static final Logger LOG = LoggerFactory.getLogger(FlinkOperatorITCase.class);
diff --git a/helm/flink-kubernetes-operator/templates/_helpers.tpl b/helm/flink-kubernetes-operator/templates/_helpers.tpl
index 630f5fef..aa53cb3d 100644
--- a/helm/flink-kubernetes-operator/templates/_helpers.tpl
+++ b/helm/flink-kubernetes-operator/templates/_helpers.tpl
@@ -134,7 +134,18 @@ Create the name of the job service account to use
 {{- end }}
 {{- end }}
 
-{{- define "validating-webhook-enabled" -}}
+{{/*
+Determine role scope based on name
+*/}}
+{{- define "flink-operator.roleScope" -}}
+{{- if contains ":" .role  }}
+{{- printf "ClusterRole" }}
+{{- else }}
+{{- printf "Role" }}
+{{- end }}
+{{- end }}
+
+{{- define "flink-operator.validating-webhook-enabled" -}}
 {{- if hasKey .Values.webhook "validator" }}
 {{- if .Values.webhook.validator.create }}
 {{- printf "true" }}
@@ -150,7 +161,7 @@ Create the name of the job service account to use
 {{- end }}
 {{- end }}
 
-{{- define "mutating-webhook-enabled" -}}
+{{- define "flink-operator.mutating-webhook-enabled" -}}
 {{- if hasKey .Values.webhook "mutator" }}
 {{- if .Values.webhook.mutator.create }}
 {{- printf "true" }}
@@ -166,8 +177,8 @@ Create the name of the job service account to use
 {{- end }}
 {{- end }}
 
-{{- define "webhook-enabled" -}}
-{{- if or (eq (include "validating-webhook-enabled" .) "true") (eq (include "mutating-webhook-enabled" .) "true") }}
+{{- define "flink-operator.webhook-enabled" -}}
+{{- if or (eq (include "flink-operator.validating-webhook-enabled" .) "true") (eq (include "flink-operator.mutating-webhook-enabled" .) "true") }}
 {{- printf "true" }}
 {{- else }}
 {{- printf "false" }}
diff --git a/helm/flink-kubernetes-operator/templates/flink-operator.yaml b/helm/flink-kubernetes-operator/templates/flink-operator.yaml
index 301077b9..8232a150 100644
--- a/helm/flink-kubernetes-operator/templates/flink-operator.yaml
+++ b/helm/flink-kubernetes-operator/templates/flink-operator.yaml
@@ -116,7 +116,7 @@ spec:
               path: /
               port: health-port
           {{- end }}
-        {{- if eq (include "webhook-enabled" .) "true" }}
+        {{- if eq (include "flink-operator.webhook-enabled" .) "true" }}
         - name: flink-webhook
           image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
           imagePullPolicy: {{ .Values.image.pullPolicy }}
@@ -179,7 +179,7 @@ spec:
         {{- if .Values.operatorVolumes.create }}
               {{- toYaml .Values.operatorVolumes.data | nindent 8 }}
         {{- end }}
-        {{- if eq (include "webhook-enabled" .) "true" }}
+        {{- if eq (include "flink-operator.webhook-enabled" .) "true" }}
         - name: keystore
           secret:
             secretName: webhook-server-cert
diff --git a/helm/flink-kubernetes-operator/templates/rbac.yaml b/helm/flink-kubernetes-operator/templates/rbac.yaml
index 19b090e0..52b87b62 100644
--- a/helm/flink-kubernetes-operator/templates/rbac.yaml
+++ b/helm/flink-kubernetes-operator/templates/rbac.yaml
@@ -133,7 +133,7 @@ metadata:
   labels:
     {{- include "flink-operator.labels" $ | nindent 4 }}
 roleRef:
-  kind: Role
+  kind: {{ $role := include "flink-operator.roleName" $ }}{{ include "flink-operator.roleScope" (dict "role" $role)}}
   name: {{ include "flink-operator.roleName" $ }}
   apiGroup: rbac.authorization.k8s.io
 subjects:
@@ -153,7 +153,7 @@ metadata:
   annotations:
     "helm.sh/resource-policy": keep
 roleRef:
-  kind: Role
+  kind: {{ $role := include "flink-operator.jobRoleName" $ }}{{ include "flink-operator.roleScope" (dict "role" $role)}}
   name: {{ include "flink-operator.jobRoleName" $ }}
   apiGroup: rbac.authorization.k8s.io
 subjects:
diff --git a/helm/flink-kubernetes-operator/templates/webhook.yaml b/helm/flink-kubernetes-operator/templates/webhook.yaml
index e8ad8599..9436b8fa 100644
--- a/helm/flink-kubernetes-operator/templates/webhook.yaml
+++ b/helm/flink-kubernetes-operator/templates/webhook.yaml
@@ -16,7 +16,7 @@
 # limitations under the License.
 ################################################################################
 ---
-{{- if eq (include "webhook-enabled" .) "true" }}
+{{- if eq (include "flink-operator.webhook-enabled" .) "true" }}
 ---
 apiVersion: v1
 kind: Service
@@ -76,7 +76,7 @@ metadata:
 spec:
   selfSigned: {}
 {{- end }}
-{{- if eq (include "validating-webhook-enabled" .) "true" }}
+{{- if eq (include "flink-operator.validating-webhook-enabled" .) "true" }}
 ---
 apiVersion: admissionregistration.k8s.io/v1
 kind: ValidatingWebhookConfiguration
@@ -112,7 +112,7 @@ webhooks:
         values: [{{- range .Values.watchNamespaces }}{{ . | quote }},{{- end}}]
   {{- end }}
 {{- end }}
-{{- if eq (include "mutating-webhook-enabled" .) "true" }}
+{{- if eq (include "flink-operator.mutating-webhook-enabled" .) "true" }}
 ---
 apiVersion: admissionregistration.k8s.io/v1
 kind: MutatingWebhookConfiguration