mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 01:39:06 +00:00
update edit add secrets/configmaps to use plugins
This commit is contained in:
@@ -17,8 +17,6 @@ limitations under the License.
|
||||
package add
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
@@ -112,12 +110,9 @@ func addSecret(
|
||||
k *types.Kustomization,
|
||||
flags flagsAndArgs, kf ifc.KunstructuredFactory) error {
|
||||
secretArgs := makeSecretArgs(k, flags.Name, flags.Type)
|
||||
err := mergeFlagsIntoSecretArgs(&secretArgs.DataSources, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mergeFlagsIntoSecretArgs(&secretArgs.KVSources, flags)
|
||||
// Validate by trying to create corev1.secret.
|
||||
_, err = kf.MakeSecret(ldr, k.GeneratorOptions, secretArgs)
|
||||
_, err := kf.MakeSecret(ldr, k.GeneratorOptions, secretArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -136,12 +131,17 @@ func makeSecretArgs(m *types.Kustomization, name, secretType string) *types.Secr
|
||||
return &m.SecretGenerator[len(m.SecretGenerator)-1]
|
||||
}
|
||||
|
||||
func mergeFlagsIntoSecretArgs(src *types.DataSources, flags flagsAndArgs) error {
|
||||
src.LiteralSources = append(src.LiteralSources, flags.LiteralSources...)
|
||||
src.FileSources = append(src.FileSources, flags.FileSources...)
|
||||
if src.EnvSource != "" && src.EnvSource != flags.EnvFileSource {
|
||||
return fmt.Errorf("updating existing env source '%s' not allowed", src.EnvSource)
|
||||
}
|
||||
src.EnvSource = flags.EnvFileSource
|
||||
return nil
|
||||
func mergeFlagsIntoSecretArgs(src *[]types.KVSource, flags flagsAndArgs) {
|
||||
*src = append(*src, types.KVSource{
|
||||
Name: "literals",
|
||||
Args: flags.LiteralSources,
|
||||
})
|
||||
*src = append(*src, types.KVSource{
|
||||
Name: "files",
|
||||
Args: flags.FileSources,
|
||||
})
|
||||
*src = append(*src, types.KVSource{
|
||||
Name: "envfiles",
|
||||
Args: []string{flags.EnvFileSource},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user