Skip to content
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

Add support for adding securityContext in the initContainer of the da… #35593

Merged
merged 2 commits into from
Nov 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions chart/templates/dag-processor/dag-processor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{{- $revisionHistoryLimit := or .Values.dagProcessor.revisionHistoryLimit .Values.revisionHistoryLimit }}
{{- $securityContext := include "airflowPodSecurityContext" (list . .Values.dagProcessor) }}
{{- $containerSecurityContext := include "containerSecurityContext" (list . .Values.dagProcessor) }}
{{- $containerSecurityContextWaitForMigrations := include "containerSecurityContext" (list . .Values.dagProcessor.waitForMigrations) }}
{{- $containerLifecycleHooks := or .Values.dagProcessor.containerLifecycleHooks .Values.containerLifecycleHooks }}
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -120,6 +121,7 @@ spec:
resources: {{- toYaml .Values.dagProcessor.resources | nindent 12 }}
image: {{ template "airflow_image_for_migrations" . }}
imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
securityContext: {{ $containerSecurityContextWaitForMigrations | nindent 12 }}
volumeMounts:
{{- if .Values.volumeMounts }}
{{- toYaml .Values.volumeMounts | nindent 12 }}
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,9 @@ dagProcessor:
# Whether to create init container to wait for db migrations
enabled: true
env: []
# Detailed default security context for waitForMigrations for container level
securityContexts:
container: {}

env: []

Expand Down
23 changes: 23 additions & 0 deletions helm_tests/airflow_core/test_dag_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ def test_disable_wait_for_migration(self):
)
assert actual is None

def test_wait_for_migration_security_contexts_are_configurable(self):
docs = render_chart(
values={
"dagProcessor": {
"enabled": True,
"waitForMigrations": {
"enabled": True,
"securityContexts": {
"container": {
"allowPrivilegeEscalation": False,
"readOnlyRootFilesystem": True,
},
},
},
},
},
show_only=["templates/dag-processor/dag-processor-deployment.yaml"],
)

assert {"allowPrivilegeEscalation": False, "readOnlyRootFilesystem": True} == jmespath.search(
"spec.template.spec.initContainers[0].securityContext", docs[0]
)

def test_should_add_extra_containers(self):
docs = render_chart(
values={
Expand Down