Skip to content

Commit

Permalink
Update chart to match RBAC best practices for charts
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Mar 5, 2018
1 parent dff0605 commit 0681e06
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
5 changes: 3 additions & 2 deletions chart/stable/kubed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ The following tables lists the configurable parameters of the Kubed chart and th
| `criticalAddon` | If true, installs kubed operator as critical addon | `false` |
| `logLevel` | Log level for kubed | `3` |
| `nodeSelector` | Node labels for pod assignment | `{}` |
| `rbac.create` | install required rbac service account, roles and rolebindings | `false` |
| `rbac.serviceAccountName` | ServiceAccount Kubed will use (ignored if rbac.create=true) | `default` |
| `rbac.create` | If `true`, create and use RBAC resources | `true` |
| `serviceAccount.create` | If `true`, create a new service account | `true` |
| `serviceAccount.name` | Service account to be used. If not set and `serviceAccount.create` is `true`, a name is generated using the fullname template | `` |
| `apiserver.groupPriorityMinimum` | The minimum priority the group should have. | 10000 |
| `apiserver.versionPriority` | The ordering of this API inside of the group. | 15 |
| `apiserver.ca` | CA certificate used by main Kubernetes api server | `` |
Expand Down
11 changes: 11 additions & 0 deletions chart/stable/kubed/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" $name .Release.Name | trunc 63 -}}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "kubed.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "kubed.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
7 changes: 3 additions & 4 deletions chart/stable/kubed/templates/apiregistration.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- $ca := genCA "svc-cat-ca" 3650 }}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- $cn := printf "%s-%s" $name .Release.Name | trunc 63 -}}
{{- $cn := include "kubed.fullname" . -}}
{{- $altName1 := printf "%s.%s" $cn .Release.Namespace }}
{{- $altName2 := printf "%s.%s.svc" $cn .Release.Namespace }}
{{- $cert := genSignedCert $cn nil (list $altName1 $altName2) 3650 $ca }}
Expand Down Expand Up @@ -55,7 +54,7 @@ roleRef:
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: {{ template "kubed.fullname" . }}
name: {{ template "kubed.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
---
# to delegate authentication and authorization
Expand All @@ -74,6 +73,6 @@ roleRef:
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: {{ template "kubed.fullname" . }}
name: {{ template "kubed.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{ end }}
2 changes: 1 addition & 1 deletion chart/stable/kubed/templates/cluster-role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ roleRef:
name: {{ template "kubed.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "kubed.fullname" . }}
name: {{ template "kubed.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{ end }}
2 changes: 1 addition & 1 deletion chart/stable/kubed/templates/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rules:
- networking.k8s.io
- storage.k8s.io
- monitoring.coreos.com
- kubedb.com
- kubed.com
- monitoring.appscode.com
- rbac.authorization.k8s.io
- stash.appscode.com
Expand Down
2 changes: 1 addition & 1 deletion chart/stable/kubed/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
scheduler.alpha.kubernetes.io/critical-pod: ''
{{- end }}
spec:
serviceAccountName: {{ if .Values.rbac.create }}{{ template "kubed.fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
serviceAccountName: {{ template "kubed.serviceAccountName" . }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 6 }}
Expand Down
4 changes: 2 additions & 2 deletions chart/stable/kubed/templates/service-account.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ if .Values.rbac.create }}
{{ if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "kubed.fullname" . }}
name: {{ template "kubed.serviceAccountName" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: "{{ template "kubed.name" . }}"
Expand Down
14 changes: 10 additions & 4 deletions chart/stable/kubed/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ logLevel: 3
## Ref: https://kubernetes.io/docs/user-guide/node-selection/
##
nodeSelector: {}

## Install Default RBAC roles and bindings
rbac:
## If true, create & use RBAC resources
create: false
## Ignored if rbac.create is true
serviceAccountName: default
# Specifies whether RBAC resources should be created
create: true

serviceAccount:
# Specifies whether a ServiceAccount should be created
create: true
# The name of the ServiceAccount to use.
# If not set and create is true, a name is generated using the fullname template
name:

apiserver:
# groupPriorityMinimum is the minimum priority the group should have. Please see
Expand Down

0 comments on commit 0681e06

Please sign in to comment.