Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/helm_lib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
type: library
name: deckhouse_lib_helm
version: 1.72.18
version: 1.72.19
description: "Helm utils template definitions for Deckhouse modules."
48 changes: 47 additions & 1 deletion charts/helm_lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
| [helm_lib_module_common_image_no_fail](#helm_lib_module_common_image_no_fail) |
| [helm_lib_module_image_digest](#helm_lib_module_image_digest) |
| [helm_lib_module_image_digest_no_fail](#helm_lib_module_image_digest_no_fail) |
| [helm_lib_internal_module_own_package](#helm_lib_internal_module_own_package) |
| [helm_lib_internal_module_package_registry_base](#helm_lib_internal_module_package_registry_base) |
| [helm_lib_internal_module_raw_name](#helm_lib_internal_module_raw_name) |
| [helm_lib_internal_module_registry_base](#helm_lib_internal_module_registry_base) |
| **Module Ingress Class** |
| [helm_lib_module_ingress_class](#helm_lib_module_ingress_class) |
| **Module Ingress Snippets** |
Expand Down Expand Up @@ -1024,7 +1028,7 @@ list:

#### Usage

`{{ include "helm_lib_module_image_no_fail" (list . "<container-name>") }} `
`{{ include "helm_lib_module_image_no_fail" (list . "<container-name>" "<module-name>(optional)") }} `

#### Arguments

Expand Down Expand Up @@ -1092,6 +1096,48 @@ list:
- Template context with .Values, .Chart, etc
- Container name


### helm_lib_internal_module_own_package

Decide whether the images resolve from the module's own package.
Returns a non-empty string when the context carries a package and no other module was named.

#### Arguments

list:
- Template context with .Values, .Chart, etc
- An explicit module name asks for another module's image, which only the global map holds


### helm_lib_internal_module_package_registry_base

Resolve the registry path of the images shipped in the module's own package.
Returns the platform registry base for an embedded package, the package path otherwise, empty when unresolvable.

#### Arguments

- Embedded packages are built into the platform image set, so their images are addressed by digest alone


### helm_lib_internal_module_raw_name

Resolve the module name passed to an image helper.
Returns the optional third argument, or the chart name when it is omitted.



### helm_lib_internal_module_registry_base

Resolve the registry path the legacy module images live in.
Returns the platform registry base, or the external module override when the module values set one.

#### Arguments

list:
- Template context with .Values, .Chart, etc
- Camelcased module name, the key the module values live under
- Path appended to the override host

## Module Ingress Class

### helm_lib_module_ingress_class
Expand Down
158 changes: 99 additions & 59 deletions charts/helm_lib/templates/_module_image.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,61 @@
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}

{{- /* New approach: use module package values */}}
{{- if and $context.Module $context.Module.Package }}
{{- $registryBase := $context.Module.Package.Registry.repository }}
{{- /* New approach: the module ships its own images in a package */}}
{{- if include "helm_lib_internal_module_own_package" . }}
{{- $registryBase := include "helm_lib_internal_module_package_registry_base" $context }}
{{- if not $registryBase }}
{{- fail "Registry base is not set" }}
{{- end }}

{{- $packageName := $context.Module.Package.Name }}
{{- if not $packageName }}
{{- if not $context.Module.Package.Registry.repository }}
{{- fail "Registry base is not set" }}
{{- end }}
{{- fail "Package name is not set" }}
{{- end }}

{{- $imageDigest := index $context.Module.Package.Digests $containerName }}
{{- $imageDigest := index ($context.Module.Package.Digests | default dict) $containerName }}
{{- if not $imageDigest }}
{{- fail (printf "Image %s has no digest" $containerName) }}
{{- end }}

{{- printf "%s/%s@%s" $registryBase $packageName $imageDigest }}
{{- printf "%s@%s" $registryBase $imageDigest }}

{{- /* Legacy fallback: use global modulesImages values */}}
{{- else }}
{{- $rawModuleName := $context.Chart.Name }}
{{- if ge (len .) 3 }}
{{- $rawModuleName = (index . 2) }} {{- /* Optional module name */ -}}
{{- end }}
{{- $moduleName := (include "helm_lib_module_camelcase_name" $rawModuleName) }}
{{- $rawModuleName := include "helm_lib_internal_module_raw_name" . }}
{{- $moduleName := include "helm_lib_module_camelcase_name" $rawModuleName }}

{{- $imageDigest := index $context.Values.global.modulesImages.digests $moduleName $containerName }}
{{- if not $imageDigest }}
{{- $error := (printf "Image %s.%s has no digest" $moduleName $containerName ) }}
{{- fail $error }}
{{- fail (printf "Image %s.%s has no digest" $moduleName $containerName) }}
{{- end }}

{{- $registryBase := $context.Values.global.modulesImages.registry.base }}
{{- /* handle external modules registry */}}
{{- if index $context.Values $moduleName }}
{{- if index $context.Values $moduleName "registry" }}
{{- if index $context.Values $moduleName "registry" "base" }}
{{- $host := trimAll "/" (index $context.Values $moduleName "registry" "base") }}
{{- $path := trimAll "/" (include "helm_lib_module_kebabcase_name" $rawModuleName) }}
{{- $registryBase = join "/" (list $host $path) }}
{{- end }}
{{- end }}
{{- end }}
{{- /* end of external module handling block */}}
{{- printf "%s@%s" $registryBase $imageDigest }}
{{- /* here the external module registry override addresses images by the kebab-cased module name */}}
{{- $registryPath := include "helm_lib_module_kebabcase_name" $rawModuleName }}
{{- printf "%s@%s" (include "helm_lib_internal_module_registry_base" (list $context $moduleName $registryPath)) $imageDigest }}
{{- end }}
{{- end }}

{{- /* Usage: {{ include "helm_lib_module_image_no_fail" (list . "<container-name>") }} */ -}}
{{- /* Usage: {{ include "helm_lib_module_image_no_fail" (list . "<container-name>" "<module-name>(optional)") }} */ -}}
{{- /* returns image name if found */ -}}
{{- define "helm_lib_module_image_no_fail" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $moduleName := (include "helm_lib_module_camelcase_name" $context) }}
{{- if ge (len .) 3 }}
{{- $moduleName = (include "helm_lib_module_camelcase_name" (index . 2)) }} {{- /* Optional module name */ -}}
{{- end }}
{{- $imageDigest := index $context.Values.global.modulesImages.digests $moduleName $containerName }}
{{- if $imageDigest }}
{{- $registryBase := $context.Values.global.modulesImages.registry.base }}
{{- if index $context.Values $moduleName }}
{{- if index $context.Values $moduleName "registry" }}
{{- if index $context.Values $moduleName "registry" "base" }}
{{- $host := trimAll "/" (index $context.Values $moduleName "registry" "base") }}
{{- $path := trimAll "/" $context.Chart.Name }}
{{- $registryBase = join "/" (list $host $path) }}
{{- end }}
{{- end }}

{{- /* New approach: the module ships its own images in a package */}}
{{- if include "helm_lib_internal_module_own_package" . }}
{{- $registryBase := include "helm_lib_internal_module_package_registry_base" $context }}
{{- $imageDigest := include "helm_lib_module_image_digest_no_fail" . }}
{{- if and $registryBase $imageDigest }}
{{- printf "%s@%s" $registryBase $imageDigest }}
{{- end }}

{{- /* Legacy fallback: use global modulesImages values */}}
{{- else }}
{{- $moduleName := include "helm_lib_module_camelcase_name" (include "helm_lib_internal_module_raw_name" .) }}
{{- $imageDigest := index $context.Values.global.modulesImages.digests $moduleName $containerName }}
{{- if $imageDigest }}
{{- /* here the external module registry override addresses images by the chart name */}}
{{- printf "%s@%s" (include "helm_lib_internal_module_registry_base" (list $context $moduleName $context.Chart.Name)) $imageDigest }}
{{- end }}
{{- printf "%s@%s" $registryBase $imageDigest }}
{{- end }}
{{- end }}

Expand Down Expand Up @@ -107,14 +91,9 @@
{{- define "helm_lib_module_image_digest" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $rawModuleName := $context.Chart.Name }}
{{- if ge (len .) 3 }}
{{- $rawModuleName = (index . 2) }} {{- /* Optional module name */ -}}
{{- end }}
{{- $moduleName := (include "helm_lib_module_camelcase_name" $rawModuleName) }}
{{- $moduleMap := index $context.Values.global.modulesImages.digests $moduleName | default dict }}
{{- $imageDigest := index $moduleMap $containerName | default "" }}
{{- $imageDigest := include "helm_lib_module_image_digest_no_fail" . }}
{{- if not $imageDigest }}
{{- $moduleName := include "helm_lib_module_camelcase_name" (include "helm_lib_internal_module_raw_name" .) }}
{{- $error := (printf "Image %s.%s has no digest" $moduleName $containerName ) }}
{{- fail $error }}
{{- end }}
Expand All @@ -126,11 +105,72 @@
{{- define "helm_lib_module_image_digest_no_fail" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $moduleName := (include "helm_lib_module_camelcase_name" $context) }}

{{- /* New approach: the module ships its own images in a package */}}
{{- if include "helm_lib_internal_module_own_package" . }}
{{- index ($context.Module.Package.Digests | default dict) $containerName | default "" }}

{{- /* Legacy fallback: use global modulesImages values */}}
{{- else }}
{{- $moduleName := include "helm_lib_module_camelcase_name" (include "helm_lib_internal_module_raw_name" .) }}
{{- $moduleMap := index $context.Values.global.modulesImages.digests $moduleName | default dict }}
{{- index $moduleMap $containerName | default "" }}
{{- end }}
{{- end }}

{{- /* Decide whether the images resolve from the module's own package. */ -}}
{{- /* Returns a non-empty string when the context carries a package and no other module was named. */ -}}
{{- define "helm_lib_internal_module_own_package" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- /* An explicit module name asks for another module's image, which only the global map holds */}}
{{- if and (lt (len .) 3) $context.Module $context.Module.Package }}
{{- true }}
{{- end }}
{{- end }}

{{- /* Resolve the registry path of the images shipped in the module's own package. */ -}}
{{- /* Returns the platform registry base for an embedded package, the package path otherwise, empty when unresolvable. */ -}}
{{- define "helm_lib_internal_module_package_registry_base" }}
{{- /* Embedded packages are built into the platform image set, so their images are addressed by digest alone */}}
{{- if .Module.Package.Embedded }}
{{- .Values.global.modulesImages.registry.base }}
{{- else }}
{{- $repository := .Module.Package.Registry.repository }}
{{- $packageName := .Module.Package.Name }}
{{- if and $repository $packageName }}
{{- printf "%s/%s" $repository $packageName }}
{{- end }}
{{- end }}
{{- end }}

{{- /* Resolve the module name passed to an image helper. */ -}}
{{- /* Returns the optional third argument, or the chart name when it is omitted. */ -}}
{{- define "helm_lib_internal_module_raw_name" }}
{{- if ge (len .) 3 }}
{{- $moduleName = (include "helm_lib_module_camelcase_name" (index . 2)) }} {{- /* Optional module name */ -}}
{{- index . 2 }} {{- /* Optional module name */ -}}
{{- else }}
{{- (index . 0).Chart.Name }}
{{- end }}
{{- $moduleMap := index $context.Values.global.modulesImages.digests $moduleName | default dict }}
{{- $imageDigest := index $moduleMap $containerName | default "" }}
{{- printf "%s" $imageDigest }}
{{- end }}

{{- /* Resolve the registry path the legacy module images live in. */ -}}
{{- /* Returns the platform registry base, or the external module override when the module values set one. */ -}}
{{- define "helm_lib_internal_module_registry_base" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $moduleName := index . 1 }} {{- /* Camelcased module name, the key the module values live under */ -}}
{{- $registryPath := index . 2 }} {{- /* Path appended to the override host */ -}}

{{- $registryBase := $context.Values.global.modulesImages.registry.base }}
{{- /* handle external modules registry */}}
{{- if index $context.Values $moduleName }}
{{- if index $context.Values $moduleName "registry" }}
{{- if index $context.Values $moduleName "registry" "base" }}
{{- $host := trimAll "/" (index $context.Values $moduleName "registry" "base") }}
{{- $path := trimAll "/" $registryPath }}
{{- $registryBase = join "/" (list $host $path) }}
{{- end }}
{{- end }}
{{- end }}
{{- /* end of external module handling block */}}
{{- $registryBase }}
{{- end }}
12 changes: 12 additions & 0 deletions tests/templates/helm_lib_module_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ commonImageNoFailNotExist: {{ include "helm_lib_module_common_image_no_fail" (li
externalModuleImage: {{ include "helm_lib_module_image" (list .Values.new "testContainer") }}
externalModuleImageWithOptionalName: {{ include "helm_lib_module_image" (list .Values.new "testContainer" "fooBar") }}
externalModuleKebabImageWithOptionalName: {{ include "helm_lib_module_image" (list .Values.new "externalContainer" "some-module") }}
---
# Embedded package: images are addressed by digest in the platform registry
embeddedPackageImage: {{ include "helm_lib_module_image" (list .Values.embedded "testContainer") }}
---
# New approach: every helper resolves the module's own images from the package
packageImageNoFail: {{ include "helm_lib_module_image_no_fail" (list .Values.new "testContainer") }}
packageImageNoFailNotExist: {{ include "helm_lib_module_image_no_fail" (list .Values.new "nonExistentContainer") }}
packageImageDigest: {{ include "helm_lib_module_image_digest" (list .Values.new "testContainer") }}
packageImageDigestNoFail: {{ include "helm_lib_module_image_digest_no_fail" (list .Values.new "testContainer") }}
packageImageDigestNoFailNotExist: {{ include "helm_lib_module_image_digest_no_fail" (list .Values.new "nonExistentContainer") }}
packageImageDigestWithOptionalName: {{ include "helm_lib_module_image_digest" (list .Values.new "testContainer" "fooBar") }}
packageCommonImage: {{ include "helm_lib_module_common_image" (list .Values.new "commonContainer") }}
Loading
Loading