Skip to content
Closed
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
11 changes: 11 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,17 @@ server_tls_key_file = /etc/pgbouncer/server.key
{{- end }}
{{- end }}

{{/* Create the name of the worker celery service account to use */}}
{{- define "worker.celery.serviceAccountName" -}}
{{- $filteredCeleryServiceAccount := include "removeNilFields" .Values.workers.celery.serviceAccount | fromYaml -}}
{{- $serviceAccount := include "workersMergeValues" (list .Values.workers.serviceAccount $filteredCeleryServiceAccount "" list) | fromYaml -}}
{{- if and (hasKey .Values.workers "name") (ne .Values.workers.name "default") }}
{{- include "_serviceAccountNameGen" (merge (dict "sa" $serviceAccount "key" "workers" "nameSuffix" (printf "%s-%s" "worker" .Values.workers.name)) .) -}}
{{- else }}
{{- include "_serviceAccountNameGen" (merge (dict "sa" $serviceAccount "key" "workers" "nameSuffix" "worker") .) -}}
{{- end }}
{{- end }}

{{/* Create the name of the worker kubernetes service account to use */}}
{{- define "worker.kubernetes.serviceAccountName" -}}
{{- include "_serviceAccountName" (merge (dict "key" "workers" "subKey" "kubernetes" "nameSuffix" "worker-kubernetes") .) -}}
Expand Down
11 changes: 9 additions & 2 deletions chart/templates/rbac/job-launcher-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ roleRef:
name: {{ include "airflow.fullname" . }}-job-launcher-role
{{- end }}
subjects:
{{- $workerServiceAccountName := include "worker.serviceAccountName" $ }}
{{- $workerCeleryServiceAccountName := include "worker.celery.serviceAccountName" $ }}
{{- if and .Values.scheduler.enabled (or (contains "LocalExecutor" .Values.executor) (contains "KubernetesExecutor" .Values.executor)) }}
- kind: ServiceAccount
name: {{ include "scheduler.serviceAccountName" $ }}
namespace: "{{ $.Release.Namespace }}"
{{- end }}
{{- if or (contains "CeleryExecutor" .Values.executor) (and (contains "KubernetesExecutor" .Values.executor) (eq .Values.workers.kubernetes.serviceAccount.create nil)) }}
{{- if contains "CeleryExecutor" .Values.executor }}
- kind: ServiceAccount
name: {{ include "worker.serviceAccountName" $ }}
name: {{ $workerCeleryServiceAccountName }}
namespace: "{{ $.Release.Namespace }}"
{{- end }}
{{- if and (contains "KubernetesExecutor" .Values.executor) (eq .Values.workers.kubernetes.serviceAccount.create nil) (or (not (contains "CeleryExecutor" .Values.executor)) (ne $workerServiceAccountName $workerCeleryServiceAccountName)) }}
- kind: ServiceAccount
name: {{ $workerServiceAccountName }}
namespace: "{{ $.Release.Namespace }}"
{{- end }}
{{- if and (or .Values.workers.kubernetes.serviceAccount.create .Values.workers.kubernetes.serviceAccount.name) (contains "KubernetesExecutor" .Values.executor) }}
Expand Down
11 changes: 9 additions & 2 deletions chart/templates/rbac/pod-launcher-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ roleRef:
name: {{ include "airflow.fullname" . }}-pod-launcher-role
{{- end }}
subjects:
{{- $workerServiceAccountName := include "worker.serviceAccountName" $ }}
{{- $workerCeleryServiceAccountName := include "worker.celery.serviceAccountName" $ }}
{{- if and .Values.scheduler.enabled (or (contains "LocalExecutor" .Values.executor) (contains "KubernetesExecutor" .Values.executor)) }}
- kind: ServiceAccount
name: {{ include "scheduler.serviceAccountName" $ }}
namespace: "{{ $.Release.Namespace }}"
{{- end }}
{{- if or (contains "CeleryExecutor" .Values.executor) (and (contains "KubernetesExecutor" .Values.executor) (eq .Values.workers.kubernetes.serviceAccount.create nil)) }}
{{- if contains "CeleryExecutor" .Values.executor }}
- kind: ServiceAccount
name: {{ include "worker.serviceAccountName" $ }}
name: {{ $workerCeleryServiceAccountName }}
namespace: "{{ $.Release.Namespace }}"
{{- end }}
{{- if and (contains "KubernetesExecutor" .Values.executor) (eq .Values.workers.kubernetes.serviceAccount.create nil) (or (not (contains "CeleryExecutor" .Values.executor)) (ne $workerServiceAccountName $workerCeleryServiceAccountName)) }}
- kind: ServiceAccount
name: {{ $workerServiceAccountName }}
namespace: "{{ $.Release.Namespace }}"
{{- end }}
{{- if and (or .Values.workers.kubernetes.serviceAccount.create .Values.workers.kubernetes.serviceAccount.name) (contains "KubernetesExecutor" .Values.executor) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ roleRef:
kind: ClusterRole
name: system:openshift:scc:anyuid
subjects:
{{- if or (contains "CeleryExecutor" .Values.executor) (and (contains "KubernetesExecutor" .Values.executor) (eq .Values.workers.kubernetes.serviceAccount.create nil)) }}
{{- $workerServiceAccountName := include "worker.serviceAccountName" . }}
{{- $workerCeleryServiceAccountName := include "worker.celery.serviceAccountName" . }}
{{- if contains "CeleryExecutor" .Values.executor }}
- kind: ServiceAccount
name: {{ include "worker.serviceAccountName" . }}
name: {{ $workerCeleryServiceAccountName }}
namespace: "{{ .Release.Namespace }}"
{{- end }}
{{- if and (contains "KubernetesExecutor" .Values.executor) (eq .Values.workers.kubernetes.serviceAccount.create nil) (or (not (contains "CeleryExecutor" .Values.executor)) (ne $workerServiceAccountName $workerCeleryServiceAccountName)) }}
- kind: ServiceAccount
name: {{ $workerServiceAccountName }}
namespace: "{{ .Release.Namespace }}"
{{- end }}
{{- if and (or .Values.workers.kubernetes.serviceAccount.create .Values.workers.kubernetes.serviceAccount.name) (contains "KubernetesExecutor" .Values.executor) }}
Expand Down
44 changes: 44 additions & 0 deletions chart/tests/helm_tests/airflow_aux/test_job_launcher_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,50 @@ def test_worker_role_binding_should_exists(self, executor):
"namespace": "airflow",
}

def test_worker_role_binding_uses_celery_service_account_name(self):
docs = render_chart(
name="prod",
namespace="airflow",
values={
"rbac": {"create": True},
"allowJobLaunching": True,
"executor": "CeleryExecutor",
"workers": {"celery": {"serviceAccount": {"name": "custom-worker"}}},
},
show_only=["templates/rbac/job-launcher-rolebinding.yaml"],
)

assert jmespath.search("subjects[?name=='custom-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "custom-worker",
"namespace": "airflow",
}
assert jmespath.search("subjects[?name=='prod-airflow-worker']", docs[0]) == []

def test_worker_role_binding_keeps_kubernetes_fallback_service_account_when_celery_differs(self):
docs = render_chart(
name="prod",
namespace="airflow",
values={
"rbac": {"create": True},
"allowJobLaunching": True,
"executor": "CeleryExecutor,KubernetesExecutor",
"workers": {"celery": {"serviceAccount": {"name": "custom-worker"}}},
},
show_only=["templates/rbac/job-launcher-rolebinding.yaml"],
)

assert jmespath.search("subjects[?name=='custom-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "custom-worker",
"namespace": "airflow",
}
assert jmespath.search("subjects[?name=='prod-airflow-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "prod-airflow-worker",
"namespace": "airflow",
}

def test_worker_role_binding_should_not_exists(self):
docs = render_chart(
name="prod",
Expand Down
44 changes: 44 additions & 0 deletions chart/tests/helm_tests/airflow_aux/test_pod_launcher_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,50 @@ def test_worker_role_binding_should_exists(self, executor):
"namespace": "airflow",
}

def test_worker_role_binding_uses_celery_service_account_name(self):
docs = render_chart(
name="prod",
namespace="airflow",
values={
"rbac": {"create": True},
"allowPodLaunching": True,
"executor": "CeleryExecutor",
"workers": {"celery": {"serviceAccount": {"name": "custom-worker"}}},
},
show_only=["templates/rbac/pod-launcher-rolebinding.yaml"],
)

assert jmespath.search("subjects[?name=='custom-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "custom-worker",
"namespace": "airflow",
}
assert jmespath.search("subjects[?name=='prod-airflow-worker']", docs[0]) == []

def test_worker_role_binding_keeps_kubernetes_fallback_service_account_when_celery_differs(self):
docs = render_chart(
name="prod",
namespace="airflow",
values={
"rbac": {"create": True},
"allowPodLaunching": True,
"executor": "CeleryExecutor,KubernetesExecutor",
"workers": {"celery": {"serviceAccount": {"name": "custom-worker"}}},
},
show_only=["templates/rbac/pod-launcher-rolebinding.yaml"],
)

assert jmespath.search("subjects[?name=='custom-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "custom-worker",
"namespace": "airflow",
}
assert jmespath.search("subjects[?name=='prod-airflow-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "prod-airflow-worker",
"namespace": "airflow",
}

def test_worker_role_binding_should_not_exists(self):
docs = render_chart(
name="prod",
Expand Down
19 changes: 19 additions & 0 deletions chart/tests/helm_tests/security/test_scc_rolebinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ def test_worker_role_binding_should_exists(self, executor):
"namespace": "airflow",
}

def test_worker_role_binding_uses_celery_service_account_name(self):
docs = render_chart(
name="prod",
namespace="airflow",
values={
"rbac": {"create": True, "createSCCRoleBinding": True},
"executor": "CeleryExecutor",
"workers": {"celery": {"serviceAccount": {"name": "custom-worker"}}},
},
show_only=["templates/rbac/security-context-constraint-rolebinding.yaml"],
)

assert jmespath.search("subjects[?name=='custom-worker'] | [0]", docs[0]) == {
"kind": "ServiceAccount",
"name": "custom-worker",
"namespace": "airflow",
}
assert jmespath.search("subjects[?name=='prod-airflow-worker']", docs[0]) == []

def test_worker_role_binding_should_not_exists(self):
docs = render_chart(
name="prod",
Expand Down