This is an automated email from the ASF dual-hosted git repository. sijie pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pulsar-helm-chart.git
commit a6d1f86974cb4994b1530d16d9102a84664cb225 Author: roman-popenov <58950486+roman-pope...@users.noreply.github.com> AuthorDate: Thu Feb 13 16:45:31 2020 -0500 [Issue-6143][helm]: Add the rbac policy to give the brokers permissions to deploy functions (#6191) ### Motivation Fixes feature enhancement request #6143: Currently, there are quite a few undocumented steps that are needed to be performed manually in order to make sure that the functions can be submitted as pods in K8s runtime environment. It would be much better if this process would be automated. #### Proposed solution: Automate this process via helm install and update the helm charts with templates. ### Modifications I've added an additional `functionsAsPods` filed in extra components inside the values file. If the setting is set to `yes`, then it would add `serviceAccount` to the broker deployment. It will also add the rbac policy to give the brokers permissions to deploy functions. The policies can be found in the new `broker-rbac.yaml` template file. Moreover, it will also change the `functions_worker` settings and set the function runtime factory setting that can be found inside `broker-config [...] ### Verifying this change 1) Set `functionsAsPods: yes` inside helm values yaml file. 2) Follow the instructions on how deploying helm and run: `helm install pulsar --values pulsar/values-mini.yaml ./pulsar/`. 3) Wait until all the services are up and running. 4) Set up tenant, namespace. 5) Create a function, sink and source and submit it using the CLI to make sure the pods are running alongside the Pulsar cluster. In addition, set up such a flow where the data is flowing from source to topics, the processed by a function and sink outputs the data 6) Push data into cluster through the source and make sure it comes out of the sink into destination. There shouldn't be any errors in the logs of brokers, bookie, sources, sinks and functions. #### Modules affected: The changes in the PR are affecting the deployment using the helm charts. Now the if the flag `functionsAsPods` is set to `yes` inside the `values.yaml. file, the functions would run as pods. ### Documentation Currently, the documentations explaining the helm chart deployment process is lacking and this should be updated. --- pulsar/templates/broker-configmap.yaml | 7 +++- pulsar/templates/broker-deployment.yaml | 3 ++ pulsar/templates/broker-rbac.yaml | 60 +++++++++++++++++++++++++++++++++ pulsar/values-mini.yaml | 7 ++++ pulsar/values.yaml | 7 ++++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/pulsar/templates/broker-configmap.yaml b/pulsar/templates/broker-configmap.yaml index d577826..cf7b5c1 100644 --- a/pulsar/templates/broker-configmap.yaml +++ b/pulsar/templates/broker-configmap.yaml @@ -39,4 +39,9 @@ data: clusterName: {{ template "pulsar.fullname" . }} functionsWorkerEnabled: "true" PF_pulsarFunctionsCluster: {{ template "pulsar.fullname" . }} -{{ toYaml .Values.broker.configData | indent 2 }} + {{- if .Values.extra.functionsAsPods }} + PF_functionRuntimeFactoryClassName: "org.apache.pulsar.functions.runtime.kubernetes.KubernetesRuntimeFactory" + PF_functionRuntimeFactoryConfigs_submittingInsidePod: "true" + PF_functionRuntimeFactoryConfigs_jobNamespace: {{ .Values.namespace }} + {{- end }} + {{ toYaml .Values.broker.configData | indent 2 }} diff --git a/pulsar/templates/broker-deployment.yaml b/pulsar/templates/broker-deployment.yaml index 9c74764..4abd2b6 100644 --- a/pulsar/templates/broker-deployment.yaml +++ b/pulsar/templates/broker-deployment.yaml @@ -55,6 +55,9 @@ spec: tolerations: {{ toYaml .Values.broker.tolerations | indent 8 }} {{- end }} + {{- if .Values.extra.functionsAsPods }} + serviceAccount: "{{ template "pulsar.fullname" . }}-{{ .Values.broker.functions.component }}" + {{- end }} affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: diff --git a/pulsar/templates/broker-rbac.yaml b/pulsar/templates/broker-rbac.yaml new file mode 100644 index 0000000..8f37ed7 --- /dev/null +++ b/pulsar/templates/broker-rbac.yaml @@ -0,0 +1,60 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + {{- if .Values.extra.functionsAsPods }} +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRole +metadata: + name: "{{ template "pulsar.fullname" . }}-{{ .Values.broker.functions.component }}" +rules: +- apiGroups: [""] + resources: + - services + - configmaps + - pods + verbs: + - '*' +- apiGroups: + - apps + resources: + - statefulsets + verbs: + - '*' +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: "{{ template "pulsar.fullname" . }}-{{ .Values.broker.functions.component }}" + namespace: {{ .Values.namespace }} +--- + +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRoleBinding +metadata: + name: "{{ template "pulsar.fullname" . }}-{{ .Values.broker.functions.component }}" +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: "{{ template "pulsar.fullname" . }}-{{ .Values.broker.functions.component }}" +subjects: +- kind: ServiceAccount + name: "{{ template "pulsar.fullname" . }}-{{ .Values.broker.functions.component }}" + namespace: {{ .Values.namespace }} + {{- end }} diff --git a/pulsar/values-mini.yaml b/pulsar/values-mini.yaml index dadff58..49f65e0 100644 --- a/pulsar/values-mini.yaml +++ b/pulsar/values-mini.yaml @@ -49,6 +49,8 @@ extra: bastion: yes # Monitoring stack (prometheus and grafana) monitoring: yes + # Configure Kubernetes runtime for Functions + functionsAsPods: no ## Which pulsar image to use image: @@ -245,6 +247,11 @@ broker: pdb: usePolicy: yes maxUnavailable: 1 + ## Broker rbac + ## templates/broker-rbac.yaml + ## + functions: + component: functions-worker ## Pulsar Extra: Proxy ## templates/proxy-deployment.yaml diff --git a/pulsar/values.yaml b/pulsar/values.yaml index 84a2bba..d9fc502 100644 --- a/pulsar/values.yaml +++ b/pulsar/values.yaml @@ -49,6 +49,8 @@ extra: bastion: yes # Monitoring stack (prometheus and grafana) monitoring: yes + # Configure Kubernetes runtime for Functions + functionsAsPods: no ## Which pulsar image to use image: @@ -247,6 +249,11 @@ broker: pdb: usePolicy: yes maxUnavailable: 1 + ## Broker rbac + ## templates/broker-rbac.yaml + ## + functions: + component: functions-worker ## Pulsar Extra: Proxy ## templates/proxy-deployment.yaml