Skip to content

Commit

Permalink
salt,charts: Allow defining registry separately
Browse files Browse the repository at this point in the history
Some charts now expect the image registry to be defined separately from
the repository, and enforces that these values are joined with a slash.
This causes issues with our macro "build_image_name", which builds the
whole path.
We add an option to this macro to omit the registry endpoint, and make
this value available to rendered charts using the charts/render.py
script header.
  • Loading branch information
gdemonet committed Mar 8, 2023
1 parent 53f3451 commit d1efe37
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 3 deletions.
19 changes: 19 additions & 0 deletions charts/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"{{ build_image_name("<imgname>", False) }}"
- "__full_image__(<imgname>)", to replace with
"{{ build_image_name("<imgname>") }}"
- "__image_no_reg__(<imgname>)", to replace with
"{{ build_image_name("<imgname>", False, False) }}"
- "__full_image_no_reg__(<imgname>)", to replace with
"{{ build_image_name("<imgname>", True, False) }}"
"""

import argparse
Expand Down Expand Up @@ -51,6 +55,7 @@
START_BLOCK = """
#!jinja | metalk8s_kubernetes
{{%- from "metalk8s/map.jinja" import repo with context %}}
{{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}}
{csc_defaults}
{configlines}
Expand Down Expand Up @@ -201,6 +206,20 @@ def replace_magic_strings(rendered_yaml):
result,
)

# Handle __image_no_reg__
result = re.sub(
r"__image_no_reg__\((?P<imgname>[\w\-]+)\)",
r'{% endraw -%}{{ build_image_name("\g<imgname>", False, False) }}{%- raw %}',
result,
)

# Handle __full_image_no_reg__ (include version tag in the rendered name)
result = re.sub(
r"__full_image_no_reg__\((?P<imgname>[\w\-]+)\)",
r'{% endraw -%}{{ build_image_name("\g<imgname>", True, False) }}{%- raw %}',
result,
)

return result


Expand Down
1 change: 1 addition & 0 deletions salt/metalk8s/addons/dex/deployed/chart.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
{%- set dex_defaults = salt.slsutil.renderer('salt://metalk8s/addons/dex/config/dex.yaml.j2', saltenv=saltenv) %}
{%- set dex = salt.metalk8s_service_configuration.get_service_conf('metalk8s-auth', 'metalk8s-dex-config', dex_defaults) %}
Expand Down
1 change: 1 addition & 0 deletions salt/metalk8s/addons/logging/fluent-bit/deployed/chart.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
{%- set fluent_bit_defaults = salt.slsutil.renderer('salt://metalk8s/addons/logging/fluent-bit/config/fluent-bit.yaml', saltenv=saltenv) %}
{%- set fluent_bit = salt.metalk8s_service_configuration.get_service_conf('metalk8s-logging', 'metalk8s-fluent-bit-config', fluent_bit_defaults) %}
Expand Down
1 change: 1 addition & 0 deletions salt/metalk8s/addons/logging/loki/deployed/chart.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
{%- set loki_defaults = salt.slsutil.renderer('salt://metalk8s/addons/logging/loki/config/loki.yaml', saltenv=saltenv) %}
{%- set loki = salt.metalk8s_service_configuration.get_service_conf('metalk8s-logging', 'metalk8s-loki-config', loki_defaults) %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
Expand Down
1 change: 1 addition & 0 deletions salt/metalk8s/addons/nginx-ingress/deployed/chart.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
Expand Down
1 change: 1 addition & 0 deletions salt/metalk8s/addons/prometheus-adapter/deployed/chart.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!jinja | metalk8s_kubernetes

{%- from "metalk8s/map.jinja" import repo with context %}
{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}
Expand Down
7 changes: 4 additions & 3 deletions salt/metalk8s/repo/macro.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
{%- set repo_prefix = repo.registry_endpoint %}
{%- set metalk8s_repository = repo_prefix ~ '/' ~ saltenv %}
{%- macro build_image_name(name='', include_tag=True) -%}
{%- macro build_image_name(name='', include_tag=True, include_registry=True) -%}
{%- set prefix = metalk8s_repository if include_registry else saltenv %}
{%- if include_tag -%}
{%- set image_info = repo.images.get(name, {}) -%}
{%- if image_info -%}
{%- set image_tag = name ~ ':' ~ image_info.version -%}
{{ metalk8s_repository }}/{{ image_tag }}
{{ prefix }}/{{ image_tag }}
{%- else -%}
{{ raise('Missing version information about image "' ~ name ~ '"') }}
{%- endif -%}
{%- else -%}
{{ metalk8s_repository }}/{{ name }}
{{ prefix }}/{{ name }}
{%- endif -%}
{%- endmacro -%}

0 comments on commit d1efe37

Please sign in to comment.