Skip to content

Commit

Permalink
[Issue-6143][helm]: Add the rbac policy to give the brokers permissio…
Browse files Browse the repository at this point in the history
…ns to deploy functions (apache#6191)

### Motivation
Fixes feature enhancement request apache#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-configmap.yaml`.
### 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.
  • Loading branch information
roman-popenov authored Feb 13, 2020
1 parent 33232ca commit bc1f078
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
60 changes: 60 additions & 0 deletions deployment/kubernetes/helm/pulsar/templates/broker-rbac.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 7 additions & 0 deletions deployment/kubernetes/helm/pulsar/values-mini.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions deployment/kubernetes/helm/pulsar/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc1f078

Please sign in to comment.