diff --git a/varnish-cache/test/unit/deployment.bats b/varnish-cache/test/unit/deployment.bats index 2c1725b..852783f 100644 --- a/varnish-cache/test/unit/deployment.bats +++ b/varnish-cache/test/unit/deployment.bats @@ -101,4 +101,4 @@ rollingUpdate: tee -a /dev/stderr) [[ "${actual}" == *"'server.extraVolumeClaimTemplates' cannot be enabled"* ]] -} +} \ No newline at end of file diff --git a/varnish-enterprise/templates/_helpers.tpl b/varnish-enterprise/templates/_helpers.tpl index 0d17045..30ce524 100644 --- a/varnish-enterprise/templates/_helpers.tpl +++ b/varnish-enterprise/templates/_helpers.tpl @@ -35,12 +35,29 @@ Create chart name and version as used by the chart label. {{/* Sets up the Varnish Enterprise image and its overrides (if any) */}} -{{- define "varnish-enterprise.image" }} -{{- $base := .base | default dict }} -{{- $image := .image | default dict }} -image: "{{- if eq $image.repository "-" -}}{{ $base.repository }}{{ else }}{{ $image.repository }}{{ end }}:{{- if eq $image.tag "-" }}{{ default .Chart.AppVersion $base.tag }}{{ else }}{{ default $.Chart.AppVersion $image.tag }}{{ end }}" +{{- define "varnish-enterprise.image" -}} +{{- $base := .base | default dict -}} + {{- $image := .image | default dict -}} + {{- $repoType := .Values.global.repoType | default "" -}} + {{- $calculatedRepo := $base.repository -}} + {{- if eq $repoType "public-enterprise" -}} + {{- $calculatedRepo = "varnish/varnish-enterprise" -}} + {{- else if eq $repoType "private-enterprise" -}} + {{- $calculatedRepo = "quay.io/varnish-software/varnish-plus" -}} +{{ end }} +image: "{{- if eq $image.repository "-" -}} + {{ $calculatedRepo }} + {{- else -}} + {{ $image.repository }} + {{- end -}} + : + {{- if eq $image.tag "-" -}} + {{- default .Chart.AppVersion $base.tag -}} + {{- else -}} + {{- default $.Chart.AppVersion $image.tag -}} + {{- end -}}" imagePullPolicy: {{ if eq $image.pullPolicy "-" }}{{ $base.pullPolicy }}{{ else }}{{ $image.pullPolicy }}{{ end }} -{{- end }} +{{- end -}} {{/* Converts size string (e.g. 10Mi or 10M) to a number diff --git a/varnish-enterprise/test/unit/_helpers.bash b/varnish-enterprise/test/unit/_helpers.bash index 12771fa..7517dff 100644 --- a/varnish-enterprise/test/unit/_helpers.bash +++ b/varnish-enterprise/test/unit/_helpers.bash @@ -2,6 +2,22 @@ chart_dir() { echo "${BATS_TEST_DIRNAME}"/../.. } +helm_template_compare() { + local valuefile="${BATS_TMPDIR}/values-${BATS_TEST_NUMBER}" + echo "$1" > "$valuefile" + local templatefile="$2" + local jqpattern="$3" + local expected_result="$4" + + local result=$(helm template --namespace default\ + --values "$valuefile" \ + --show-only "$templatefile" "$(chart_dir)" | + yq -c "$jqpattern" + ) + + [ "$result" == "$expected_result" ] +} + app_version() { yq -r '.appVersion' < "${BATS_TEST_DIRNAME}"/../../Chart.yaml } diff --git a/varnish-enterprise/test/unit/deployment.bats b/varnish-enterprise/test/unit/deployment.bats index 524ef64..fba03f6 100644 --- a/varnish-enterprise/test/unit/deployment.bats +++ b/varnish-enterprise/test/unit/deployment.bats @@ -151,4 +151,4 @@ rollingUpdate: tee -a /dev/stderr) [[ "${actual}" == *"'server.extraVolumeClaimTemplates' cannot be enabled"* ]] -} +} \ No newline at end of file diff --git a/varnish-enterprise/test/unit/repotype.bats b/varnish-enterprise/test/unit/repotype.bats new file mode 100644 index 0000000..41ac59d --- /dev/null +++ b/varnish-enterprise/test/unit/repotype.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +load _helpers + +@test "repoType: default (no global.repoType set)" { + helm_template_compare \ + "global: {}" \ + "templates/deployment.yaml" \ + '.spec.template.spec.containers[0].image' \ + "\"quay.io/varnish-software/varnish-plus:$(app_version)\"" +} + +@test "repoType: public-enterprise" { + helm_template_compare \ + "global: {repoType: public-enterprise}" \ + "templates/deployment.yaml" \ + '.spec.template.spec.containers[0].image' \ + "\"varnish/varnish-enterprise:$(app_version)\"" +} + +@test "repoType: private-enterprise" { + helm_template_compare \ + "global: {repoType: private-enterprise}" \ + "templates/deployment.yaml" \ + '.spec.template.spec.containers[0].image' \ + "\"quay.io/varnish-software/varnish-plus:$(app_version)\"" +} \ No newline at end of file diff --git a/varnish-enterprise/values.yaml b/varnish-enterprise/values.yaml index 23223f5..224f126 100644 --- a/varnish-enterprise/values.yaml +++ b/varnish-enterprise/values.yaml @@ -71,6 +71,11 @@ global: # on a separate cluster. clusterDomain: "cluster.local" + # Defines which repository to use by default + # Options are public-enterprise or private-enterprise + # Check server.image.repository for more information + repoType: "private-enterprise" + serviceAccount: # Specifies whether a service account should be created create: true @@ -543,8 +548,11 @@ server: # Sets the image and tag to use to deploy Varnish Enterprise. # If tag is blank, appVersion is used. + # If repository is "-", check global.repoType + # - private-enterprise: repository will be "quay.io/varnish-software/varnish-plus" + # - public-enterprise: repository will be "varnish/varnish-enterprise" image: - repository: "quay.io/varnish-software/varnish-plus" + repository: "-" pullPolicy: IfNotPresent tag: ""