Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
91c7ee3
Use rbac.create Helm best practice
jaydesl Oct 23, 2020
08a72db
Enable serviceAccount creation per component
jaydesl Oct 23, 2020
4dd5a18
Add conditional to webserver SA creation
jaydesl Oct 23, 2020
af5ad7f
Use ServiceAccount name if given
jaydesl Nov 2, 2020
2eb4e3d
Add RBAC unit tests
jaydesl Nov 2, 2020
5501b40
rebase with master
DerekHeldtWerle Jan 27, 2021
1bbb62e
Adds service accounts to every deployable service, uid for pgbouncer/…
DerekHeldtWerle Jan 28, 2021
60c8edc
Revamps the way service accounts are generated, fixes all test issues…
DerekHeldtWerle Feb 10, 2021
40c707a
fixes service account templating for pod cleanup/launcher rolebindings
DerekHeldtWerle Feb 10, 2021
11ad521
remove airflow.name from template, add fullnameOverride and nameOverr…
DerekHeldtWerle Feb 10, 2021
b72a75d
fix formatting for failing tests, add nameOverride and fullnameOverri…
DerekHeldtWerle Feb 10, 2021
1c1a811
conditionally create worker service account using same checks as the …
DerekHeldtWerle Feb 12, 2021
8006251
remove serviceAccountAnnotations in favor of <service>.serviceaccount…
DerekHeldtWerle Mar 24, 2021
52a3769
adds cleanup sa annotations, missing job annotations from values.yaml…
DerekHeldtWerle Apr 23, 2021
6a4d59e
Update chart/values.schema.json
DerekHeldtWerle Apr 26, 2021
7e8d02d
Update chart/values.yaml
DerekHeldtWerle Apr 26, 2021
c1f1ad1
Adds test for service account annotations
DerekHeldtWerle Apr 27, 2021
627aee1
split jobs into createUserJob and migrateDatabaseJob, address other P…
DerekHeldtWerle Apr 30, 2021
d717574
update docs to include createUserJob and migrateDatabaseJob
DerekHeldtWerle Apr 30, 2021
521c93c
rebase with master and fix tests
DerekHeldtWerle Apr 30, 2021
9460b8b
remove unused jobs.serviceAccountName from helpers.yaml
DerekHeldtWerle Apr 30, 2021
3a9a580
change name of CLEANUP_DEPLOYMENT_KIND_NAME_TUPLES to DEPLOYMENT_NO_R…
DerekHeldtWerle Apr 30, 2021
659be35
fix static checks
DerekHeldtWerle Apr 30, 2021
0beaee4
fix path to newly added test
DerekHeldtWerle Apr 30, 2021
3c04f88
Apply suggestions from code review
kaxil Apr 30, 2021
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
2 changes: 1 addition & 1 deletion chart/files/pod-template-file.kubernetes-helm-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ spec:
nodeSelector: {{ toYaml .Values.nodeSelector | nindent 4 }}
affinity: {{ toYaml .Values.affinity | nindent 4 }}
tolerations: {{ toYaml .Values.tolerations | nindent 4 }}
serviceAccountName: '{{ .Release.Name }}-worker'
serviceAccountName: {{ include "worker.serviceAccountName" . }}
volumes:
{{- if .Values.dags.persistence.enabled }}
- name: dags
Expand Down
129 changes: 129 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
# specific language governing permissions and limitations
# under the License.

{{/*
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 "airflow.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 }}


{{/* Standard Airflow environment variables */}}
{{- define "standard_airflow_environment" }}
# Hard Coded Airflow Envs
Expand Down Expand Up @@ -372,6 +391,116 @@ server_tls_key_file = /etc/pgbouncer/server.key
{{ (printf "%s-airflow-config" .Release.Name) }}
{{- end }}

