Drop useless or duplicative code.

This commit is contained in:
Jeffrey Regan
2018-07-24 10:54:18 -07:00
parent 8d420ec3f7
commit a78aa22399
8 changed files with 50 additions and 90 deletions

View File

@@ -137,7 +137,7 @@ func (f *ConfigMapFactory) MakeConfigMap2(
all = append(all, pairs...)
for _, kv := range all {
err = addKeyFromLiteralToConfigMap(cm, kv.key, kv.value)
err = AddKv(cm, kv.key, kv.value)
if err != nil {
return nil, err
}
@@ -166,7 +166,7 @@ func (f *ConfigMapFactory) handleConfigMapFromLiteralSources(
if err != nil {
return err
}
err = addKeyFromLiteralToConfigMap(configMap, k, v)
err = AddKv(configMap, k, v)
if err != nil {
return err
}
@@ -251,7 +251,7 @@ func (f *ConfigMapFactory) handleConfigMapFromEnvFileSource(
return fmt.Errorf("env config file %s cannot be a directory", args.EnvSource)
}
return addFromEnvFile(args.EnvSource, func(key, value string) error {
return addKeyFromLiteralToConfigMap(configMap, key, value)
return AddKv(configMap, key, value)
})
}
@@ -262,12 +262,12 @@ func addKeyFromFileToConfigMap(configMap *v1.ConfigMap, keyName, filePath string
if err != nil {
return err
}
return addKeyFromLiteralToConfigMap(configMap, keyName, string(data))
return AddKv(configMap, keyName, string(data))
}
// addKeyFromLiteralToConfigMap adds the given key and data to the given config map,
// returning an error if the key is not valid or if the key already exists.
func addKeyFromLiteralToConfigMap(configMap *v1.ConfigMap, keyName, data string) error {
// AddKv adds the given key and data to the given config map.
// Error if key invalid, or already exists.
func AddKv(configMap *v1.ConfigMap, keyName, data string) error {
// Note, the rules for ConfigMap keys are the exact same as the ones for SecretKeys.
if errs := validation.IsConfigMapKey(keyName); len(errs) != 0 {
return fmt.Errorf("%q is not a valid key name for a ConfigMap: %s", keyName, strings.Join(errs, ";"))

View File

@@ -21,6 +21,7 @@ import (
"testing"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -134,7 +135,9 @@ func TestConstructConfigMap(t *testing.T) {
}
// TODO: all tests should use a FakeFs
f := NewConfigMapFactory(fs.MakeRealFS(), nil)
fSys := fs.MakeRealFS()
f := NewConfigMapFactory(fSys,
loader.NewLoader(loader.NewFileLoader(fSys)))
for _, tc := range testCases {
cm, err := f.MakeConfigMap1(&tc.input)
if err != nil {