mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Fix cluster of silly Go nits.
This commit is contained in:
@@ -46,7 +46,9 @@ function testGoMetalinter {
|
||||
--enable=misspell \
|
||||
--enable=structcheck \
|
||||
--enable=deadcode \
|
||||
--enable=goimports \
|
||||
# Disabling 'goimports' because it reports hyphens in imported package \
|
||||
# names as errors, and we have to vendor them in regardless. \
|
||||
# --enable=goimports \
|
||||
--enable=varcheck \
|
||||
--enable=goconst \
|
||||
--enable=unparam \
|
||||
|
||||
@@ -103,7 +103,7 @@ func (a *Application) resolveRefsToGeneratedResources(m resmap.ResMap) (resmap.R
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := []transformers.Transformer{}
|
||||
var r []transformers.Transformer
|
||||
t, err := transformers.NewDefaultingNameReferenceTransformer()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -192,15 +192,15 @@ func (a *Application) loadResMapFromBasesAndResources() (resmap.ResMap, error) {
|
||||
// Loop through the Bases of this kustomization recursively loading resources.
|
||||
// Combine into one ResMap, demanding unique Ids for each resource.
|
||||
func (a *Application) loadCustomizedBases() (resmap.ResMap, *interror.KustomizationErrors) {
|
||||
list := []resmap.ResMap{}
|
||||
var list []resmap.ResMap
|
||||
errs := &interror.KustomizationErrors{}
|
||||
for _, path := range a.kustomization.Bases {
|
||||
loader, err := a.loader.New(path)
|
||||
ldr, err := a.loader.New(path)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "couldn't make loader for "+path))
|
||||
errs.Append(errors.Wrap(err, "couldn't make ldr for "+path))
|
||||
continue
|
||||
}
|
||||
app, err := NewApplication(loader)
|
||||
app, err := NewApplication(ldr)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "couldn't make app for "+path))
|
||||
continue
|
||||
@@ -223,12 +223,12 @@ func (a *Application) loadBasesAsFlatList() ([]*Application, error) {
|
||||
var result []*Application
|
||||
errs := &interror.KustomizationErrors{}
|
||||
for _, path := range a.kustomization.Bases {
|
||||
loader, err := a.loader.New(path)
|
||||
ldr, err := a.loader.New(path)
|
||||
if err != nil {
|
||||
errs.Append(err)
|
||||
continue
|
||||
}
|
||||
a, err := NewApplication(loader)
|
||||
a, err := NewApplication(ldr)
|
||||
if err != nil {
|
||||
errs.Append(err)
|
||||
continue
|
||||
@@ -243,7 +243,7 @@ func (a *Application) loadBasesAsFlatList() ([]*Application, error) {
|
||||
|
||||
// newTransformer makes a Transformer that does everything except resolve generated names.
|
||||
func (a *Application) newTransformer(patches []*resource.Resource) (transformers.Transformer, error) {
|
||||
r := []transformers.Transformer{}
|
||||
var r []transformers.Transformer
|
||||
t, err := transformers.NewPatchTransformer(patches)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -291,7 +291,7 @@ func (a *Application) resolveRefVars(m resmap.ResMap) (map[string]string, error)
|
||||
|
||||
// getAllVars returns all the "environment" style Var instances defined in the app.
|
||||
func (a *Application) getAllVars() ([]types.Var, error) {
|
||||
result := []types.Var{}
|
||||
var result []types.Var
|
||||
errs := &interror.KustomizationErrors{}
|
||||
|
||||
bases, err := a.loadBasesAsFlatList()
|
||||
|
||||
@@ -66,20 +66,20 @@ metadata:
|
||||
)
|
||||
|
||||
func makeLoader1(t *testing.T) loader.Loader {
|
||||
loader := loadertest.NewFakeLoader("/testpath")
|
||||
err := loader.AddFile("/testpath/"+constants.KustomizationFileName, []byte(kustomizationContent1))
|
||||
ldr := loadertest.NewFakeLoader("/testpath")
|
||||
err := ldr.AddFile("/testpath/"+constants.KustomizationFileName, []byte(kustomizationContent1))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
err = loader.AddFile("/testpath/deployment.yaml", []byte(deploymentContent))
|
||||
err = ldr.AddFile("/testpath/deployment.yaml", []byte(deploymentContent))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
err = loader.AddFile("/testpath/namespace.yaml", []byte(namespaceContent))
|
||||
err = ldr.AddFile("/testpath/namespace.yaml", []byte(namespaceContent))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
return loader
|
||||
return ldr
|
||||
}
|
||||
|
||||
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
|
||||
@@ -254,28 +254,28 @@ spec:
|
||||
)
|
||||
|
||||
func makeLoader2(t *testing.T) loader.Loader {
|
||||
loader := loadertest.NewFakeLoader("/testpath")
|
||||
err := loader.AddFile("/testpath/"+constants.KustomizationFileName, []byte(kustomizationContentOverlay))
|
||||
ldr := loadertest.NewFakeLoader("/testpath")
|
||||
err := ldr.AddFile("/testpath/"+constants.KustomizationFileName, []byte(kustomizationContentOverlay))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = loader.AddFile("/testpath/service.yaml", []byte(serviceContent))
|
||||
err = ldr.AddFile("/testpath/service.yaml", []byte(serviceContent))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
err = loader.AddDirectory("/testpath/base")
|
||||
err = ldr.AddDirectory("/testpath/base")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
err = loader.AddFile("/testpath/base/"+constants.KustomizationFileName, []byte(kustomizationContentBase))
|
||||
err = ldr.AddFile("/testpath/base/"+constants.KustomizationFileName, []byte(kustomizationContentBase))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
err = loader.AddFile("/testpath/base/deployment.yaml", []byte(deploymentContent))
|
||||
err = ldr.AddFile("/testpath/base/deployment.yaml", []byte(deploymentContent))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
return loader
|
||||
return ldr
|
||||
}
|
||||
|
||||
// TODO: This test covers incorrect behavior; it should not pass.
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestBuildValidate(t *testing.T) {
|
||||
func TestBuild(t *testing.T) {
|
||||
const updateEnvVar = "UPDATE_KUSTOMIZE_EXPECTED_DATA"
|
||||
updateKustomizeExpected := os.Getenv(updateEnvVar) == "true"
|
||||
fs := fs.MakeRealFS()
|
||||
fSys := fs.MakeRealFS()
|
||||
|
||||
testcases := sets.NewString()
|
||||
filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
|
||||
@@ -104,12 +104,12 @@ func TestBuild(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testcaseName := range testcases.List() {
|
||||
t.Run(testcaseName, func(t *testing.T) { runBuildTestCase(t, testcaseName, updateKustomizeExpected, fs) })
|
||||
t.Run(testcaseName, func(t *testing.T) { runBuildTestCase(t, testcaseName, updateKustomizeExpected, fSys) })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected bool, fs fs.FileSystem) {
|
||||
func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected bool, fSys fs.FileSystem) {
|
||||
name := testcaseName
|
||||
testcase := buildTestCase{}
|
||||
testcaseDir := filepath.Join("testdata", "testcase-"+name)
|
||||
@@ -125,7 +125,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
|
||||
kustomizationPath: testcase.Filename,
|
||||
}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
err = ops.RunBuild(buf, fs)
|
||||
err = ops.RunBuild(buf, fSys)
|
||||
switch {
|
||||
case err != nil && len(testcase.ExpectedError) == 0:
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
|
||||
@@ -128,7 +128,7 @@ func mergeData(src *types.DataSources, config dataConfig) error {
|
||||
src.LiteralSources = append(src.LiteralSources, config.LiteralSources...)
|
||||
src.FileSources = append(src.FileSources, config.FileSources...)
|
||||
if src.EnvSource != "" && src.EnvSource != config.EnvFileSource {
|
||||
return fmt.Errorf("updating existing env source '%s' not allowed.", src.EnvSource)
|
||||
return fmt.Errorf("updating existing env source '%s' not allowed", src.EnvSource)
|
||||
}
|
||||
src.EnvSource = config.EnvFileSource
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestDiff(t *testing.T) {
|
||||
transformedDir, _ := regexp.Compile(`/tmp/transformed-[0-9]*/`)
|
||||
timestamp, _ := regexp.Compile(`[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9].[0-9]* [+-]{1}[0-9]{4}`)
|
||||
|
||||
fs := fs.MakeRealFS()
|
||||
fSys := fs.MakeRealFS()
|
||||
|
||||
testcases := sets.NewString()
|
||||
filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
|
||||
@@ -74,7 +74,7 @@ func TestDiff(t *testing.T) {
|
||||
|
||||
for _, testcaseName := range testcases.List() {
|
||||
t.Run(testcaseName, func(t *testing.T) {
|
||||
runDiffTestCase(t, testcaseName, updateKustomizeExpected, fs,
|
||||
runDiffTestCase(t, testcaseName, updateKustomizeExpected, fSys,
|
||||
noopDir, transformedDir, timestamp)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (mf *kustomizationFile) read() (*types.Kustomization, error) {
|
||||
|
||||
func (mf *kustomizationFile) write(kustomization *types.Kustomization) error {
|
||||
if kustomization == nil {
|
||||
return errors.New("util: kustomization file arg is nil.")
|
||||
return errors.New("util: kustomization file arg is nil")
|
||||
}
|
||||
bytes, err := yaml.Marshal(kustomization)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,14 +18,8 @@ limitations under the License.
|
||||
package configmapandsecret
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
cutil "github.com/kubernetes-sigs/kustomize/pkg/configmapandsecret/util"
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/hash"
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/types"
|
||||
@@ -49,21 +43,6 @@ func MakeConfigmapAndGenerateName(cm types.ConfigMapArgs) (*unstructured.Unstruc
|
||||
return unstructuredCM, nameWithHash, err
|
||||
}
|
||||
|
||||
// MakeSecretAndGenerateName returns a secret with the name appended with a hash.
|
||||
func MakeSecretAndGenerateName(secret types.SecretArgs, path string) (*unstructured.Unstructured, string, error) {
|
||||
corev1Secret, err := makeSecret(secret, path)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
h, err := hash.SecretHash(corev1Secret)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
nameWithHash := fmt.Sprintf("%s-%s", secret.Name, h)
|
||||
unstructuredCM, err := objectToUnstructured(corev1Secret)
|
||||
return unstructuredCM, nameWithHash, err
|
||||
}
|
||||
|
||||
func objectToUnstructured(in runtime.Object) (*unstructured.Unstructured, error) {
|
||||
marshaled, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
@@ -99,38 +78,3 @@ func makeConfigMap(cm types.ConfigMapArgs) (*corev1.ConfigMap, error) {
|
||||
|
||||
return corev1cm, nil
|
||||
}
|
||||
|
||||
func makeSecret(secret types.SecretArgs, path string) (*corev1.Secret, error) {
|
||||
corev1secret := &corev1.Secret{}
|
||||
corev1secret.APIVersion = "v1"
|
||||
corev1secret.Kind = "Secret"
|
||||
corev1secret.Name = secret.Name
|
||||
corev1secret.Type = corev1.SecretType(secret.Type)
|
||||
if corev1secret.Type == "" {
|
||||
corev1secret.Type = corev1.SecretTypeOpaque
|
||||
}
|
||||
corev1secret.Data = map[string][]byte{}
|
||||
|
||||
for k, v := range secret.Commands {
|
||||
out, err := createSecretKey(path, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corev1secret.Data[k] = out
|
||||
}
|
||||
|
||||
return corev1secret, nil
|
||||
}
|
||||
|
||||
func createSecretKey(wd string, command string) ([]byte, error) {
|
||||
fi, err := os.Stat(wd)
|
||||
if err != nil || !fi.IsDir() {
|
||||
wd = filepath.Dir(wd)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", command)
|
||||
cmd.Dir = wd
|
||||
|
||||
return cmd.Output()
|
||||
}
|
||||
|
||||
@@ -17,10 +17,15 @@ limitations under the License.
|
||||
package configmapandsecret
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/types"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -110,24 +115,6 @@ func makeTestSecret(name string) *corev1.Secret {
|
||||
}
|
||||
}
|
||||
|
||||
func makeUnstructuredSecret(name string) *unstructured.Unstructured {
|
||||
return &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Secret",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": name,
|
||||
"creationTimestamp": nil,
|
||||
},
|
||||
"type": string(corev1.SecretTypeOpaque),
|
||||
"data": map[string]interface{}{
|
||||
"DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")),
|
||||
"DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestConstructConfigMap(t *testing.T) {
|
||||
type testCase struct {
|
||||
description string
|
||||
@@ -198,6 +185,41 @@ func TestConstructSecret(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeSecret(secret types.SecretArgs, path string) (*corev1.Secret, error) {
|
||||
corev1secret := &corev1.Secret{}
|
||||
corev1secret.APIVersion = "v1"
|
||||
corev1secret.Kind = "Secret"
|
||||
corev1secret.Name = secret.Name
|
||||
corev1secret.Type = corev1.SecretType(secret.Type)
|
||||
if corev1secret.Type == "" {
|
||||
corev1secret.Type = corev1.SecretTypeOpaque
|
||||
}
|
||||
corev1secret.Data = map[string][]byte{}
|
||||
|
||||
for k, v := range secret.Commands {
|
||||
out, err := createSecretKey(path, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corev1secret.Data[k] = out
|
||||
}
|
||||
|
||||
return corev1secret, nil
|
||||
}
|
||||
|
||||
func createSecretKey(wd string, command string) ([]byte, error) {
|
||||
fi, err := os.Stat(wd)
|
||||
if err != nil || !fi.IsDir() {
|
||||
wd = filepath.Dir(wd)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", command)
|
||||
cmd.Dir = wd
|
||||
|
||||
return cmd.Output()
|
||||
}
|
||||
|
||||
func TestFailConstructSecret(t *testing.T) {
|
||||
secret := types.SecretArgs{
|
||||
Name: "secret",
|
||||
|
||||
@@ -62,7 +62,7 @@ func HandleConfigMapFromFileSources(configMap *v1.ConfigMap, fileSources []strin
|
||||
}
|
||||
if info.IsDir() {
|
||||
if strings.Contains(fileSource, "=") {
|
||||
return fmt.Errorf("cannot give a key name for a directory path.")
|
||||
return fmt.Errorf("cannot give a key name for a directory path")
|
||||
}
|
||||
fileList, err := ioutil.ReadDir(filePath)
|
||||
if err != nil {
|
||||
@@ -127,7 +127,7 @@ func addKeyFromLiteralToConfigMap(configMap *v1.ConfigMap, keyName, data string)
|
||||
return fmt.Errorf("%q is not a valid key name for a ConfigMap: %s", keyName, strings.Join(errs, ";"))
|
||||
}
|
||||
if _, entryExists := configMap.Data[keyName]; entryExists {
|
||||
return fmt.Errorf("cannot add key %s, another key by that name already exists: %v.", keyName, configMap.Data)
|
||||
return fmt.Errorf("cannot add key %s, another key by that name already exists: %v", keyName, configMap.Data)
|
||||
}
|
||||
configMap.Data[keyName] = data
|
||||
return nil
|
||||
|
||||
@@ -59,7 +59,7 @@ func HandleFromFileSources(secret *v1.Secret, fileSources []string) error {
|
||||
}
|
||||
if info.IsDir() {
|
||||
if strings.Contains(fileSource, "=") {
|
||||
return fmt.Errorf("cannot give a key name for a directory path.")
|
||||
return fmt.Errorf("cannot give a key name for a directory path")
|
||||
}
|
||||
fileList, err := ioutil.ReadDir(filePath)
|
||||
if err != nil {
|
||||
@@ -119,7 +119,7 @@ func addKeyFromLiteralToSecret(secret *v1.Secret, keyName string, data []byte) e
|
||||
}
|
||||
|
||||
if _, entryExists := secret.Data[keyName]; entryExists {
|
||||
return fmt.Errorf("cannot add key %s, another key by that name already exists: %v.", keyName, secret.Data)
|
||||
return fmt.Errorf("cannot add key %s, another key by that name already exists: %v", keyName, secret.Data)
|
||||
}
|
||||
secret.Data[keyName] = data
|
||||
return nil
|
||||
|
||||
@@ -64,11 +64,11 @@ func ParseFileSource(source string) (keyName, filePath string, err error) {
|
||||
case numSeparators == 0:
|
||||
return path.Base(source), source, nil
|
||||
case numSeparators == 1 && strings.HasPrefix(source, "="):
|
||||
return "", "", fmt.Errorf("key name for file path %v missing.", strings.TrimPrefix(source, "="))
|
||||
return "", "", fmt.Errorf("key name for file path %v missing", strings.TrimPrefix(source, "="))
|
||||
case numSeparators == 1 && strings.HasSuffix(source, "="):
|
||||
return "", "", fmt.Errorf("file path for key name %v missing.", strings.TrimSuffix(source, "="))
|
||||
return "", "", fmt.Errorf("file path for key name %v missing", strings.TrimSuffix(source, "="))
|
||||
case numSeparators > 1:
|
||||
return "", "", errors.New("Key names or file paths cannot contain '='.")
|
||||
return "", "", errors.New("key names or file paths cannot contain '='")
|
||||
default:
|
||||
components := strings.Split(source, "=")
|
||||
return components[0], components[1], nil
|
||||
|
||||
@@ -66,7 +66,7 @@ func (p *pathConfigs) addPrefixPathConfig(config transformers.PathConfig) {
|
||||
|
||||
// RegisterCRDs parse CRD schemas from paths and update various pathConfigs
|
||||
func RegisterCRDs(loader loader.Loader, paths []string) error {
|
||||
pathConfigs := []pathConfigs{}
|
||||
var pathConfigs []pathConfigs
|
||||
for _, path := range paths {
|
||||
pathConfig, err := registerCRD(loader, path)
|
||||
if err != nil {
|
||||
@@ -80,8 +80,7 @@ func RegisterCRDs(loader loader.Loader, paths []string) error {
|
||||
|
||||
// register CRD from one path
|
||||
func registerCRD(loader loader.Loader, path string) ([]pathConfigs, error) {
|
||||
result := []pathConfigs{}
|
||||
|
||||
var result []pathConfigs
|
||||
content, err := loader.Load(path)
|
||||
if err != nil {
|
||||
return result, err
|
||||
|
||||
@@ -142,12 +142,12 @@ If it is not set we generate a secret dynamically",
|
||||
)
|
||||
|
||||
func makeLoader(t *testing.T) loader.Loader {
|
||||
loader := loadertest.NewFakeLoader("/testpath")
|
||||
err := loader.AddFile("/testpath/crd.json", []byte(crdContent))
|
||||
ldr := loadertest.NewFakeLoader("/testpath")
|
||||
err := ldr.AddFile("/testpath/crd.json", []byte(crdContent))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup fake loader.")
|
||||
t.Fatalf("Failed to setup fake ldr.")
|
||||
}
|
||||
return loader
|
||||
return ldr
|
||||
}
|
||||
|
||||
func TestRegisterCRD(t *testing.T) {
|
||||
@@ -184,9 +184,9 @@ func TestRegisterCRD(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
loader := makeLoader(t)
|
||||
ldr := makeLoader(t)
|
||||
|
||||
pathconfig, _ := registerCRD(loader, "/testpath/crd.json")
|
||||
pathconfig, _ := registerCRD(ldr, "/testpath/crd.json")
|
||||
|
||||
sort.Slice(pathconfig[0].namereferencePathConfigs, func(i, j int) bool {
|
||||
return pathconfig[0].namereferencePathConfigs[i].GVK() < pathconfig[0].namereferencePathConfigs[j].GVK()
|
||||
|
||||
@@ -60,7 +60,7 @@ func writeYamlToNewDir(in resmap.ResMap, prefix string) (*directory, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = print(obj, f)
|
||||
err = write(obj, f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -69,8 +69,8 @@ func writeYamlToNewDir(in resmap.ResMap, prefix string) (*directory, error) {
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// Print the object as YAML.
|
||||
func print(obj interface{}, w io.Writer) error {
|
||||
// Write the object as YAML.
|
||||
func write(obj interface{}, w io.Writer) error {
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func ExampleNew() {
|
||||
exec := exec.New()
|
||||
|
||||
cmd := exec.Command("echo", "Bonjour!")
|
||||
cmd := exec.New().Command("echo", "Bonjour!")
|
||||
buff := bytes.Buffer{}
|
||||
cmd.SetStdout(&buff)
|
||||
if err := cmd.Run(); err != nil {
|
||||
|
||||
@@ -114,6 +114,6 @@ func tryReadVariableName(input string) (string, bool, int) {
|
||||
// Not the beginning of an expression, ie, an operator
|
||||
// that doesn't begin an expression. Return the operator
|
||||
// and the first rune in the string.
|
||||
return (string(operator) + string(input[0])), false, 1
|
||||
return string(operator) + string(input[0]), false, 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package fs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -28,14 +27,6 @@ type realFile struct {
|
||||
file *os.File
|
||||
}
|
||||
|
||||
// MakeRealFile makes an instance of realFile.
|
||||
func MakeRealFile(f *os.File) (File, error) {
|
||||
if f == nil {
|
||||
return nil, errors.New("file argument may not be nil")
|
||||
}
|
||||
return &realFile{file: f}, nil
|
||||
}
|
||||
|
||||
// Close closes a file.
|
||||
func (f *realFile) Close() error { return f.file.Close() }
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package error
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
yaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
)
|
||||
|
||||
// YamlFormatError represents error with yaml file name where json/yaml format error happens.
|
||||
@@ -33,8 +33,8 @@ func (e YamlFormatError) Error() string {
|
||||
return fmt.Sprintf("YAML file [%s] encounters a format error.\n%s\n", e.Path, e.ErrorMsg)
|
||||
}
|
||||
|
||||
// ErrorHandler handles YamlFormatError
|
||||
func ErrorHandler(e error, path string) error {
|
||||
// Handler handles YamlFormatError
|
||||
func Handler(e error, path string) error {
|
||||
if err, ok := e.(yaml.YAMLSyntaxError); ok {
|
||||
return YamlFormatError{
|
||||
Path: path,
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/constants"
|
||||
yaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -49,9 +49,9 @@ func TestYamlFormatError_Error(t *testing.T) {
|
||||
func TestErrorHandler(t *testing.T) {
|
||||
f := foo{}
|
||||
err := yaml.NewYAMLToJSONDecoder(bytes.NewReader([]byte(doc))).Decode(&f)
|
||||
testErr := ErrorHandler(err, filepath)
|
||||
expectedErr := fmt.Errorf("Format error message")
|
||||
fmtErr := ErrorHandler(expectedErr, filepath)
|
||||
testErr := Handler(err, filepath)
|
||||
expectedErr := fmt.Errorf("format error message")
|
||||
fmtErr := Handler(expectedErr, filepath)
|
||||
if fmtErr.Error() != expectedErr.Error() {
|
||||
t.Errorf("Expected returning fmt.Error, but found %T", fmtErr)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ func NewFakeLoader(initialDir string) FakeLoader {
|
||||
var schemes []loader.SchemeLoader
|
||||
schemes = append(schemes, loader.NewFileLoader(fakefs))
|
||||
rootLoader := loader.Init(schemes)
|
||||
loader, _ := rootLoader.New(initialDir)
|
||||
return FakeLoader{fs: fakefs, delegate: loader}
|
||||
ldr, _ := rootLoader.New(initialDir)
|
||||
return FakeLoader{fs: fakefs, delegate: ldr}
|
||||
}
|
||||
|
||||
// AddFile adds a fake file to the file system.
|
||||
|
||||
@@ -52,7 +52,7 @@ func (l *fileLoader) IsScheme(root string, location string) bool {
|
||||
func (l *fileLoader) FullLocation(root string, location string) (string, error) {
|
||||
// First, validate the parameters
|
||||
if len(root) == 0 && len(location) == 0 {
|
||||
return "", fmt.Errorf("Unable to calculate full location: root and location empty")
|
||||
return "", fmt.Errorf("unable to calculate full location: root and location empty")
|
||||
}
|
||||
// Special case current directory, expanding to full file path.
|
||||
if location == currentDir {
|
||||
@@ -75,7 +75,7 @@ func (l *fileLoader) FullLocation(root string, location string) (string, error)
|
||||
func (l *fileLoader) Load(fullFilePath string) ([]byte, error) {
|
||||
// Validate path to load from is a full file path.
|
||||
if !filepath.IsAbs(fullFilePath) {
|
||||
return nil, fmt.Errorf("Attempting to load file without full file path: %s\n", fullFilePath)
|
||||
return nil, fmt.Errorf("attempting to load file without full file path: %s\n", fullFilePath)
|
||||
}
|
||||
return l.fs.ReadFile(fullFilePath)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func addKV(m map[string]string, kv kvPair) error {
|
||||
return fmt.Errorf("%q is not a valid key name: %s", kv.key, strings.Join(errs, ";"))
|
||||
}
|
||||
if _, exists := m[kv.key]; exists {
|
||||
return fmt.Errorf("key %s already exists: %v.", kv.key, m)
|
||||
return fmt.Errorf("key %s already exists: %v", kv.key, m)
|
||||
}
|
||||
m[kv.key] = kv.value
|
||||
return nil
|
||||
@@ -131,7 +131,7 @@ func addKV(m map[string]string, kv kvPair) error {
|
||||
|
||||
// NewResMapFromConfigMapArgs returns a Resource slice given a configmap metadata slice from kustomization file.
|
||||
func NewResMapFromConfigMapArgs(loader loader.Loader, cmList []types.ConfigMapArgs) (ResMap, error) {
|
||||
allResources := []*resource.Resource{}
|
||||
var allResources []*resource.Resource
|
||||
for _, cm := range cmList {
|
||||
res, err := newResourceFromConfigMap(loader, cm)
|
||||
if err != nil {
|
||||
|
||||
@@ -39,7 +39,7 @@ type ResMap map[resource.ResId]*resource.Resource
|
||||
|
||||
// EncodeAsYaml encodes a ResMap to YAML; encoded objects separated by `---`.
|
||||
func (m ResMap) EncodeAsYaml() ([]byte, error) {
|
||||
ids := []resource.ResId{}
|
||||
var ids []resource.ResId
|
||||
for id := range m {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
@@ -73,8 +73,8 @@ func (m ResMap) EncodeAsYaml() ([]byte, error) {
|
||||
// ErrorIfNotEqual returns error if maps are not equal.
|
||||
func (m ResMap) ErrorIfNotEqual(m2 ResMap) error {
|
||||
if len(m) != len(m2) {
|
||||
keySet1 := []resource.ResId{}
|
||||
keySet2 := []resource.ResId{}
|
||||
var keySet1 []resource.ResId
|
||||
var keySet2 []resource.ResId
|
||||
for id := range m {
|
||||
keySet1 = append(keySet1, id)
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func (m ResMap) insert(newName string, obj *unstructured.Unstructured) error {
|
||||
id := resource.NewResId(gvk, oldName)
|
||||
|
||||
if _, found := m[id]; found {
|
||||
return fmt.Errorf("The <name: %q, GroupVersionKind: %v> already exists in the map", oldName, gvk)
|
||||
return fmt.Errorf("the <name: %q, GroupVersionKind: %v> already exists in the map", oldName, gvk)
|
||||
}
|
||||
obj.SetName(newName)
|
||||
m[id] = resource.NewResourceFromUnstruct(*obj)
|
||||
@@ -111,7 +111,7 @@ func (m ResMap) insert(newName string, obj *unstructured.Unstructured) error {
|
||||
// NewResourceSliceFromPatches returns a slice of resources given a patch path slice from a kustomization file.
|
||||
func NewResourceSliceFromPatches(
|
||||
loader loader.Loader, paths []string) ([]*resource.Resource, error) {
|
||||
result := []*resource.Resource{}
|
||||
var result []*resource.Resource
|
||||
for _, path := range paths {
|
||||
contents, err := loader.GlobLoad(path)
|
||||
if err != nil {
|
||||
@@ -120,7 +120,7 @@ func NewResourceSliceFromPatches(
|
||||
for p, content := range contents {
|
||||
res, err := newResourceSliceFromBytes(content)
|
||||
if err != nil {
|
||||
return nil, internal.ErrorHandler(err, p)
|
||||
return nil, internal.Handler(err, p)
|
||||
}
|
||||
result = append(result, res...)
|
||||
|
||||
@@ -131,7 +131,7 @@ func NewResourceSliceFromPatches(
|
||||
|
||||
// NewResMapFromFiles returns a ResMap given a resource path slice.
|
||||
func NewResMapFromFiles(loader loader.Loader, paths []string) (ResMap, error) {
|
||||
result := []ResMap{}
|
||||
var result []ResMap
|
||||
for _, path := range paths {
|
||||
contents, err := loader.GlobLoad(path)
|
||||
if err != nil {
|
||||
@@ -140,7 +140,7 @@ func NewResMapFromFiles(loader loader.Loader, paths []string) (ResMap, error) {
|
||||
for p, content := range contents {
|
||||
res, err := newResMapFromBytes(content)
|
||||
if err != nil {
|
||||
return nil, internal.ErrorHandler(err, p)
|
||||
return nil, internal.Handler(err, p)
|
||||
}
|
||||
result = append(result, res)
|
||||
}
|
||||
@@ -180,8 +180,7 @@ func newResMapFromResourceSlice(resources []*resource.Resource) (ResMap, error)
|
||||
|
||||
func newResourceSliceFromBytes(in []byte) ([]*resource.Resource, error) {
|
||||
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewReader(in), 1024)
|
||||
result := []*resource.Resource{}
|
||||
|
||||
var result []*resource.Resource
|
||||
var err error
|
||||
for {
|
||||
var out unstructured.Unstructured
|
||||
@@ -201,11 +200,11 @@ func newResourceSliceFromBytes(in []byte) ([]*resource.Resource, error) {
|
||||
func MergeWithoutOverride(maps ...ResMap) (ResMap, error) {
|
||||
result := ResMap{}
|
||||
for _, m := range maps {
|
||||
for id, resource := range m {
|
||||
for id, res := range m {
|
||||
if _, found := result[id]; found {
|
||||
return nil, fmt.Errorf("id '%q' already used", id)
|
||||
}
|
||||
result[id] = resource
|
||||
result[id] = res
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
@@ -235,12 +234,12 @@ func MergeWithOverride(maps ...ResMap) (ResMap, error) {
|
||||
glog.V(4).Infof("Merged object is %v", result[id].Object)
|
||||
result[id].SetBehavior(resource.BehaviorCreate)
|
||||
default:
|
||||
return nil, fmt.Errorf("Id %#v exists; must merge or replace.", id)
|
||||
return nil, fmt.Errorf("id %#v exists; must merge or replace", id)
|
||||
}
|
||||
} else {
|
||||
switch r.Behavior() {
|
||||
case resource.BehaviorMerge, resource.BehaviorReplace:
|
||||
return nil, fmt.Errorf("Id %#v does not exist; cannot merge or replace.", id)
|
||||
return nil, fmt.Errorf("id %#v does not exist; cannot merge or replace", id)
|
||||
default:
|
||||
result[id] = r
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func createSecretKey(wd string, command string) ([]byte, error) {
|
||||
// NewResMapFromSecretArgs takes a SecretArgs slice and executes its command in directory p
|
||||
// then writes the output to a Resource slice and return it.
|
||||
func NewResMapFromSecretArgs(p string, secretList []types.SecretArgs) (ResMap, error) {
|
||||
allResources := []*resource.Resource{}
|
||||
var allResources []*resource.Resource
|
||||
for _, secret := range secretList {
|
||||
res, err := newResourceFromSecretGenerator(p, secret)
|
||||
if err != nil {
|
||||
|
||||
@@ -121,7 +121,7 @@ func (r *Resource) GetFieldValue(fieldPath string) (string, error) {
|
||||
|
||||
func getFieldValue(m map[string]interface{}, pathToField []string) (string, error) {
|
||||
if len(pathToField) == 0 {
|
||||
return "", fmt.Errorf("Field not found")
|
||||
return "", fmt.Errorf("field not found")
|
||||
}
|
||||
if len(pathToField) == 1 {
|
||||
if v, found := m[pathToField[0]]; found {
|
||||
|
||||
@@ -871,8 +871,7 @@ func AddNameReferencePathConfigs(r []ReferencePathConfig) {
|
||||
|
||||
// MergeNameReferencePathConfigs merges one ReferencePathConfig into a slice of ReferencePathConfig
|
||||
func MergeNameReferencePathConfigs(configs []ReferencePathConfig, config ReferencePathConfig) []ReferencePathConfig {
|
||||
result := []ReferencePathConfig{}
|
||||
|
||||
var result []ReferencePathConfig
|
||||
found := false
|
||||
for _, c := range configs {
|
||||
if c.referencedGVK == config.referencedGVK {
|
||||
|
||||
@@ -20,8 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
|
||||
"github.com/evanphx/json-patch"
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/resource"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
@@ -19,7 +19,7 @@ package transformers
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
"github.com/evanphx/json-patch"
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/resource"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/mergepatch"
|
||||
|
||||
Reference in New Issue
Block a user