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

@ -85,7 +85,7 @@ set for a key called 'foo', the 'newbar' value would take precedence:
$ helm install --set foo=bar --set foo=newbar myredis ./redis $ helm install --set foo=bar --set foo=newbar myredis ./redis
Similarly, in the following example 'foo' is set to '["four"]': Similarly, in the following example 'foo' is set to '["four"]':
$ helm install --set-json='foo=["one", "two", "three"]' --set-json='foo=["four"]' myredis ./redis $ helm install --set-json='foo=["one", "two", "three"]' --set-json='foo=["four"]' myredis ./redis
@ -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) { 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.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: // --dry-run options with expected outcome:
// - Not set means no dry run and server is contacted. // - 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 // - 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{} valueOpts := &values.Options{}
var outfmt output.Format var outfmt output.Format
var createNamespace bool var createNamespace bool
var createNamespaceMetadata string
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "upgrade [RELEASE] [CHART]", Use: "upgrade [RELEASE] [CHART]",
@ -123,6 +124,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
} }
instClient := action.NewInstall(cfg) instClient := action.NewInstall(cfg)
instClient.CreateNamespace = createNamespace instClient.CreateNamespace = createNamespace
instClient.CreateNamespaceMetadata = createNamespaceMetadata
instClient.ChartPathOptions = client.ChartPathOptions instClient.ChartPathOptions = client.ChartPathOptions
instClient.Force = client.Force instClient.Force = client.Force
instClient.DryRun = client.DryRun instClient.DryRun = client.DryRun
@ -239,6 +241,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.BoolVar(&createNamespace, "create-namespace", false, "if --install is set, create the release namespace if not present") 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.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.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.") 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 ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"fmt" "fmt"
"io" "io"
"net/url" "net/url"
@ -72,6 +73,7 @@ type Install struct {
ClientOnly bool ClientOnly bool
Force bool Force bool
CreateNamespace bool CreateNamespace bool
CreateNamespaceMetadata string
DryRun bool DryRun bool
DryRunOption string DryRunOption string
DisableHooks bool 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) buf, err := yaml.Marshal(ns)
if err != nil { if err != nil {
return nil, err return nil, err

Loading…
Cancel
Save