add flag to add namespace metadata

pull/12830/head
Krzysztof Ostrowski 2 years ago
parent c5698e5e51
commit e5481dce96
No known key found for this signature in database
GPG Key ID: C8D389AA4B172F88

@ -167,6 +167,7 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
func addInstallFlags(cmd *cobra.Command, f *pflag.FlagSet, client *action.Install, valueOpts *values.Options) {
f.BoolVar(&client.CreateNamespace, "create-namespace", false, "create the release namespace if not present")
f.StringVar(&client.CreateNamespaceMetadata, "create-namespace-metadata", "", "Add namespace metadata as json-formatted string when creating the namespace with --create-namespace.")
// --dry-run options with expected outcome:
// - Not set means no dry run and server is contacted.
// - Set with no value, a value of client, or a value of true and the server is not contacted

@ -79,6 +79,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
valueOpts := &values.Options{}
var outfmt output.Format
var createNamespace bool
var createNamespaceMetadata string
cmd := &cobra.Command{
Use: "upgrade [RELEASE] [CHART]",
@ -123,6 +124,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
}
instClient := action.NewInstall(cfg)
instClient.CreateNamespace = createNamespace
instClient.CreateNamespaceMetadata = createNamespaceMetadata
instClient.ChartPathOptions = client.ChartPathOptions
instClient.Force = client.Force
instClient.DryRun = client.DryRun
@ -239,6 +241,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags()
f.BoolVar(&createNamespace, "create-namespace", false, "if --install is set, create the release namespace if not present")
f.StringVar(&createNamespaceMetadata, "create-namespace-metadata", "", "Add namespace metadata as json-formatted string when creating the namespace with --create-namespace.")
f.BoolVarP(&client.Install, "install", "i", false, "if a release by this name doesn't already exist, run an install")
f.BoolVar(&client.Devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored")
f.StringVar(&client.DryRunOption, "dry-run", "", "simulate an install. If --dry-run is set with no option being specified or as '--dry-run=client', it will not attempt cluster connections. Setting '--dry-run=server' allows attempting cluster connections.")

@ -19,6 +19,7 @@ package action
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/url"
@ -72,6 +73,7 @@ type Install struct {
ClientOnly bool
Force bool
CreateNamespace bool
CreateNamespaceMetadata string
DryRun bool
DryRunOption string
DisableHooks bool
@ -360,6 +362,11 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
},
},
}
if len(i.CreateNamespaceMetadata) > 0 {
if err := json.Unmarshal([]byte(i.CreateNamespaceMetadata), &ns.ObjectMeta); err != nil {
return nil, errors.Wrap(err, "unable to unmarshal namespace metadata")
}
}
buf, err := yaml.Marshal(ns)
if err != nil {
return nil, err

Loading…
Cancel
Save