Skip to content

Commit

Permalink
[stable/redis-ha] feat: implement RBAC (helm#11842)
Browse files Browse the repository at this point in the history
* feat: implement RBAC

Signed-off-by: Vladimir Syromyatnikov <[email protected]>

* fix: typo in README

Signed-off-by: Vladimir Syromyatnikov <[email protected]>
  • Loading branch information
SweetOps authored and k8s-ci-robot committed Mar 1, 2019
1 parent dc2cf67 commit 6cb8277
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 32 deletions.
2 changes: 1 addition & 1 deletion stable/redis-ha/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ keywords:
- redis
- keyvalue
- database
version: 3.2.1
version: 3.3.0
appVersion: 5.0.3
description: Highly available Kubernetes implementation of Redis
icon: https://upload.wikimedia.org/wikipedia/en/thumb/6/6b/Redis_Logo.svg/1200px-Redis_Logo.svg.png
Expand Down
64 changes: 33 additions & 31 deletions stable/redis-ha/README.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions stable/redis-ha/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ Example output:
{{- replace "+" "_" .Chart.Version | printf "%s-%s" .Chart.Name -}}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "redis-ha.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "redis-ha.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
18 changes: 18 additions & 0 deletions stable/redis-ha/templates/redis-ha-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if and .Values.serviceAccount.create .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ template "redis-ha.fullname" . }}
labels:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: {{ template "redis-ha.fullname" . }}
rules:
- apiGroups:
- ""
resources:
- endpoints
verbs:
- get
{{- end }}
18 changes: 18 additions & 0 deletions stable/redis-ha/templates/redis-ha-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if and .Values.serviceAccount.create .Values.rbac.create }}
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "redis-ha.fullname" . }}
labels:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: {{ template "redis-ha.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "redis-ha.serviceAccountName" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "redis-ha.fullname" . }}
{{- end }}
11 changes: 11 additions & 0 deletions stable/redis-ha/templates/redis-ha-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "redis-ha.serviceAccountName" . }}
labels:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: {{ template "redis-ha.fullname" . }}
{{- end }}
1 change: 1 addition & 0 deletions stable/redis-ha/templates/redis-ha-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
{{- end }}
securityContext:
{{ toYaml .Values.securityContext | indent 8 }}
serviceAccountName: {{ template "redis-ha.serviceAccountName" . }}
initContainers:
{{- if and .Values.hostPath.path .Values.hostPath.chown }}
- name: hostpath-chown
Expand Down
17 changes: 17 additions & 0 deletions stable/redis-ha/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ replicas: 3
## Custom labels for the redis pod
labels: {}

## Pods Service Account
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
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 redis-ha.fullname template
# name:

## Role Based Access
## Ref: https://kubernetes.io/docs/admin/authorization/rbac/
##

rbac:
create: true

## Redis specific configuration options
redis:
port: 6379
Expand Down

0 comments on commit 6cb8277

Please sign in to comment.