{{/*
Create the name of the webserver service account to use
*/}}
{{- define "webserver.serviceAccountName" -}}
{{- if .Values.webserver.serviceAccount.create -}}
{{ default (printf "%s-webserver" (include "airflow.fullname" .)) .Values.webserver.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.webserver.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the redis service account to use
*/}}
{{- define "redis.serviceAccountName" -}}
{{- if .Values.redis.serviceAccount.create -}}
{{ default (printf "%s-redis" (include "airflow.fullname" .)) .Values.redis.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.redis.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the flower service account to use
*/}}
{{- define "flower.serviceAccountName" -}}
{{- if .Values.flower.serviceAccount.create -}}
{{ default (printf "%s-flower" (include "airflow.fullname" .)) .Values.flower.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.flower.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the scheduler service account to use
*/}}
{{- define "scheduler.serviceAccountName" -}}
{{- if .Values.scheduler.serviceAccount.create -}}
{{ default (printf "%s-scheduler" (include "airflow.fullname" .)) .Values.scheduler.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.scheduler.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the statsd service account to use
*/}}
{{- define "statsd.serviceAccountName" -}}
{{- if .Values.statsd.serviceAccount.create -}}
{{ default (printf "%s-statsd" (include "airflow.fullname" .)) .Values.statsd.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.statsd.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the create user job service account to use
*/}}
{{- define "createUserJob.serviceAccountName" -}}
{{- if .Values.createUserJob.serviceAccount.create -}}
{{ default (printf "%s-create-user-job" (include "airflow.fullname" .)) .Values.createUserJob.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.createUserJob.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the migrate database job service account to use
*/}}
{{- define "migrateDatabaseJob.serviceAccountName" -}}
{{- if .Values.migrateDatabaseJob.serviceAccount.create -}}
{{ default (printf "%s-migrate-database-job" (include "airflow.fullname" .)) .Values.migrateDatabaseJob.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.migrateDatabaseJob.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the worker service account to use
*/}}
{{- define "worker.serviceAccountName" -}}
{{- if .Values.workers.serviceAccount.create -}}
{{ default (printf "%s-worker" (include "airflow.fullname" .)) .Values.workers.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.workers.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the pgbouncer service account to use
*/}}
{{- define "pgbouncer.serviceAccountName" -}}
{{- if .Values.pgbouncer.serviceAccount.create -}}
{{ default (printf "%s-pgbouncer" (include "airflow.fullname" .)) .Values.pgbouncer.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.pgbouncer.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the cleanup service account to use
*/}}
{{- define "cleanup.serviceAccountName" -}}
{{- if .Values.cleanup.serviceAccount.create -}}
{{ default (printf "%s-cleanup" (include "airflow.fullname" .)) .Values.cleanup.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.cleanup.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{ define "wait-for-migrations-command" }}
{{/* From Airflow 2.0.0 this can become [airflow, db, check-migrations] */}}
- python
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/cleanup/cleanup-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
{{ toYaml $affinity | indent 12 }}
tolerations:
{{ toYaml $tolerations | indent 12 }}
serviceAccountName: {{ .Release.Name }}-cleanup
serviceAccountName: {{ include "cleanup.serviceAccountName" . }}
{{- if or .Values.registry.secretName .Values.registry.connection }}
imagePullSecrets:
- name: {{ template "registry_secret" . }}
Expand Down
14 changes: 9 additions & 5 deletions chart/templates/cleanup/cleanup-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@
################################
## Airflow Cleanup ServiceAccount
#################################
{{- if and .Values.rbacEnabled .Values.cleanup.enabled }}
{{- if and .Values.cleanup.serviceAccount.create .Values.cleanup.enabled }}
kind: ServiceAccount
apiVersion: v1
metadata:
name: {{ .Release.Name }}-cleanup
name: {{ include "cleanup.serviceAccountName" . }}
labels:
tier: airflow
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.labels }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.cleanup.serviceAccount.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions chart/templates/flower/flower-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
{{ toYaml $affinity | indent 8 }}
tolerations:
{{ toYaml $tolerations | indent 8 }}
serviceAccountName: {{ include "flower.serviceAccountName" . }}
restartPolicy: Always
securityContext:
runAsUser: {{ .Values.uid }}
Expand Down
38 changes: 38 additions & 0 deletions chart/templates/flower/flower-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

######################################
## Airflow Flower ServiceAccount
######################################
{{- if and (or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor")) .Values.flower.serviceAccount.create }}
kind: ServiceAccount
apiVersion: v1
metadata:
name: {{ include "flower.serviceAccountName" . }}
labels:
tier: airflow
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.flower.serviceAccount.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
38 changes: 38 additions & 0 deletions chart/templates/jobs/create-user-job-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

###########################################
## Airflow Create User Job ServiceAccount
###########################################
{{- if and .Values.createUserJob.serviceAccount.create .Values.webserver.defaultUser.enabled }}
kind: ServiceAccount
apiVersion: v1
metadata:
name: {{ include "createUserJob.serviceAccountName" . }}
labels:
tier: airflow
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.createUserJob.serviceAccount.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spec:
{{ toYaml $affinity | indent 8 }}
tolerations:
{{ toYaml $tolerations | indent 8 }}
serviceAccountName: {{ include "createUserJob.serviceAccountName" . }}
{{- if or .Values.registry.secretName .Values.registry.connection }}
imagePullSecrets:
- name: {{ template "registry_secret" . }}
Expand Down
38 changes: 38 additions & 0 deletions chart/templates/jobs/migrate-database-job-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

#############################################
## Airflow Migrate Database Job ServiceAccount
##############################################
{{- if .Values.migrateDatabaseJob.serviceAccount.create }}
kind: ServiceAccount
apiVersion: v1
metadata:
name: {{ include "migrateDatabaseJob.serviceAccountName" . }}
labels:
tier: airflow
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.migrateDatabaseJob.serviceAccount.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ spec:
{{ toYaml $affinity | indent 8 }}
tolerations:
{{ toYaml $tolerations | indent 8 }}
serviceAccountName: {{ include "migrateDatabaseJob.serviceAccountName" . }}
{{- if or .Values.registry.secretName .Values.registry.connection }}
imagePullSecrets:
- name: {{ template "registry_secret" . }}
Expand Down
3 changes: 3 additions & 0 deletions chart/templates/pgbouncer/pgbouncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ spec:
{{ toYaml $affinity | indent 8 }}
tolerations:
{{ toYaml $tolerations | indent 8 }}
serviceAccountName: {{ include "pgbouncer.serviceAccountName" . }}
securityContext:
runAsUser: {{ .Values.pgbouncer.uid }}
restartPolicy: Always
{{- if or .Values.registry.secretName .Values.registry.connection }}
imagePullSecrets:
Expand Down
38 changes: 38 additions & 0 deletions chart/templates/pgbouncer/pgbouncer-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

######################################
## Airflow Pgbouncer ServiceAccount
######################################
{{- if and .Values.pgbouncer.serviceAccount.create .Values.pgbouncer.enabled }}
kind: ServiceAccount
apiVersion: v1
metadata:
name: {{ include "pgbouncer.serviceAccountName" . }}
labels:
tier: airflow
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.pgbouncer.serviceAccount.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion chart/templates/rbac/pod-cleanup-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
################################
## Airflow Cleanup Role
#################################
{{- if and .Values.rbacEnabled .Values.cleanup.enabled }}
{{- if and .Values.rbac.create .Values.cleanup.enabled }}
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down
Loading