Skip to content

Commit 3f428cd

Browse files
authored
Add release-name option (#735)
Signed-off-by: alisonlhart <alhart@redhat.com>
1 parent 5b4fb1a commit 3f428cd

5 files changed

Lines changed: 19 additions & 6 deletions

File tree

ct/cmd/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func addInstallFlags(flags *flag.FlagSet) {
7171
flags.String("namespace", "", heredoc.Doc(`
7272
Namespace to install the release(s) into. If not specified, each release will be
7373
installed in its own randomly generated namespace`))
74+
flags.String("release-name", "", heredoc.Doc(`
75+
Name for the release. If not specified, is set to the chart name and a random
76+
identifier.`))
7477
flags.String("release-label", "app.kubernetes.io/instance", heredoc.Doc(`
7578
The label to be used as a selector when inspecting resources created by charts.
7679
This is only used if namespace is specified`))

doc/ct_install.md

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

doc/ct_lint-and-install.md

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

pkg/chart/chart.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,17 @@ func (c *Chart) HasCIValuesFile(path string) bool {
206206
}
207207

208208
// CreateInstallParams generates a randomized release name and namespace based on the chart path
209-
// and optional buildID. If a buildID is specified, it will be part of the generated namespace.
210-
func (c *Chart) CreateInstallParams(buildID string) (release string, namespace string) {
209+
// and optional buildID. If release_name is specified, the release name is set to that string instead.
210+
// If a buildID is specified, it will be part of the generated namespace.
211+
func (c *Chart) CreateInstallParams(buildID string, releaseName string) (release string, namespace string) {
211212
release = filepath.Base(c.Path())
212213
if release == "." || release == "/" {
213-
yaml := c.Yaml()
214-
release = yaml.Name
214+
if releaseName != "" {
215+
release = releaseName
216+
} else {
217+
yaml := c.Yaml()
218+
release = yaml.Name
219+
}
215220
}
216221
namespace = release
217222
if buildID != "" {
@@ -687,14 +692,14 @@ func (t *Testing) testRelease(namespace, release, releaseSelector string) error
687692
func (t *Testing) generateInstallConfig(chart *Chart) (namespace, release, releaseSelector string, cleanup func()) {
688693
if t.config.Namespace != "" {
689694
namespace = t.config.Namespace
690-
release, _ = chart.CreateInstallParams(t.config.BuildID)
695+
release, _ = chart.CreateInstallParams(t.config.BuildID, t.config.ReleaseName)
691696
releaseSelector = fmt.Sprintf("%s=%s", t.config.ReleaseLabel, release)
692697
cleanup = func() {
693698
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
694699
t.helm.DeleteRelease(namespace, release)
695700
}
696701
} else {
697-
release, namespace = chart.CreateInstallParams(t.config.BuildID)
702+
release, namespace = chart.CreateInstallParams(t.config.BuildID, t.config.ReleaseName)
698703
cleanup = func() {
699704
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
700705
t.helm.DeleteRelease(namespace, release)

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Configuration struct {
7070
SkipMissingValues bool `mapstructure:"skip-missing-values"`
7171
SkipCleanUp bool `mapstructure:"skip-clean-up"`
7272
Namespace string `mapstructure:"namespace"`
73+
ReleaseName string `mapstructure:"release-name"`
7374
ReleaseLabel string `mapstructure:"release-label"`
7475
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
7576
KubectlTimeout time.Duration `mapstructure:"kubectl-timeout"`

0 commit comments

Comments
 (0)