Skip to content

Commit

Permalink
Fix namespace set on upgrade command
Browse files Browse the repository at this point in the history
Namespace was not being set via annotations properly
for the upgrade command nor the install command called
from the upgrade

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Mar 9, 2021
1 parent ab3de8f commit 52cd46e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmd/hypper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ argument can be either: a chart reference('example/mariadb'), a path to a chart
a packaged chart, or a fully qualified URL. For chart references, the latest
version will be specified unless the '--version' flag is set.
There are four different ways you can select the release name and namespace
where the chart will be installed. By priority order:
1. By the args passed from the CLI: hypper upgrade --release-name mariadb example/mariadb --namespace system
2. By using hypper.cattle.io annotations in the Chart.yaml
3. By using catalog.cattle.io annotations in the Chart.yaml
4. By using the current namespace as configured with the kubeconfig
To override values in a chart, use either the '--values' flag and pass in a file
or use the '--set' flag and pass configuration from the command line, to force string
values, use '--set-string'. In case a value is large and therefore
Expand Down Expand Up @@ -114,6 +122,12 @@ func newUpgradeCmd(cfg *action.Configuration, logger log.Logger) *cobra.Command
logger.Info(eyecandy.ESPrintf(settings.NoEmojis, "Release %q does not exist. Installing it now. :toolbox:\n", client.ReleaseName))
}
instClient := action.NewInstall(cfg)
// Set namespace for the install client
if settings.NamespaceFromFlag {
instClient.Namespace = settings.Namespace()
} else {
instClient.SetNamespace(ch, settings.Namespace())
}
instClient.CreateNamespace = createNamespace
instClient.ChartPathOptions = client.ChartPathOptions
instClient.DryRun = client.DryRun
Expand Down Expand Up @@ -151,6 +165,13 @@ func newUpgradeCmd(cfg *action.Configuration, logger log.Logger) *cobra.Command
return err
}

// Set namespace for the upgrade client
if settings.NamespaceFromFlag {
client.Namespace = settings.Namespace()
} else {
client.SetNamespace(ch, settings.Namespace())
}

rel, err := client.Run(client.ReleaseName, ch, vals)
if err != nil {
return errors.Wrap(err, "UPGRADE FAILED")
Expand Down
16 changes: 16 additions & 0 deletions pkg/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ func (i *Upgrade) Name(chart *chart.Chart, args []string) (string, error) {
// If we dont have our annotations then return the base name
return chart.Metadata.Name, nil
}

// SetNamespace sets the Namespace that should be used in action.Install
//
// This will read the chart annotations. If no annotations, it leave the existing ns in the action.
func (i *Upgrade) SetNamespace(chart *chart.Chart, defaultns string) {
i.Namespace = defaultns
if chart.Metadata.Annotations != nil {
if val, ok := chart.Metadata.Annotations["hypper.cattle.io/namespace"]; ok {
i.Namespace = val
} else {
if val, ok := chart.Metadata.Annotations["catalog.cattle.io/namespace"]; ok {
i.Namespace = val
}
}
}
}

0 comments on commit 52cd46e

Please sign in to comment.