Skip to content

Add serviceAccount to postgreslet-support chart #80

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

Merged
merged 6 commits into from
Feb 8, 2021
Merged
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
73 changes: 73 additions & 0 deletions charts/postgreslet-support/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "postgreslet-support.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "postgreslet-support.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "postgreslet-support.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "postgreslet-support.labels" -}}
helm.sh/chart: {{ include "postgreslet-support.chart" . }}
{{ include "postgreslet-support.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "postgreslet-support.selectorLabels" -}}
app.kubernetes.io/name: {{ include "postgreslet-support.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the prefix to use in (cluster)role names and bindings
*/}}
{{- define "postgreslet-support.roleName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "postgreslet-support.fullname" .) .Values.serviceAccount.roleNamePrefix }}
{{- else }}
{{- default "postgreslet-support" .Values.serviceAccount.roleNamePrefix }}
{{- end }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "postgreslet-support.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "postgreslet-support.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
22 changes: 22 additions & 0 deletions charts/postgreslet-support/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "postgreslet-support.roleName" . }}
rules:
- apiGroups:
- "database.fits.cloud"
resources:
- postgres
verbs:
- get
- list
- watch
- update
- apiGroups:
- "database.fits.cloud"
resources:
- postgres/status
verbs:
- get
- update
- patch
12 changes: 12 additions & 0 deletions charts/postgreslet-support/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "postgreslet-support.roleName" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "postgreslet-support.roleName" . }}
subjects:
- kind: ServiceAccount
name: {{ include "postgreslet-support.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
12 changes: 12 additions & 0 deletions charts/postgreslet-support/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "postgreslet-support.serviceAccountName" . }}
labels:
{{- include "postgreslet-support.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/postgreslet-support/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Default values for postgreslet-support.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

nameOverride: ""
fullnameOverride: ""

serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
# A prefix to use in all the (Cluster)Roles that are being created for this service account.
# If not set and create is true, a name is generated using the fullname template
roleNamePrefix: ""