Skip to content

Commit

Permalink
fix(helm): support numeric type image tags (#7579)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouly committed Apr 26, 2022
1 parent 22e0267 commit 4516740
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If release name contains chart name it will be used as a full name.
{{- $ := index . 0 }}

{{- with index . 1 }}
{{- $tag := .tag | default $.Chart.Version }}
{{- $tag := .tag | default $.Chart.Version | toYaml }}
{{- printf "%s:%s" .repository $tag }}
{{- end }}
{{- end }}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions helm/dagster/schema/schema/charts/utils/kubernetes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel, Extra # pylint: disable=no-name-in-module

Expand Down Expand Up @@ -35,7 +35,7 @@ class PullPolicy(str, Enum):

class Image(BaseModelWithNullableRequiredFields):
repository: str
tag: Optional[str]
tag: Optional[Union[str, int]]
pullPolicy: PullPolicy

@property
Expand Down
52 changes: 51 additions & 1 deletion helm/dagster/schema/schema_tests/test_user_deployments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import subprocess
from typing import List
from typing import List, Union

import pytest
from dagster_k8s.models import k8s_model_from_dict, k8s_snake_case_dict
Expand Down Expand Up @@ -492,6 +492,29 @@ def test_user_deployment_default_image_tag_is_chart_version(
assert image_tag == chart_version


@pytest.mark.parametrize("tag", [5176135, "abc1234"])
def test_user_deployment_tag_can_be_numeric(template: HelmTemplate, tag: Union[str, int]):
deployment = create_simple_user_deployment("foo")
deployment.image.tag = tag

helm_values = DagsterHelmValues.construct(
dagsterUserDeployments=UserDeployments(
enabled=True,
enableSubchart=True,
deployments=[deployment],
)
)

user_deployments = template.render(helm_values)

assert len(user_deployments) == 1

image = user_deployments[0].spec.template.spec.containers[0].image
_, image_tag = image.split(":")

assert image_tag == str(tag)


def _assert_no_container_context(user_deployment):
# No container context set by default
env_names = [env.name for env in user_deployment.spec.template.spec.containers[0].env]
Expand Down Expand Up @@ -793,3 +816,30 @@ def test_subchart_default_postgres_password(subchart_template: HelmTemplate):

assert container.env[1].name == "DAGSTER_PG_PASSWORD"
assert container.env[1].value_from.secret_key_ref.name == "dagster-postgresql-secret"


@pytest.mark.parametrize("tag", [5176135, "abc1234"])
def test_subchart_tag_can_be_numeric(subchart_template: HelmTemplate, tag: Union[str, int]):
deployment_values = DagsterUserDeploymentsHelmValues.construct(
deployments=[
UserDeployment.construct(
name="foo",
image=kubernetes.Image.construct(
repository="foo",
tag=tag,
pullPolicy="Always",
),
dagsterApiGrpcArgs=[],
port=0,
)
]
)

deployment_templates = subchart_template.render(deployment_values)

assert len(deployment_templates) == 1

image = deployment_templates[0].spec.template.spec.containers[0].image
_, image_tag = image.split(":")

assert image_tag == str(tag)
2 changes: 1 addition & 1 deletion helm/dagster/templates/helpers/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If release name contains chart name it will be used as a full name.
{{- $ := index . 0 }}

{{- with index . 1 }}
{{- $tag := .tag | default $.Chart.Version }}
{{- $tag := .tag | default $.Chart.Version | toYaml }}
{{- printf "%s:%s" .repository $tag }}
{{- end }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions helm/dagster/values.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4516740

Please sign in to comment.