mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
Address new linter complaints
This commit is contained in:
@@ -330,7 +330,7 @@ func (r *ByteReader) decode(originalYAML string, index int, decoder *yaml.Decode
|
||||
// derive and add the seqindent annotation
|
||||
seqIndentStyle := yaml.DeriveSeqIndentStyle(originalYAML)
|
||||
if seqIndentStyle != "" {
|
||||
r.SetAnnotations[kioutil.SeqIndentAnnotation] = fmt.Sprintf("%s", seqIndentStyle)
|
||||
r.SetAnnotations[kioutil.SeqIndentAnnotation] = seqIndentStyle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestIgnoreFilesMatcher_readIgnoreFile(t *testing.T) {
|
||||
fsMakers := map[string]func(bool) (string, filesys.FileSystem){
|
||||
// onDisk creates a temp directory and returns a nil FileSystem, testing
|
||||
// the normal conditions under which ignoreFileMatcher is used.
|
||||
"onDisk": func(writeIgnoreFile bool) (string, filesys.FileSystem) {
|
||||
"onDisk": func(writeIgnoreFile bool) (string, filesys.FileSystem) { //nolint:unparam
|
||||
dir, err := ioutil.TempDir("", "kyaml-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -107,10 +107,10 @@ func TestLocalPackageReader_Read_ignoreFile(t *testing.T) {
|
||||
filepath.Join("a", "c"),
|
||||
},
|
||||
files: map[string][]byte{
|
||||
filepath.Join("pkgFile"): {},
|
||||
"pkgFile": {},
|
||||
filepath.Join("a", "b", "a_test.yaml"): readFileA,
|
||||
filepath.Join("a", "c", "c_test.yaml"): readFileB,
|
||||
filepath.Join(".krmignore"): []byte(`
|
||||
".krmignore": []byte(`
|
||||
a/c/c_test.yaml
|
||||
`,
|
||||
),
|
||||
@@ -127,10 +127,10 @@ a/c/c_test.yaml
|
||||
filepath.Join("a", "c"),
|
||||
},
|
||||
files: map[string][]byte{
|
||||
filepath.Join("pkgFile"): {},
|
||||
"pkgFile": {},
|
||||
filepath.Join("a", "b", "a_test.yaml"): readFileA,
|
||||
filepath.Join("a", "c", "c_test.yaml"): readFileB,
|
||||
filepath.Join(".krmignore"): []byte(`
|
||||
".krmignore": []byte(`
|
||||
a/c
|
||||
`,
|
||||
),
|
||||
@@ -146,10 +146,10 @@ a/c
|
||||
filepath.Join("a", "c"),
|
||||
},
|
||||
files: map[string][]byte{
|
||||
filepath.Join("pkgFile"): {},
|
||||
"pkgFile": {},
|
||||
filepath.Join("a", "c", "a_test.yaml"): readFileA,
|
||||
filepath.Join("a", "c", "c_test.yaml"): readFileB,
|
||||
filepath.Join(".krmignore"): []byte(`
|
||||
".krmignore": []byte(`
|
||||
d/e/f.yaml
|
||||
`,
|
||||
),
|
||||
@@ -168,10 +168,10 @@ a_test.yaml
|
||||
filepath.Join("a", "c"),
|
||||
},
|
||||
files: map[string][]byte{
|
||||
filepath.Join("pkgFile"): {},
|
||||
"pkgFile": {},
|
||||
filepath.Join("a", "c", "a_test.yaml"): readFileA,
|
||||
filepath.Join("a", "c", "c_test.yaml"): readFileB,
|
||||
filepath.Join(".krmignore"): []byte(`
|
||||
".krmignore": []byte(`
|
||||
a/c/c_test.yaml
|
||||
`,
|
||||
),
|
||||
@@ -187,16 +187,16 @@ a_test.yaml
|
||||
{
|
||||
name: "handles a combination of packages and directories",
|
||||
directories: []string{
|
||||
filepath.Join("a"),
|
||||
"a",
|
||||
filepath.Join("d", "e"),
|
||||
filepath.Join("f"),
|
||||
"f",
|
||||
},
|
||||
files: map[string][]byte{
|
||||
filepath.Join("pkgFile"): {},
|
||||
"pkgFile": {},
|
||||
filepath.Join("d", "pkgFile"): {},
|
||||
filepath.Join("d", "e", "pkgFile"): {},
|
||||
filepath.Join("f", "pkgFile"): {},
|
||||
filepath.Join("manifest.yaml"): []byte(`root: root`),
|
||||
"manifest.yaml": []byte(`root: root`),
|
||||
filepath.Join("a", "manifest.yaml"): []byte(`a: a`),
|
||||
filepath.Join("d", "manifest.yaml"): []byte(`d: d`),
|
||||
filepath.Join("d", "e", "manifest.yaml"): []byte(`e: e`),
|
||||
@@ -215,14 +215,14 @@ manifest.yaml
|
||||
{
|
||||
name: "ignore file can exclude subpackages",
|
||||
directories: []string{
|
||||
filepath.Join("a"),
|
||||
"a",
|
||||
},
|
||||
files: map[string][]byte{
|
||||
filepath.Join("pkgFile"): {},
|
||||
"pkgFile": {},
|
||||
filepath.Join("a", "pkgFile"): {},
|
||||
filepath.Join("manifest.yaml"): []byte(`root: root`),
|
||||
"manifest.yaml": []byte(`root: root`),
|
||||
filepath.Join("a", "manifest.yaml"): []byte(`a: a`),
|
||||
filepath.Join(".krmignore"): []byte(`
|
||||
".krmignore": []byte(`
|
||||
a
|
||||
`),
|
||||
},
|
||||
|
||||
@@ -270,7 +270,10 @@ func ReconcileInternalAnnotations(result []*yaml.RNode, nodeAnnosMap map[string]
|
||||
}
|
||||
|
||||
// determineAnnotationsFormat determines if the resources are using one of the internal and legacy annotation format or both of them.
|
||||
func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (useInternal, useLegacy bool, err error) {
|
||||
func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (bool, bool, error) {
|
||||
var useInternal, useLegacy bool
|
||||
var err error
|
||||
|
||||
if len(nodeAnnosMap) == 0 {
|
||||
return true, true, nil
|
||||
}
|
||||
@@ -295,7 +298,7 @@ func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (useI
|
||||
}
|
||||
if (foundOneOf && !*internal) || (!foundOneOf && *internal) {
|
||||
err = fmt.Errorf("the annotation formatting in the input resources is not consistent")
|
||||
return
|
||||
return useInternal, useLegacy, err
|
||||
}
|
||||
|
||||
foundOneOf = foundLegacyPath || foundLegacyIndex || foundLegacyId
|
||||
@@ -305,7 +308,7 @@ func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (useI
|
||||
}
|
||||
if (foundOneOf && !*legacy) || (!foundOneOf && *legacy) {
|
||||
err = fmt.Errorf("the annotation formatting in the input resources is not consistent")
|
||||
return
|
||||
return useInternal, useLegacy, err
|
||||
}
|
||||
}
|
||||
if internal != nil {
|
||||
@@ -314,7 +317,7 @@ func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (useI
|
||||
if legacy != nil {
|
||||
useLegacy = *legacy
|
||||
}
|
||||
return
|
||||
return useInternal, useLegacy, err
|
||||
}
|
||||
|
||||
func missingInternalOrLegacyAnnotations(rn *yaml.RNode) error {
|
||||
@@ -382,13 +385,14 @@ func checkAnnotationsAltered(rn *yaml.RNode, nodeAnnosMap map[string]map[string]
|
||||
originalPath = originalAnnotations[kioutil.LegacyPathAnnotation]
|
||||
}
|
||||
if originalPath != "" {
|
||||
if originalPath != internal.path && originalPath != legacy.path && internal.path != legacy.path {
|
||||
switch {
|
||||
case originalPath != internal.path && originalPath != legacy.path && internal.path != legacy.path:
|
||||
return fmt.Errorf("resource input to function has mismatched legacy and internal path annotations")
|
||||
} else if originalPath != internal.path {
|
||||
case originalPath != internal.path:
|
||||
if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.LegacyPathAnnotation, internal.path)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if originalPath != legacy.path {
|
||||
case originalPath != legacy.path:
|
||||
if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.PathAnnotation, legacy.path)); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -400,13 +404,14 @@ func checkAnnotationsAltered(rn *yaml.RNode, nodeAnnosMap map[string]map[string]
|
||||
originalIndex = originalAnnotations[kioutil.LegacyIndexAnnotation]
|
||||
}
|
||||
if originalIndex != "" {
|
||||
if originalIndex != internal.index && originalIndex != legacy.index && internal.index != legacy.index {
|
||||
switch {
|
||||
case originalIndex != internal.index && originalIndex != legacy.index && internal.index != legacy.index:
|
||||
return fmt.Errorf("resource input to function has mismatched legacy and internal index annotations")
|
||||
} else if originalIndex != internal.index {
|
||||
case originalIndex != internal.index:
|
||||
if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.LegacyIndexAnnotation, internal.index)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if originalIndex != legacy.index {
|
||||
case originalIndex != legacy.index:
|
||||
if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.IndexAnnotation, legacy.index)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -883,7 +883,6 @@ data:
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, tc.expectedErr, err.Error())
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,7 +644,9 @@ metadata:
|
||||
internal.config.kubernetes.io/e: 'f'
|
||||
internal.config.kubernetes.io/g: 'h'
|
||||
`,
|
||||
expectedErr: `internal annotations differ: internal.config.kubernetes.io/a, internal.config.kubernetes.io/c, internal.config.kubernetes.io/e, internal.config.kubernetes.io/g`,
|
||||
expectedErr: `internal annotations differ: ` +
|
||||
`internal.config.kubernetes.io/a, internal.config.kubernetes.io/c, ` +
|
||||
`internal.config.kubernetes.io/e, internal.config.kubernetes.io/g`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -216,9 +216,19 @@ func TestLocalPackageReader_Read_JSON(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, nodes, 2)
|
||||
expected := []string{
|
||||
`{"a": "b", metadata: {annotations: {config.kubernetes.io/index: '0', config.kubernetes.io/path: 'a_test.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'a_test.json'}}}
|
||||
`{"a": "b", ` +
|
||||
`metadata: {annotations: {` +
|
||||
`config.kubernetes.io/index: '0', ` +
|
||||
`config.kubernetes.io/path: 'a_test.json', ` +
|
||||
`internal.config.kubernetes.io/index: '0', ` +
|
||||
`internal.config.kubernetes.io/path: 'a_test.json'}}}
|
||||
`,
|
||||
`{"e": "f", "g": {"h": ["i", "j"]}, metadata: {annotations: {config.kubernetes.io/index: '0', config.kubernetes.io/path: 'b_test.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'b_test.json'}}}
|
||||
`{"e": "f", "g": {"h": ["i", "j"]}, ` +
|
||||
`metadata: {annotations: {` +
|
||||
`config.kubernetes.io/index: '0', ` +
|
||||
`config.kubernetes.io/path: 'b_test.json', ` +
|
||||
`internal.config.kubernetes.io/index: '0', ` +
|
||||
`internal.config.kubernetes.io/path: 'b_test.json'}}}
|
||||
`,
|
||||
}
|
||||
for i := range nodes {
|
||||
|
||||
@@ -325,7 +325,7 @@ metadata:
|
||||
|
||||
// These two lines are similar to calling ioutil.TempDir, but we don't actually create any directory.
|
||||
rand.Seed(time.Now().Unix())
|
||||
path := filepath.Join(os.TempDir(), fmt.Sprintf("kyaml-test%d", rand.Int31()))
|
||||
path := filepath.Join(os.TempDir(), fmt.Sprintf("kyaml-test%d", rand.Int31())) //nolint:gosec
|
||||
require.NoError(t, mockFS.MkdirAll(filepath.Join(path, "a")))
|
||||
return path, node1, node2, node3, func() { require.NoError(t, mockFS.RemoveAll(path)) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user