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

Added support for using SHA digest of Docker images. #30214

Merged
merged 27 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
88abf33
Added support for using SHA sigest of Docker images.
elongl Mar 21, 2023
5505d0a
Added a comment to convery tag and digest precedence.
elongl Mar 21, 2023
31d2eff
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 21, 2023
b4728e1
Added to the values schema as well.
elongl Mar 21, 2023
fd744b2
Merge branch 'airflow-image-sha-digest' of github.com:elongl/airflow …
elongl Mar 21, 2023
eb5f3df
Fixed indentation.
elongl Mar 21, 2023
f8daac4
Added 'defaultAirflowDigest'.
elongl Mar 21, 2023
0c5784b
Update chart/values.schema.json
elongl Mar 21, 2023
94d73c2
Added a missing comma.
elongl Mar 21, 2023
f4fe4ab
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 21, 2023
75266f4
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 21, 2023
0477e1d
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 21, 2023
07553f8
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 22, 2023
ca57c02
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 22, 2023
e382ff4
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 23, 2023
8cbe8af
Added test-cases for SHA digest image.
elongl Mar 23, 2023
5f9f0f6
Merge branch 'airflow-image-sha-digest' of github.com:elongl/airflow …
elongl Mar 23, 2023
3b97287
Update tests/charts/test_airflow_common.py
elongl Mar 24, 2023
fd7f186
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 30, 2023
0a5f953
Updated template of default Airflow image.
elongl Mar 31, 2023
7be9671
Added a test case for the default Airflow image.
elongl Mar 31, 2023
49879ef
Merge branch 'main' into airflow-image-sha-digest
elongl Mar 31, 2023
f1f3d2f
Pulled main and resolved conflicts.
elongl Apr 8, 2023
0e070cb
Merge branch 'main' into airflow-image-sha-digest
elongl Apr 8, 2023
7b6f7c1
Update chart/templates/_helpers.yaml
elongl Apr 8, 2023
77c386c
Update chart/templates/_helpers.yaml
elongl Apr 8, 2023
834f2b0
Merge branch 'main' into airflow-image-sha-digest
elongl Apr 9, 2023
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
20 changes: 17 additions & 3 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,30 @@ If release name contains chart name it will be used as a full name.

{{/* This helper will change when customers deploy a new image */}}
{{- define "airflow_image" -}}
{{- printf "%s:%s" (.Values.images.airflow.repository | default .Values.defaultAirflowRepository) (.Values.images.airflow.tag | default .Values.defaultAirflowTag) }}
{{- $repository := .Values.images.airflow.repository | default .Values.defaultAirflowRepository -}}
{{- $tag := .Values.images.airflow.tag | default .Values.defaultAirflowTag -}}
{{- $digest := .Values.images.airflow.digest | default .Values.defaultAirflowDigest -}}
{{- if $digest }}
{{- printf "%s@%s" $repository $digest -}}
{{- else }}
{{- printf "%s:%s" $repository $tag -}}
{{- end }}
elongl marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}

{{- define "pod_template_image" -}}
{{- printf "%s:%s" (.Values.images.pod_template.repository | default .Values.defaultAirflowRepository) (.Values.images.pod_template.tag | default .Values.defaultAirflowTag) }}
{{- end }}

{{/* This helper is used for airflow containers that do not need the users code */}}
{{- define "default_airflow_image" -}}
{{- printf "%s:%s" .Values.defaultAirflowRepository .Values.defaultAirflowTag }}
{{ define "default_airflow_image" -}}
{{- $repository := .Values.defaultAirflowRepository -}}
{{- $tag := .Values.defaultAirflowTag -}}
{{- $digest := .Values.defaultAirflowDigest -}}
{{- if $digest }}
{{- printf "%s@%s" $repository $digest -}}
{{- else }}
{{- printf "%s:%s" $repository $tag -}}
{{- end }}
elongl marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}

{{ define "airflow_image_for_migrations" -}}
Expand Down
17 changes: 17 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
"default": "2.5.3",
"x-docsSection": "Common"
},
"defaultAirflowDigest": {
"description": "Default airflow digest to deploy. Overrides tag.",
"type": [
"string",
"null"
],
"default": null,
"x-docsSection": "Common"
},
"airflowVersion": {
"description": "Airflow version (Used to make some decisions based on Airflow Version being deployed).",
"type": "string",
Expand Down Expand Up @@ -477,6 +486,14 @@
],
"default": null
},
"digest": {
"description": "The airflow image digest. If set, it will override the tag.",
"type": [
"string",
"null"
],
"default": null
},
"pullPolicy": {
"description": "The airflow image pull policy.",
"type": "string",
Expand Down
5 changes: 5 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ defaultAirflowRepository: apache/airflow
# Default airflow tag to deploy
defaultAirflowTag: "2.5.3"

# Default airflow digest. If specified, it takes precedence over tag
defaultAirflowDigest: ~

# Airflow version (Used to make some decisions based on Airflow Version being deployed)
airflowVersion: "2.5.3"

Expand All @@ -59,6 +62,8 @@ images:
airflow:
repository: ~
tag: ~
# Specifying digest takes precedence over tag.
elongl marked this conversation as resolved.
Show resolved Hide resolved
digest: ~
elongl marked this conversation as resolved.
Show resolved Hide resolved
pullPolicy: IfNotPresent
# To avoid images with user code, you can turn this to 'true' and
# all the 'run-airflow-migrations' and 'wait-for-airflow-migrations' containers/jobs
Expand Down
43 changes: 35 additions & 8 deletions tests/charts/test_airflow_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,22 @@ def test_global_affinity_tolerations_topology_spread_constraints_and_node_select
assert "foo" == jmespath.search("topologySpreadConstraints[0].topologyKey", podSpec)

@pytest.mark.parametrize(
"use_default_image,expected_image",
"expected_image,tag,digest",
[
(True, "apache/airflow:2.1.0"),
(False, "apache/airflow:user-image"),
("apache/airflow:user-tag", "user-tag", None),
("apache/airflow@user-digest", None, "user-digest"),
("apache/airflow@user-digest", "user-tag", "user-digest"),
],
)
def test_should_use_correct_image(self, use_default_image, expected_image):
def test_should_use_correct_image(self, expected_image, tag, digest):
docs = render_chart(
values={
"defaultAirflowRepository": "apache/airflow",
"defaultAirflowTag": "2.1.0",
"images": {
"airflow": {
"repository": "apache/airflow",
"tag": "user-image",
"tag": tag,
"digest": digest,
},
"useDefaultImageForMigration": use_default_image,
},
},
show_only=[
Expand All @@ -265,6 +264,34 @@ 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)

@pytest.mark.parametrize(
"expected_image,tag,digest",
[
("apache/airflow:user-tag", "user-tag", None),
("apache/airflow@user-digest", None, "user-digest"),
("apache/airflow@user-digest", "user-tag", "user-digest"),
],
)
def test_should_use_correct_default_image(self, expected_image, tag, digest):
docs = render_chart(
values={
"defaultAirflowRepository": "apache/airflow",
"defaultAirflowTag": tag,
"defaultAirflowDigest": digest,
"images": {"useDefaultImageForMigration": True},
},
show_only=[
"templates/scheduler/scheduler-deployment.yaml",
"templates/workers/worker-deployment.yaml",
"templates/webserver/webserver-deployment.yaml",
"templates/triggerer/triggerer-deployment.yaml",
"templates/dag-processor/dag-processor-deployment.yaml",
],
)

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"],
Expand Down