update edit add secrets/configmaps to use plugins

This commit is contained in:
Seth Pollack
2019-03-20 09:24:10 -04:00
parent 46bd38e89d
commit b60fca05bd
4 changed files with 66 additions and 96 deletions

View File

@@ -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},
})
}