1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 09:45:14 +01:00

Add release-name option (#735)

Signed-off-by: alisonlhart <alhart@redhat.com>
This commit is contained in:
Alison Hart
2025-06-02 04:41:47 -04:00
committed by GitHub
parent 5b4fb1a4cf
commit 3f428cda4d
5 changed files with 19 additions and 6 deletions

View File

@@ -71,6 +71,9 @@ func addInstallFlags(flags *flag.FlagSet) {
flags.String("namespace", "", heredoc.Doc(`
Namespace to install the release(s) into. If not specified, each release will be
installed in its own randomly generated namespace`))
flags.String("release-name", "", heredoc.Doc(`
Name for the release. If not specified, is set to the chart name and a random
identifier.`))
flags.String("release-label", "app.kubernetes.io/instance", heredoc.Doc(`
The label to be used as a selector when inspecting resources created by charts.
This is only used if namespace is specified`))

View File

@@ -68,6 +68,8 @@ ct install [flags]
expose sensitive data when helm-repo-extra-args contains passwords)
--release-label string The label to be used as a selector when inspecting resources created by charts.
This is only used if namespace is specified (default "app.kubernetes.io/instance")
--release-name string Name for the release. If not specified, is set to the chart name and a random
identifier.
--remote string The name of the Git remote used to identify changed charts (default "origin")
--since string The Git reference used to identify changed charts (default "HEAD")
--skip-clean-up Skip resources clean-up. Used if need to continue other flows or keep it around.

View File

@@ -63,6 +63,8 @@ ct lint-and-install [flags]
expose sensitive data when helm-repo-extra-args contains passwords)
--release-label string The label to be used as a selector when inspecting resources created by charts.
This is only used if namespace is specified (default "app.kubernetes.io/instance")
--release-name string Name for the release. If not specified, is set to the chart name and a random
identifier.
--remote string The name of the Git remote used to identify changed charts (default "origin")
--since string The Git reference used to identify changed charts (default "HEAD")
--skip-clean-up Skip resources clean-up. Used if need to continue other flows or keep it around.

View File

@@ -206,13 +206,18 @@ func (c *Chart) HasCIValuesFile(path string) bool {
}
// CreateInstallParams generates a randomized release name and namespace based on the chart path
// and optional buildID. If a buildID is specified, it will be part of the generated namespace.
func (c *Chart) CreateInstallParams(buildID string) (release string, namespace string) {
// and optional buildID. If release_name is specified, the release name is set to that string instead.
// If a buildID is specified, it will be part of the generated namespace.
func (c *Chart) CreateInstallParams(buildID string, releaseName string) (release string, namespace string) {
release = filepath.Base(c.Path())
if release == "." || release == "/" {
if releaseName != "" {
release = releaseName
} else {
yaml := c.Yaml()
release = yaml.Name
}
}
namespace = release
if buildID != "" {
namespace = fmt.Sprintf("%s-%s", namespace, buildID)
@@ -687,14 +692,14 @@ func (t *Testing) testRelease(namespace, release, releaseSelector string) error
func (t *Testing) generateInstallConfig(chart *Chart) (namespace, release, releaseSelector string, cleanup func()) {
if t.config.Namespace != "" {
namespace = t.config.Namespace
release, _ = chart.CreateInstallParams(t.config.BuildID)
release, _ = chart.CreateInstallParams(t.config.BuildID, t.config.ReleaseName)
releaseSelector = fmt.Sprintf("%s=%s", t.config.ReleaseLabel, release)
cleanup = func() {
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
t.helm.DeleteRelease(namespace, release)
}
} else {
release, namespace = chart.CreateInstallParams(t.config.BuildID)
release, namespace = chart.CreateInstallParams(t.config.BuildID, t.config.ReleaseName)
cleanup = func() {
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
t.helm.DeleteRelease(namespace, release)

View File

@@ -70,6 +70,7 @@ type Configuration struct {
SkipMissingValues bool `mapstructure:"skip-missing-values"`
SkipCleanUp bool `mapstructure:"skip-clean-up"`
Namespace string `mapstructure:"namespace"`
ReleaseName string `mapstructure:"release-name"`
ReleaseLabel string `mapstructure:"release-label"`
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
KubectlTimeout time.Duration `mapstructure:"kubectl-timeout"`