Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 varnish-cache/test/unit/deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ rollingUpdate:
tee -a /dev/stderr)

[[ "${actual}" == *"'server.extraVolumeClaimTemplates' cannot be enabled"* ]]
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep trailing newlines.

}
29 changes: 24 additions & 5 deletions varnish-enterprise/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,31 @@ 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 }}
Comment on lines +38 to +47

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, you're introducing a newline between the image and the tag.

The reason it was all written on one line was probably to avoid introducing newlines.
It wasn't pretty and I prefer to not do it that way.
If you want to keep it on several lines, please indent the code between {{ define }} and {{ end }} to make it more readable.

image: "{{- if eq $image.repository "-" -}}
{{ $calculatedRepo }}
{{- else -}}
{{ $image.repository }} y
{{- 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
Expand Down
16 changes: 16 additions & 0 deletions varnish-enterprise/test/unit/_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion varnish-enterprise/test/unit/deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ rollingUpdate:
tee -a /dev/stderr)

[[ "${actual}" == *"'server.extraVolumeClaimTemplates' cannot be enabled"* ]]
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep trailing newlines.

27 changes: 27 additions & 0 deletions varnish-enterprise/test/unit/repotype.bats

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these tests to the unit_common test file and change back to the original test format and let's agree on a test style before we change to something like this.

Since the above code broke the varnishncsa image, and not the varnish image please test for that too.

Original file line number Diff line number Diff line change
@@ -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)\""
}
10 changes: 9 additions & 1 deletion varnish-enterprise/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ""

Expand Down