Skip to content

Commit

Permalink
Chart: Fix Helm Hooks Weight for K8s Jobs (#20018)
Browse files Browse the repository at this point in the history
apache/airflow#18776 introduced a bug where it changed the Helm Hook weight for Create User job from 2 to 1. It needs to be 2 as we want to run migrations first even before create-user-job

GitOrigin-RevId: 7d97547257ae436ea35ee35cf1a598ebd080050f
  • Loading branch information
kaxil authored and Cloud Composer Team committed Sep 12, 2024
1 parent 2af0212 commit d880b92
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chart/templates/jobs/create-user-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metadata:
{{- $annotations := dict }}
{{- if .Values.createUserJob.useHelmHooks }}
{{- $_ := set $annotations "helm.sh/hook" "post-install,post-upgrade" }}
{{- $_ := set $annotations "helm.sh/hook-weight" "1" }}
{{- $_ := set $annotations "helm.sh/hook-weight" "2" }}
{{- $_ := set $annotations "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" }}
{{- end }}
{{- with $annotations := merge $annotations .Values.createUserJob.jobAnnotations }}
Expand Down
7 changes: 7 additions & 0 deletions chart/tests/test_airflow_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ def test_should_use_correct_image(self, use_default_image, expected_image):

for doc in docs:
assert expected_image == jmespath.search("spec.template.spec.initContainers[0].image", doc)

def test_should_set_correct_helm_hooks_weight(self):
docs = render_chart(
show_only=["templates/secrets/fernetkey-secret.yaml"],
)
annotations = jmespath.search("metadata.annotations", docs[0])
assert annotations["helm.sh/hook-weight"] == "0"
9 changes: 9 additions & 0 deletions chart/tests/test_create_user_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,12 @@ def test_should_disable_default_helm_hooks(self):
)
annotations = jmespath.search("spec.template.metadata.annotations", docs[0])
assert annotations is None

def test_should_set_correct_helm_hooks_weight(self):
docs = render_chart(
show_only=[
"templates/jobs/create-user-job.yaml",
],
)
annotations = jmespath.search("metadata.annotations", docs[0])
assert annotations["helm.sh/hook-weight"] == "2"
11 changes: 10 additions & 1 deletion chart/tests/test_migrate_database_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,14 @@ def test_should_disable_default_helm_hooks(self):
values={"migrateDatabaseJob": {"useHelmHooks": False}},
show_only=["templates/jobs/migrate-database-job.yaml"],
)
annotations = jmespath.search("spec.template.metadata.annotations", docs[0])
annotations = jmespath.search("metadata.annotations", docs[0])
assert annotations is None

def test_should_set_correct_helm_hooks_weight(self):
docs = render_chart(
show_only=[
"templates/jobs/migrate-database-job.yaml",
],
)
annotations = jmespath.search("metadata.annotations", docs[0])
assert annotations["helm.sh/hook-weight"] == "1"
10 changes: 10 additions & 0 deletions chart/tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,13 @@ def test_redis_resources_are_not_added_by_default(self):
show_only=["templates/redis/redis-statefulset.yaml"],
)
assert jmespath.search("spec.template.spec.containers[0].resources", docs[0]) == {}

def test_should_set_correct_helm_hooks_weight(self):
docs = render_chart(
values={
"executor": "CeleryExecutor",
},
show_only=["templates/secrets/redis-secrets.yaml"],
)
annotations = jmespath.search("metadata.annotations", docs[0])
assert annotations["helm.sh/hook-weight"] == "0"

0 comments on commit d880b92

Please sign in to comment.