From 434b6ee1116341ec05e90a0b8c2a7865bf1f2b47 Mon Sep 17 00:00:00 2001 From: Diamon Wiggins <38189728+diamonwiggins@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:08:03 -0400 Subject: [PATCH] feat: template helm image properties (#210) * template image properties * fix broken template * update image-name for push to ttl.sh --- .github/workflows/main.yaml | 2 +- .github/workflows/publish.yaml | 2 +- chart/templates/_helpers.tpl | 28 ++++++++++++++++++++++ chart/templates/replicated-deployment.yaml | 5 ++++ chart/values.yaml.tmpl | 18 ++++++++++++-- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 90e93543..b140901d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -44,7 +44,7 @@ jobs: uses: ./.github/actions/build-push-action with: context: deploy - image-name: ttl.sh/automated-${{ github.run_id }}/replicated-sdk:24h + image-name: ttl.sh/automated-${{ github.run_id }}/replicated/replicated-sdk:24h git-tag: ${{ github.sha }} - name: Build replicated chart diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index dffc4468..ba0c751e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -126,7 +126,7 @@ jobs: - name: Run Package and Publish env: REPLICATED_TAG: v${{needs.get-tags.outputs.tag}} - REPLICATED_REGISTRY: replicated # docker.io/replicated + REPLICATED_REGISTRY: docker.io REPLICATED_CHART_NAME: replicated REPLICATED_CHART_VERSION: ${{needs.get-tags.outputs.tag}} REPLICATED_USER_STAGING: ${{secrets.REPLICATED_USER_STAGING}} diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl index 67eccd0e..1acfdf17 100644 --- a/chart/templates/_helpers.tpl +++ b/chart/templates/_helpers.tpl @@ -43,6 +43,34 @@ app.kubernetes.io/name: {{ include "replicated.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* +Image +*/}} +{{- define "replicated.image" -}} +{{- $registryName := default .Values.image.registry ((.Values.global).imageRegistry) -}} +{{- $repositoryName := .Values.image.repository -}} +{{- $separator := ":" -}} +{{- $termination := "" -}} + +{{- if not $repositoryName -}} + {{- fail "Image repository is required but not set" -}} +{{- end -}} + +{{- if .Values.image.tag -}} + {{- $termination = .Values.image.tag | toString -}} +{{- else if .Chart -}} + {{- $termination = .Chart.AppVersion | default "latest" | toString -}} +{{- else -}} + {{- $termination = "latest" -}} +{{- end -}} + +{{- if $registryName -}} + {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}} +{{- else -}} + {{- printf "%s%s%s" $repositoryName $separator $termination -}} +{{- end -}} +{{- end -}} + {{/* License Fields */}} diff --git a/chart/templates/replicated-deployment.yaml b/chart/templates/replicated-deployment.yaml index f21fbf4d..bf1cedb0 100644 --- a/chart/templates/replicated-deployment.yaml +++ b/chart/templates/replicated-deployment.yaml @@ -56,8 +56,13 @@ spec: {{- end }} containers: - name: replicated + {{- if .Values.images }} image: {{ index .Values.images "replicated-sdk" }} imagePullPolicy: IfNotPresent + {{- else }} + image: {{ include "replicated.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy | default "IfNotPresent" }} + {{- end }} {{- if .Values.containerSecurityContext.enabled }} securityContext: {{- omit .Values.containerSecurityContext "enabled" | toYaml | nindent 10 }} {{- end }} diff --git a/chart/values.yaml.tmpl b/chart/values.yaml.tmpl index 775f3ce2..127de8ff 100644 --- a/chart/values.yaml.tmpl +++ b/chart/values.yaml.tmpl @@ -2,8 +2,22 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. -images: - replicated-sdk: ${REPLICATED_REGISTRY}/replicated-sdk:${REPLICATED_TAG} +global: + imageRegistry: "" + +# Deprecated: Use .Values.image instead of .Values.images +# The following properties for the Replicated SDK image are deprecated: +# +# images: +# replicated-sdk: ${REPLICATED_REGISTRY}/replicated/replicated-sdk:${REPLICATED_TAG} + +# Replicated SDK image properties +# If .Values.images is set, it takes precedence over the following settings. +image: + registry: ${REPLICATED_REGISTRY} + repository: "replicated/replicated-sdk" + tag: "${REPLICATED_TAG}" + pullPolicy: IfNotPresent license: "" licenseFields: ""