Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: edit set secret #5467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kustomize/commands/edit/set/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ func NewCmdSet(

# Sets the namesuffix field
kustomize edit set namesuffix <suffix-value>

# Edits a field in an existing configmap in the kustomization file
kustomize edit set configmap my-configmap --from-literal=key1=value1

# Edits a field in an existing secret in the kustomization file
kustomize edit set secret my-secret --from-literal=key1=value1
`,
Args: cobra.MinimumNArgs(1),
}

c.AddCommand(
newCmdSetConfigMap(fSys, ldr, rf),
newCmdSetSecret(fSys, ldr, rf),
newCmdSetNamePrefix(fSys),
newCmdSetNameSuffix(fSys),
newCmdSetNamespace(fSys, v),
Expand Down
27 changes: 18 additions & 9 deletions kustomize/commands/edit/set/setconfigmap.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

//
//nolint:dupl
package set

import (
"fmt"

"sigs.k8s.io/kustomize/api/konfig"

"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"sigs.k8s.io/kustomize/api/ifc"
Expand All @@ -24,16 +27,22 @@ func newCmdSetConfigMap(
var flags util.ConfigMapSecretFlagsAndArgs
cmd := &cobra.Command{
Use: "configmap NAME [--from-literal=key1=value1] [--namespace=namespace-name] [--new-namespace=new-namespace-name]",
Short: "Edits the value for an existing key for a configmap in the kustomization file",
Long: `Edits the value for an existing key in an existing configmap in the kustomization file.
Both configmap name and key name must exist for this command to succeed.`,
Example: `
# Edits an existing configmap in the kustomization file, changing value of key1 to 2
Short: fmt.Sprintf("Edits the value for an existing key for a ConfigMap in the %s file", konfig.DefaultKustomizationFileName()),
Long: fmt.Sprintf(`Edits the value for an existing key in an existing ConfigMap in the %[1]s file.
ConfigMap name, ConfigMap namespace, and key name must match an existing entry in the %[1]s file for this command to succeed.
When namespace is omitted, the default namespace is used. Conversely, when an entry without a specified namespace exists
in the %[1]s file, it can be updated by either omitting the namespace on the kustomize edit set configmap invocation or by
specifying --namespace=default.`, konfig.DefaultKustomizationFileName()),
Example: fmt.Sprintf(`
# Edits an existing ConfigMap in the %[1]s file, changing value of key1 to 2, and namespace is implicitly defined as "default"
kustomize edit set configmap my-configmap --from-literal=key1=2

# Edits an existing configmap in the kustomization file, changing namespace to 'new-namespace'
# Edits an existing ConfigMap in the %[1]s file, changing value of key1 to 2, and explicitly define namespace as "default"
kustomize edit set configmap my-configmap --from-literal=key1=2 --namespace default

# Edits an existing ConfigMap in the %[1]s file, changing namespace to "new-namespace"
kustomize edit set configmap my-configmap --namespace=current-namespace --new-namespace=new-namespace
`,
`, konfig.DefaultKustomizationFileName()),
RunE: func(_ *cobra.Command, args []string) error {
return runEditSetConfigMap(flags, fSys, args, ldr, rf)
},
Expand Down Expand Up @@ -144,7 +153,7 @@ func findConfigMapArgs(m *types.Kustomization, name, namespace string) (*types.C
})

if cmIndex == -1 {
return nil, fmt.Errorf("unable to find ConfigMap with name '%q'", name)
return nil, fmt.Errorf("unable to find ConfigMap with name %q", name)
}

return &m.ConfigMapGenerator[cmIndex], nil
Expand Down
Loading
Loading