Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RBAC for endpoint slices for functions and leases for LeaderElection #1160

Merged
merged 9 commits into from
Oct 19, 2023
2 changes: 2 additions & 0 deletions chart/openfaas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ yaml) |
| `operator.image` | Container image used for the openfaas-operator | See [values.yaml](./values.yaml) |
| `operator.kubeClientQPS` | QPS rate-limit for the Kubernetes client, (OpenFaaS for Enterprises) | `""` (defaults to 100) |
| `operator.kubeClientBurst` | Burst rate-limit for the Kubernetes client (OpenFaaS for Enterprises) | `""` (defaults to 250) |
| `operator.reconcileWorkers` | Number of reconciliation workers to run to convert Function CRs into Deployments | `1` |
| `operator.leaderElection.enabled`| When set to true, only one replica of the operator within the gateway pod will perform reconciliation | `false` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operator.reconcileQPS and operator.reconcileBurst should also be added to the configuration options.


### Functions

Expand Down
35 changes: 16 additions & 19 deletions chart/openfaas/templates/controller-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ rules:
- "get"
- "list"
- "watch"
- apiGroups:
- ""
resources:
- namespaces
verbs:
- create
- update
- delete
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["create", "delete", "update"]
{{- if .Values.openfaasPro }}
- apiGroups: ["discovery.k8s.io"]
resources: ["endpointslices"]
verbs: ["get", "list", "watch"]
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down Expand Up @@ -167,17 +167,14 @@ rules:
- update
- patch
- delete
- apiGroups:
- ""
resources:
- pods
- pods/log
- namespaces
- endpoints
verbs:
- get
- list
- watch
- apiGroups: [""]
resources: ["pods", "pods/log", "namespaces", "endpoints"]
verbs: ["get", "list", "watch"]
{{- if .Values.openfaasPro }}
- apiGroups: ["discovery.k8s.io"]
resources: ["endpointslices"]
verbs: ["get", "list", "watch"]
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down
14 changes: 14 additions & 0 deletions chart/openfaas/templates/gateway-dep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ spec:
- -operator=true
- "-license-file=/var/secrets/license/license"
env:
- name: reconcile_workers
value: {{ .Values.operator.reconcileWorkers | quote }}
- name: port
value: "8081"
- name: function_namespace
Expand Down Expand Up @@ -260,6 +262,18 @@ spec:
value: "{{ .Values.operator.kubeClientQPS }}"
- name: kube_client_burst
value: "{{ .Values.operator.kubeClientBurst }}"
- name: reconcile_qps
value: "{{ .Values.operator.reconcileQPS }}"
- name: reconcile_burst
value: "{{ .Values.operator.reconcileBurst }}"
{{ if .Values.operator.leaderElection.enabled }}
- name: leader_election
value: "true"
{{- end }}
{{- if eq (or .Values.operator.pprof false) true }}
- name: pprof
value: {{ .Values.operator.pprof | quote }}
{{- end }}
{{- if .Values.iam.enabled }}
- name: issuer_key_path
value: "/var/secrets/issuer-key/issuer.key"
Expand Down
28 changes: 28 additions & 0 deletions chart/openfaas/templates/operator-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,26 @@ rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "create"]
{{- if .Values.operator.leaderElection.enabled }}
- apiGroups: [""]
resources: ["configmaps"]
verbs: [ "update", "patch", "delete", "watch"]
{{- end }}
- apiGroups: ["apps", "extensions"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
# TODO: AE - remove endpoints from RBAC now that operator uses EndpointSlices
- apiGroups: [""]
resources: ["pods", "pods/log", "namespaces", "endpoints"]
verbs: ["get", "list", "watch"]
- apiGroups: ["discovery.k8s.io"]
resources: ["endpointslices"]
verbs: ["get", "list", "watch"]
# AE: For leader election
# PATCH may not be required?
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down Expand Up @@ -132,6 +146,9 @@ rules:
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "list", "watch", "create", "delete", "update"]
- apiGroups: ["discovery.k8s.io"]
resources: ["endpointslices"]
verbs: ["get", "list", "watch"]
- apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "delete", "update"]
Expand All @@ -141,6 +158,12 @@ rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "create"]
{{- if .Values.operator.leaderElection.enabled }}
- apiGroups: [""]
resources: ["configmaps"]
verbs: [ "update", "patch", "delete", "watch"]
{{- end }}
# TODO: AE - remove endpoints from RBAC now that operator uses EndpointSlices
- apiGroups: [""]
resources: ["pods", "pods/log", "namespaces", "endpoints"]
verbs: ["get", "list", "watch"]
Expand All @@ -151,6 +174,11 @@ rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
# AE: For leader election
# PATCH may not be required?
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
2 changes: 1 addition & 1 deletion chart/openfaas/values-pro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ clusterRole: true
# you can create a HPA rule to scale on CPU, but you must not scale beyond
# what's been purchased.
gateway:
replicas: 3
replicas: 1
# Required gateway configuration for Istio
# directFunctions: true
# probeFunctions: true
Expand Down
12 changes: 11 additions & 1 deletion chart/openfaas/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ queueMode: "" # Set to `jetstream` to run the async system backed
psp: false

# image pull policy for openfaas components, can change to `IfNotPresent` for an air-gapped environment
openfaasImagePullPolicy: "Always"
openfaasImagePullPolicy: "IfNotPresent"

functions:
imagePullPolicy: "Always" # Image pull policy for deployed functions, for OpenFaaS Pro you can also set: IfNotPresent and Never.
Expand Down Expand Up @@ -94,10 +94,20 @@ gateway:
operator:
image: ghcr.io/openfaasltd/faas-netes:0.4.23
create: false
# Unnecessary when running a single replica of the gateway
leaderElection:
enabled: false
reconcileWorkers: 2
resources:
requests:
memory: "120Mi"
cpu: "50m"
# When set to true, pprof will be enabled, and the
# service "faas-provider" will gain an extra port to
# expose the pprof endpoint, this cannot be used in production
# since it may bypass authentication, and should only be used
# for debugging purposes
pprof: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also set default values for reconcileQPS and reconcileBurst.


# For OpenFaaS for Enterprises, these numbers can be set higher,
# if experiencing rate limiting due to a large number of functions
Expand Down