Files
trainer/charts/kubeflow-trainer/templates/_helpers.tpl
T
Tariq HasanandGitHub 1f57df4484 ci(boilerplate): enhance copyright boilerplate enforcement (#3665)
* ci(boilerplate): enforce copyright headers on YAML files

Signed-off-by: tariq-hasan <[email protected]>

* ci(boilerplate): enforce year-less header for new files

Signed-off-by: tariq-hasan <[email protected]>

---------

Signed-off-by: tariq-hasan <[email protected]>
2026-07-03 13:39:54 +00:00

129 lines
3.9 KiB
Smarty

{{- /*
Copyright 2025 The Kubeflow Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/ -}}
{{/*
Expand the name of the chart.
*/}}
{{- define "trainer.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "trainer.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "trainer.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "trainer.labels" -}}
helm.sh/chart: {{ include "trainer.chart" . }}
{{ include "trainer.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "trainer.selectorLabels" -}}
app.kubernetes.io/name: {{ include "trainer.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Resolve the effective image tag, using a provided tag if present or
falling back to the default image tag derived from the chart version.
Usage: include "trainer.resolveImageTag" (dict "tag" .Values.image.tag "context" .)
*/}}
{{- define "trainer.resolveImageTag" -}}
{{- if .tag }}
{{- .tag -}}
{{- else -}}
{{- include "trainer.defaultImageTag" .context -}}
{{- end -}}
{{- end }}
{{- define "trainer.image" -}}
{{- $imageRegistry := .Values.image.registry | default "docker.io" }}
{{- $imageRepository := .Values.image.repository }}
{{- $imageTag := include "trainer.resolveImageTag" (dict "tag" .Values.image.tag "context" .) -}}
{{- if eq $imageRegistry "docker.io" }}
{{- printf "%s:%s" $imageRepository $imageTag }}
{{- else }}
{{- printf "%s/%s:%s" $imageRegistry $imageRepository $imageTag }}
{{- end }}
{{- end }}
{{/*
Generate the default image tag for runtimes based on chart version
*/}}
{{- define "trainer.defaultImageTag" -}}
{{- if hasPrefix "0.0.0-" .Chart.Version -}}
{{- trimPrefix "0.0.0-" .Chart.Version -}}
{{- else -}}
{{- printf "v%s" .Chart.Version -}}
{{- end -}}
{{- end }}
{{/*
Generate runtime image with registry, repository, and tag from values
Usage: include "trainer.runtimeImage" (list .Values.runtimes.deepspeedDistributed.image .)
*/}}
{{- define "trainer.runtimeImage" -}}
{{- $imageConfig := index . 0 }}
{{- $root := index . 1 }}
{{- $registry := $imageConfig.registry | default "ghcr.io" }}
{{- $repository := $imageConfig.repository }}
{{- $tag := include "trainer.resolveImageTag" (dict "tag" ($imageConfig.tag) "context" $root) -}}
{{- if eq $registry "docker.io" }}
{{- printf "%s:%s" $repository $tag }}
{{- else }}
{{- printf "%s/%s:%s" $registry $repository $tag }}
{{- end }}
{{- end }}
{{/*
Return the version of the trainer.
If the version is 0.0.0, we assume it is a development version.
*/}}
{{- define "trainer.version" -}}
{{- if hasPrefix "0.0.0-" .Chart.Version -}}
dev
{{- else -}}
{{ printf "v%s" .Chart.Version }}
{{- end -}}
{{- end }}