Skip to content

Commit 414098e

Browse files
authored
custom helm chart url (#611)
1 parent bfc2482 commit 414098e

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

cmd/command/cd/cd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func Commands(clients client.Plural, helmConfiguration *action.Configuration) []
7878
cli.StringFlag{Name: "url", Usage: "console url", Required: true},
7979
cli.StringFlag{Name: "token", Usage: "deployment token", Required: true},
8080
cli.StringFlag{Name: "values", Usage: "values file to use for the deployment agent helm chart", Required: false},
81+
cli.StringFlag{Name: "chart-loc", Usage: "URL or filepath of helm chart tar file. Use if not wanting to install helm chart from default plural repository.", Required: false},
8182
cli.BoolFlag{Name: "force", Usage: "ignore checking if the current cluster is correct"},
8283
},
8384
},
@@ -136,7 +137,7 @@ func (p *Plural) handleInstallDeploymentsOperator(c *cli.Context) error {
136137
// we don't care if this fails to init as this command can be auth-less
137138
_ = p.InitConsoleClient(consoleToken, consoleURL)
138139

139-
return p.DoInstallOperator(c.String("url"), c.String("token"), c.String("values"))
140+
return p.DoInstallOperator(c.String("url"), c.String("token"), c.String("values"), c.String("chart-loc"))
140141
}
141142

