Skip to content
Draft
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
17 changes: 15 additions & 2 deletions test/helpers/components/operator/installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func getHelmOptions(releaseTag, platform string, withCSI bool) ([]helm.Option, e
helm.WithArgs("--set", fmt.Sprintf("csidriver.enabled=%t", withCSI)),
helm.WithArgs("--set", "manifests=true"),
helm.WithArgs("--set", "debugLogs=true"),
helm.WithArgs("--set", "webhook.highAvailability=false"),
}

// Install from registry
Expand All @@ -154,8 +155,12 @@ func getHelmOptions(releaseTag, platform string, withCSI bool) ([]helm.Option, e
}

// Install nightly
if chartURI := os.Getenv("HELM_CHART"); strings.HasSuffix(chartURI, ":0.0.0-nightly-chart") {
return append(opts, helm.WithArgs(chartURI)), nil
if chartURI := os.Getenv("HELM_CHART"); isNightlyChart(chartURI) {
return append(
opts,
helm.WithArgs("--set", "imagePullPolicy=IfNotPresent"),
helm.WithArgs(chartURI),
), nil
}

// Install from filesystem
Expand All @@ -175,6 +180,14 @@ func getHelmOptions(releaseTag, platform string, withCSI bool) ([]helm.Option, e
), nil
}

func isNightlyChart(chartURI string) bool {
_, version, ok := strings.Cut(strings.TrimPrefix(chartURI, "oci://"), ":")
if !ok {
return false
}
return strings.HasPrefix(version, "0.0.0-nightly-")
}

// Cache image ref on first invocation to allow switching branches.
var imageRef string

Expand Down
26 changes: 26 additions & 0 deletions test/helpers/components/operator/installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestGetHelmOptions(t *testing.T) {
"--set", "csidriver.enabled=true",
"--set", "manifests=true",
"--set", "debugLogs=true",
"--set", "webhook.highAvailability=false",
helmRegistryURL,
},
}, opts)
Expand All @@ -58,6 +59,8 @@ func TestGetHelmOptions(t *testing.T) {
"--set", "csidriver.enabled=true",
"--set", "manifests=true",
"--set", "debugLogs=true",
"--set", "webhook.highAvailability=false",
"--set", "imagePullPolicy=IfNotPresent",
"oci://registry:0.0.0-nightly-chart",
},
}, opts)
Expand All @@ -82,6 +85,7 @@ func TestGetHelmOptions(t *testing.T) {
"--set", "csidriver.enabled=false",
"--set", "manifests=true",
"--set", "debugLogs=true",
"--set", "webhook.highAvailability=false",
"--set", "image=repo:tag",
filepath.Join(project.RootDir(), "config", "helm", "chart", "default"),
},
Expand All @@ -103,13 +107,16 @@ func TestGetHelmOptions(t *testing.T) {
"--set", "csidriver.enabled=false",
"--set", "manifests=true",
"--set", "debugLogs=true",
"--set", "webhook.highAvailability=false",
"--set", "image=repo:tag",
filepath.Join(project.RootDir(), "config", "helm", "chart", "default"),
},
}, opts)
})

t.Run("no image found", func(t *testing.T) {
// clear cached image to ensure make is called
imageRef = ""
tempDir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(tempDir, "make"), []byte("#!/bin/sh\necho make[1] Entering directory"), os.ModePerm)) //nolint:gosec
t.Setenv("PATH", tempDir+":"+os.Getenv("PATH"))
Expand All @@ -118,3 +125,22 @@ func TestGetHelmOptions(t *testing.T) {
require.Error(t, err)
})
}

func Test_isNightlyChart(t *testing.T) {
tests := []struct {
chart string
expectNightly bool
}{
{"", false},
{"mychart:1.2.3", false},
{"oci://mychart:1.2.3", false},
{"oci://0.0.0-nightly-1", false},
{"mychart:nightly-1", false},
{"mychart:0.0.0-nightly-1", true},
{"oci://mychart:0.0.0-nightly-1", true},
}

for _, test := range tests {
assert.Equal(t, test.expectNightly, isNightlyChart(test.chart), test.chart)
}
}
Loading