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

feat: add support for watchNamespace in kuberay-apiserver #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions helm-chart/kuberay-apiserver/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

{{- if .Values.rbacEnable }}
# when we are installing in a single namespace, just iterate over a list of [.Release.Namespace] so we don't have to repeat the body of the rules in a different file
{{- $watchNamespaces := ternary (default (list .Release.Namespace) .Values.watchNamespace) (list .Release.Namespace) .Values.singleNamespaceInstall }}
{{- range $namespace := $watchNamespaces }}
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if .Values.singleNamespaceInstall }}
{{- if $.Values.singleNamespaceInstall }}
kind: Role
{{- else }}
kind: ClusterRole
{{- end }}
metadata:
labels:
app.kubernetes.io/name: {{ .Values.name }}
name: {{ .Values.name }}
app.kubernetes.io/name: {{ $.Values.name }}
name: {{ $.Values.name }}
namespace: {{ $namespace }}
rules:
- apiGroups:
- ray.io
Expand Down Expand Up @@ -51,3 +55,4 @@ rules:
- get
- list
{{- end }}
{{- end }}
20 changes: 13 additions & 7 deletions helm-chart/kuberay-apiserver/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
{{- if .Values.rbacEnable }}
{{- if .Values.singleNamespaceInstall }}
# when we are installing in a single namespace, just iterate over a list of [.Release.Namespace] so we don't have to repeat the body of the rules in a different file
{{- $watchNamespaces := ternary (default (list .Release.Namespace) .Values.watchNamespace) (list .Release.Namespace) .Values.singleNamespaceInstall }}
{{- range $namespace := $watchNamespaces }}
---
{{- if $.Values.singleNamespaceInstall }}
kind: RoleBinding
{{- else }}
kind: ClusterRoleBinding
{{- end }}
apiVersion: rbac.authorization.k8s.io/v1
metadata:
labels:
{{ include "kuberay-apiserver.labels" . | indent 4 }}
name: {{ include "kuberay-apiserver.fullname" . }}
{{ include "kuberay-apiserver.labels" $ | indent 4 }}
name: {{ include "kuberay-apiserver.fullname" $ }}
namespace: {{ $namespace }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: {{ .Release.Namespace }}
name: {{ $.Values.serviceAccount.name }}
namespace: {{ $.Release.Namespace }}
roleRef:
{{- if .Values.singleNamespaceInstall }}
{{- if $.Values.singleNamespaceInstall }}
kind: Role
{{- else }}
kind: ClusterRole
{{- end }}
name: {{ include "kuberay-apiserver.fullname" . }}
name: {{ include "kuberay-apiserver.fullname" $ }}
apiGroup: rbac.authorization.k8s.io
{{- end }}
{{- end }}
11 changes: 10 additions & 1 deletion helm-chart/kuberay-apiserver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,14 @@ route:

rbacEnable: true

# the chart can be installed by users with permissions to a single namespace only
# When singleNamespaceInstall is true:
# - Install namespaced RBAC resources such as Role and RoleBinding instead of cluster-scoped ones like ClusterRole and ClusterRoleBinding so that
# the chart can be installed by users with permissions restricted to a single namespace.
# - If "watchNamespace" is not set, the KubeRay apiserver will, by default, only able to view resources within its own namespace.
singleNamespaceInstall: false

# You can set watchNamespace to a list of namespaces that KubeRay apiserver should have permission to list CRDs for
# if singleNamespaceInstall is false, this setting is ignored
# watchNamespace:
# - n1
# - n2