diff --git a/ct/cmd/install.go b/ct/cmd/install.go index 734ea07..98180e0 100644 --- a/ct/cmd/install.go +++ b/ct/cmd/install.go @@ -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`)) diff --git a/doc/ct_install.md b/doc/ct_install.md index fe1e72d..27b5697 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -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. diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index 924f02b..0b341b9 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -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. diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index bf58b27..54fb192 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -206,12 +206,17 @@ 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 == "/" { - yaml := c.Yaml() - release = yaml.Name + if releaseName != "" { + release = releaseName + } else { + yaml := c.Yaml() + release = yaml.Name + } } namespace = release if 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) diff --git a/pkg/config/config.go b/pkg/config/config.go index 6afa353..981b276 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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"`