142143
func (p *Plural) handleUninstallOperator(_ *cli.Context) error {

cmd/command/cd/cd_clusters.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (p *Plural) cdClusterCommands() []cli.Command {
9898
cli.StringFlag{Name: "name", Usage: "The name you'll give the cluster", Required: true},
9999
cli.StringFlag{Name: "handle", Usage: "optional handle for the cluster"},
100100
cli.StringFlag{Name: "values", Usage: "values file to use for the deployment agent helm chart", Required: false},
101+
cli.StringFlag{Name: "chart-loc", Usage: "URL or filepath of helm chart tar file. Use if not wanting to install helm chart from default plural repository.", Required: false},
101102
cli.StringFlag{Name: "project", Usage: "the project this cluster will belong to", Required: false},
102103
cli.StringSliceFlag{
103104
Name: "tag",
@@ -110,6 +111,7 @@ func (p *Plural) cdClusterCommands() []cli.Command {
110111
Action: common.LatestVersion(p.handleClusterReinstall),
111112
Flags: []cli.Flag{
112113
cli.StringFlag{Name: "values", Usage: "values file to use for the deployment agent helm chart", Required: false},
114+
cli.StringFlag{Name: "chart-loc", Usage: "URL or filepath of helm chart tar file. Use if not wanting to install helm chart from default plural repository.", Required: false},
113115
},
114116
Usage: "reinstalls the deployment operator into a cluster",
115117
ArgsUsage: "@{cluster-handle}",
@@ -412,7 +414,7 @@ func (p *Plural) handleClusterReinstall(c *cli.Context) error {
412414
}
413415

414416
id, name := common.GetIdAndName(handle)
415-
return p.ReinstallOperator(c, id, name)
417+
return p.ReinstallOperator(c, id, name, c.String("chart-loc"))
416418
}
417419

418420
func (p *Plural) handleClusterBootstrap(c *cli.Context) error {
@@ -458,7 +460,7 @@ func (p *Plural) handleClusterBootstrap(c *cli.Context) error {
458460
if attrs.Handle != nil {
459461
handle = attrs.Handle
460462
}
461-
return p.ReinstallOperator(c, nil, handle)
463+
return p.ReinstallOperator(c, nil, handle, c.String("chart-loc"))
462464
}
463465

464466
return err
@@ -475,5 +477,5 @@ func (p *Plural) handleClusterBootstrap(c *cli.Context) error {
475477

476478
deployToken := *existing.CreateCluster.DeployToken
477479
utils.Highlight("installing agent on %s with url %s\n", c.String("name"), p.ConsoleClient.Url())
478-
return p.DoInstallOperator(url, deployToken, c.String("values"))
480+
return p.DoInstallOperator(url, deployToken, c.String("values"), c.String("chart-loc"))
479481
}

cmd/command/edge/bootstrap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (p *Plural) handleEdgeBootstrap(c *cli.Context) error {
5656
if agentUrl, err := p.ConsoleClient.AgentUrl(cluster.CreateCluster.ID); err == nil {
5757
url = agentUrl
5858
}
59-
return p.DoInstallOperator(url, *cluster.CreateCluster.DeployToken, "")
59+
return p.DoInstallOperator(url, *cluster.CreateCluster.DeployToken, "", c.String("chart-loc"))
6060
}
6161

6262
func (p *Plural) getClusterAttributes(registration *gqlclient.ClusterRegistrationFragment) (*gqlclient.ClusterAttributes, error) {

cmd/command/edge/edge.go

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ func Commands(clients client.Plural, helmConfiguration *action.Configuration) []
121121
Usage: "the unique id of the edge device on which this cluster runs",
122122
Required: true,
123123
},
124+
cli.StringFlag{
125+
Name: "chart-loc",
126+
Usage: "URL or filepath of helm chart tar file. Use if not wanting to install helm chart from default plural repository.",
127+
Required: false,
128+
},
124129
},
125130
},
126131
}

pkg/client/plural.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (p *Plural) HandleInit(c *cli.Context) error {
196196
return nil
197197
}
198198

199-
func (p *Plural) DoInstallOperator(url, token, values string) error {
199+
func (p *Plural) DoInstallOperator(url, token, values, chart_loc string) error {
200200
err := p.InitKube()
201201
if err != nil {
202202
return err
@@ -237,14 +237,14 @@ func (p *Plural) DoInstallOperator(url, token, values string) error {
237237
}
238238
}
239239
vals = algorithms.Merge(vals, globalVals)
240-
err = console.InstallAgent(url, token, console.OperatorNamespace, version, vals)
240+
err = console.InstallAgent(url, token, console.OperatorNamespace, version, chart_loc, vals)
241241
if err == nil {
242242
utils.Success("deployment operator installed successfully\n")
243243
}
244244
return err
245245
}
246246

247-
func (p *Plural) ReinstallOperator(c *cli.Context, id, handle *string) error {
247+
func (p *Plural) ReinstallOperator(c *cli.Context, id, handle *string, chart_loc string) error {
248248
deployToken, err := p.ConsoleClient.GetDeployToken(id, handle)
249249
if err != nil {
250250
return err
@@ -257,5 +257,5 @@ func (p *Plural) ReinstallOperator(c *cli.Context, id, handle *string) error {
257257
}
258258
}
259259

260-
return p.DoInstallOperator(url, deployToken, c.String("values"))
260+
return p.DoInstallOperator(url, deployToken, c.String("values"), chart_loc)
261261
}

pkg/console/agent.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,34 @@ func IsAlreadyAgentInstalled(k8sClient *kubernetes.Clientset) (bool, error) {
4242
return false, nil
4343
}
4444

45-
func InstallAgent(url, token, namespace, version string, values map[string]interface{}) error {
45+
func InstallAgent(url, token, namespace, version, helmChartLoc string, values map[string]interface{}) error {
4646
settings := cli.New()
4747
vals := map[string]interface{}{
4848
"secrets": map[string]string{"deployToken": token},
4949
"consoleUrl": url,
5050
}
5151
vals = algorithms.Merge(vals, values)
5252

53-
if err := helm.AddRepo(ReleaseName, RepoUrl); err != nil {
54-
return err
55-
}
56-
5753
helmConfig, err := helm.GetActionConfig(namespace)
5854
if err != nil {
5955
return err
6056
}
6157

58+
chartLoc := fmt.Sprintf("%s/%s", ReleaseName, ChartName)
59+
if helmChartLoc == "" {
60+
fmt.Println("Adding default Repo for deployment operator chart:", RepoUrl)
61+
if err := helm.AddRepo(ReleaseName, RepoUrl); err != nil {
62+
return err
63+
}
64+
} else {
65+
fmt.Println("Using custom helm chart url:", chartLoc)
66+
chartLoc = helmChartLoc
67+
}
68+
6269
newInstallAction := action.NewInstall(helmConfig)
6370
newInstallAction.ChartPathOptions.Version = version
6471

65-
cp, err := action.NewInstall(helmConfig).ChartPathOptions.LocateChart(fmt.Sprintf("%s/%s", ReleaseName, ChartName), settings)
72+
cp, err := action.NewInstall(helmConfig).ChartPathOptions.LocateChart(chartLoc, settings)
6673
if err != nil {
6774
return err
6875
}

0 commit comments

Comments
 (0)