Skip to content

Commit 39701a5

Browse files
committed
fix: make it possible to override chart repository in a particular pipeline
this includes override with the empty string to get a default value
1 parent 382e51a commit 39701a5

3 files changed

Lines changed: 57 additions & 28 deletions

File tree

pkg/cmd/helm/release/release.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"strings"
1010

1111
"github.com/jenkins-x-plugins/jx-gitops/pkg/chart"
12-
"github.com/jenkins-x/jx-helpers/v3/pkg/yamls"
13-
1412
"github.com/jenkins-x-plugins/jx-gitops/pkg/ghpages"
1513
"github.com/jenkins-x-plugins/jx-gitops/pkg/plugins"
1614
"github.com/jenkins-x-plugins/jx-gitops/pkg/rootcmd"
@@ -29,6 +27,7 @@ import (
2927
"github.com/jenkins-x/jx-helpers/v3/pkg/scmhelpers"
3028
"github.com/jenkins-x/jx-helpers/v3/pkg/stringhelpers"
3129
"github.com/jenkins-x/jx-helpers/v3/pkg/termcolor"
30+
"github.com/jenkins-x/jx-helpers/v3/pkg/yamls"
3231
"github.com/jenkins-x/jx-logging/v3/pkg/log"
3332
"github.com/pkg/errors"
3433
"github.com/spf13/cobra"
@@ -102,6 +101,7 @@ type Options struct {
102101
CommandRunner cmdrunner.CommandRunner
103102
Requirements *jxcore.RequirementsConfig
104103
ReleasedCharts int
104+
Cmd *cobra.Command
105105
}
106106

107107
// NewCmdHelmRelease creates a command object for the command
@@ -113,7 +113,8 @@ func NewCmdHelmRelease() (*cobra.Command, *Options) {
113113
Short: "Performs a release of all the charts in the charts folder",
114114
Long: cmdLong,
115115
Example: fmt.Sprintf(cmdExample, rootcmd.BinaryName),
116-
Run: func(_ *cobra.Command, _ []string) {
116+
Run: func(cmd *cobra.Command, _ []string) {
117+
o.Cmd = cmd
117118
err := o.Run()
118119
helper.CheckErr(err)
119120
},
@@ -291,10 +292,14 @@ func (o *Options) Run() error {
291292

292293
// find the repository URL
293294
if repoURL == "" {
294-
repoURL, err = variablefinders.FindRepositoryURL(o.Requirements, o.ContainerRegistryOrg, name)
295-
if err != nil {
296-
return errors.Wrapf(err, "failed to find chart repository URL")
297-
}
295+
repoURL = variablefinders.FindRepositoryURL(
296+
o.Requirements,
297+
o.ContainerRegistryOrg,
298+
name,
299+
o.ChartOCI,
300+
o.ChartPages,
301+
o.flagChanged("repo-url"),
302+
)
298303
}
299304
if o.ChartPages {
300305
err = o.ChartPageRegistry(repoURL, chartDir, name)
@@ -701,3 +706,14 @@ func (o *Options) findChartRepositoryUserPassword() (string, string, error) {
701706
}
702707
return userName, password, err
703708
}
709+
710+
// FlagChanged returns true if the given flag was supplied on the command line
711+
func (o *Options) flagChanged(name string) bool {
712+
if o.Cmd != nil {
713+
f := o.Cmd.Flag(name)
714+
if f != nil {
715+
return f.Changed
716+
}
717+
}
718+
return false
719+
}

pkg/cmd/variables/variables.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,15 @@ func (o *Options) Validate() error {
190190
return errors.Wrapf(err, "failed to find container registry org")
191191
}
192192

193-
o.RepositoryURL, err = variablefinders.FindRepositoryURL(o.Requirements, registryOrg, o.Repository)
194-
if err != nil {
195-
return errors.Wrapf(err, "failed to find chart repository URL")
196-
}
193+
chartKind := o.Requirements.Cluster.ChartKind
194+
o.RepositoryURL = variablefinders.FindRepositoryURL(
195+
o.Requirements,
196+
registryOrg,
197+
o.Repository,
198+
chartKind == jxcore.ChartRepositoryTypeOCI,
199+
chartKind == jxcore.ChartRepositoryTypePages,
200+
false,
201+
)
197202
}
198203

199204
if o.Options.Branch == "" || o.Options.Branch == "HEAD" {
@@ -270,7 +275,15 @@ func (o *Options) Validate() error {
270275
if err != nil {
271276
return "", errors.Wrapf(err, "failed to find container registry org")
272277
}
273-
return variablefinders.FindRepositoryURL(o.Requirements, registryOrg, o.Options.Repository)
278+
chartKind := o.Requirements.Cluster.ChartKind
279+
return variablefinders.FindRepositoryURL(
280+
o.Requirements,
281+
registryOrg,
282+
o.Options.Repository,
283+
chartKind == jxcore.ChartRepositoryTypeOCI,
284+
chartKind == jxcore.ChartRepositoryTypePages,
285+
false,
286+
), nil
274287
},
275288
},
276289
{

pkg/variablefinders/repo_url.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import (
88
)
99

1010
// FindRepositoryURL finds the chart repository URL via environment variables or the dev Environment CRD
11-
func FindRepositoryURL(requirements *jxcore.RequirementsConfig, registryOrg, appName string) (string, error) {
12-
answer := ""
13-
if requirements != nil {
14-
answer = requirements.Cluster.ChartRepository
15-
}
16-
if answer == "" {
17-
answer = os.Getenv("JX_CHART_REPOSITORY")
18-
}
19-
if answer == "" {
20-
registry := requirements.Cluster.Registry
21-
if requirements.Cluster.ChartKind == jxcore.ChartRepositoryTypeOCI && registryOrg != "" && appName != "" && registry != "" {
22-
return stringhelpers.UrlJoin(registry, registryOrg, appName), nil
11+
func FindRepositoryURL(requirements *jxcore.RequirementsConfig, registryOrg, appName string, oci, pages, explicitlyEmpty bool) string {
12+
if !explicitlyEmpty {
13+
answer, exists := os.LookupEnv("JX_CHART_REPOSITORY")
14+
if !exists && requirements != nil {
15+
answer = requirements.Cluster.ChartRepository
2316
}
24-
if requirements.Cluster.ChartKind != jxcore.ChartRepositoryTypeOCI && requirements.Cluster.ChartKind != jxcore.ChartRepositoryTypePages {
25-
// assume default chart museum
26-
answer = "http://jenkins-x-chartmuseum:8080"
17+
if answer != "" {
18+
return answer
2719
}
2820
}
29-
return answer, nil
21+
registry := requirements.Cluster.Registry
22+
if oci && registryOrg != "" && appName != "" && registry != "" {
23+
return stringhelpers.UrlJoin(registry, registryOrg, appName)
24+
}
25+
if !oci && !pages {
26+
// assume default chart museum
27+
return "http://jenkins-x-chartmuseum:8080"
28+
}
29+
return ""
3030
}

0 commit comments

Comments
 (0)