From c3c02887ecec9fa098c88038867e79e9734eb4fc Mon Sep 17 00:00:00 2001 From: natasha41575 Date: Tue, 19 Oct 2021 15:31:11 -0700 Subject: [PATCH 1/2] bump ResourceList from v1alpha1 to v1 --- cmd/config/internal/commands/cmdwrap_test.go | 8 ++-- cmd/config/internal/commands/cmdxargs_test.go | 2 +- cmd/config/internal/commands/sink_test.go | 8 ++-- cmd/config/internal/commands/source_test.go | 8 ++-- .../internal/krmfunction/converter_test.go | 8 ++-- .../application-cr/image/main_test.go | 4 +- kyaml/fn/framework/command/example_test.go | 16 ++++---- kyaml/fn/framework/example_test.go | 24 ++++++------ kyaml/fn/framework/framework_test.go | 4 +- kyaml/fn/framework/processors_test.go | 18 ++++----- .../testdata/validation/error/input.yaml | 2 +- .../runtime/runtimeutil/runtimeutil_test.go | 38 +++++++++---------- kyaml/kio/byteio_reader.go | 2 +- kyaml/kio/byteio_reader_test.go | 6 +-- kyaml/kio/byteio_readwriter_test.go | 24 ++++++------ kyaml/kio/byteio_writer_test.go | 4 +- kyaml/kio/kio_test.go | 4 +- 17 files changed, 90 insertions(+), 90 deletions(-) diff --git a/cmd/config/internal/commands/cmdwrap_test.go b/cmd/config/internal/commands/cmdwrap_test.go index 4b2e689bb00..d3c261cc819 100644 --- a/cmd/config/internal/commands/cmdwrap_test.go +++ b/cmd/config/internal/commands/cmdwrap_test.go @@ -14,7 +14,7 @@ import ( ) const ( - input = `apiVersion: config.kubernetes.io/v1alpha1 + input = `apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: metadata: @@ -68,7 +68,7 @@ items: name: test ` - output = `apiVersion: config.kubernetes.io/v1alpha1 + output = `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -127,7 +127,7 @@ items: targetPort: 8080 ` - outputNoMerge = `apiVersion: config.kubernetes.io/v1alpha1 + outputNoMerge = `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -183,7 +183,7 @@ items: targetPort: 8080 ` - outputOverride = `apiVersion: config.kubernetes.io/v1alpha1 + outputOverride = `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 diff --git a/cmd/config/internal/commands/cmdxargs_test.go b/cmd/config/internal/commands/cmdxargs_test.go index a170c49bda3..b3276ce498c 100644 --- a/cmd/config/internal/commands/cmdxargs_test.go +++ b/cmd/config/internal/commands/cmdxargs_test.go @@ -39,7 +39,7 @@ functionConfig: - 4 ` - resourceInput = `apiVersion: config.kubernetes.io/v1alpha1 + resourceInput = `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 diff --git a/cmd/config/internal/commands/sink_test.go b/cmd/config/internal/commands/sink_test.go index 67d364d6242..0c9505adede 100644 --- a/cmd/config/internal/commands/sink_test.go +++ b/cmd/config/internal/commands/sink_test.go @@ -22,7 +22,7 @@ func TestSinkCommand(t *testing.T) { defer os.RemoveAll(d) r := commands.GetSinkRunner("") - r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1 + r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -144,7 +144,7 @@ func TestSinkCommandJSON(t *testing.T) { defer os.RemoveAll(d) r := commands.GetSinkRunner("") - r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1 + r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", @@ -191,7 +191,7 @@ func TestSinkCommand_Stdout(t *testing.T) { // fmt the files out := &bytes.Buffer{} r := commands.GetSinkRunner("") - r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1 + r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -305,7 +305,7 @@ func TestSinkCommandJSON_Stdout(t *testing.T) { // fmt the files out := &bytes.Buffer{} r := commands.GetSinkRunner("") - r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1 + r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", diff --git a/cmd/config/internal/commands/source_test.go b/cmd/config/internal/commands/source_test.go index dd779d7e254..c7ad70d0611 100644 --- a/cmd/config/internal/commands/source_test.go +++ b/cmd/config/internal/commands/source_test.go @@ -81,7 +81,7 @@ spec: return } - if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1 + if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -199,7 +199,7 @@ func TestSourceCommandJSON(t *testing.T) { return } - if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1 + if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f1.json'}}, "spec": {"replicas": 1}} @@ -246,7 +246,7 @@ spec: return } - if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1 + if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -309,7 +309,7 @@ func TestSourceCommandJSON_Stdin(t *testing.T) { return } - if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1 + if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', internal.config.kubernetes.io/index: '0'}}, "spec": {"replicas": 1}} diff --git a/cmd/pluginator/internal/krmfunction/converter_test.go b/cmd/pluginator/internal/krmfunction/converter_test.go index 7bc1cc52c8e..4016e555023 100644 --- a/cmd/pluginator/internal/krmfunction/converter_test.go +++ b/cmd/pluginator/internal/krmfunction/converter_test.go @@ -74,7 +74,7 @@ func (p *plugin) Transform(rm resmap.ResMap) error { func getTransformerInputResource() []byte { return []byte(` -apiVersion: config.kubernetes.io/v1beta1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: apiVersion: foo-corp.com/v1 @@ -128,7 +128,7 @@ func TestTransformerConverter(t *testing.T) { assert.NoError(t, err) output := runKrmFunction(t, getTransformerInputResource(), filepath.Join(dir, "output")) - assert.Equal(t, `apiVersion: config.kubernetes.io/v1beta1 + assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -193,7 +193,7 @@ func (p *plugin) Generate() (resmap.ResMap, error) { func getGeneratorInputResource() []byte { return []byte(` -apiVersion: config.kubernetes.io/v1beta1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: apiVersion: foo-corp.com/v1 @@ -224,7 +224,7 @@ func TestGeneratorConverter(t *testing.T) { err := c.Convert() assert.NoError(t, err) output := runKrmFunction(t, getGeneratorInputResource(), filepath.Join(dir, "output")) - assert.Equal(t, `apiVersion: config.kubernetes.io/v1beta1 + assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 diff --git a/functions/examples/application-cr/image/main_test.go b/functions/examples/application-cr/image/main_test.go index fe5fabdc351..b9f8fd00a13 100644 --- a/functions/examples/application-cr/image/main_test.go +++ b/functions/examples/application-cr/image/main_test.go @@ -13,7 +13,7 @@ import ( "testing" ) -var input = `apiVersion: config.kubernetes.io/v1alpha1 +var input = `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -89,7 +89,7 @@ functionConfig: url: https://metrics/internal/worldpress-01/web-app ` -var output = `apiVersion: config.kubernetes.io/v1alpha1 +var output = `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 diff --git a/kyaml/fn/framework/command/example_test.go b/kyaml/fn/framework/command/example_test.go index 0badd3f9521..fbfd87522ec 100644 --- a/kyaml/fn/framework/command/example_test.go +++ b/kyaml/fn/framework/command/example_test.go @@ -37,7 +37,7 @@ func ExampleBuild_modify() { // for testing purposes only -- normally read from stdin when Executing cmd.SetIn(bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList # items are provided as nodes items: @@ -61,7 +61,7 @@ functionConfig: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -133,7 +133,7 @@ metadata: // for testing purposes only -- normally read from stdin when Executing cmd.SetIn(bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList # items are provided as nodes items: @@ -154,7 +154,7 @@ functionConfig: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -241,7 +241,7 @@ metadata: // for testing purposes only -- normally read from stdin when Executing cmd.SetIn(bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList # items are provided as nodes items: @@ -268,7 +268,7 @@ functionConfig: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -346,7 +346,7 @@ func ExampleBuild_validate() { cmd := command.Build(framework.ResourceListProcessorFunc(fn), command.StandaloneDisabled, true) // for testing purposes only -- normally read from stdin when Executing cmd.SetIn(bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList # items are provided as nodes items: @@ -362,7 +362,7 @@ items: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 diff --git a/kyaml/fn/framework/example_test.go b/kyaml/fn/framework/example_test.go index 14ed7015f7d..e2dd17b652c 100644 --- a/kyaml/fn/framework/example_test.go +++ b/kyaml/fn/framework/example_test.go @@ -23,7 +23,7 @@ const service = "Service" // ExampleSimpleProcessor_modify implements a function that sets an annotation on each resource. func ExampleSimpleProcessor_modify() { input := bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList # items are provided as nodes items: @@ -60,7 +60,7 @@ functionConfig: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -86,7 +86,7 @@ functionConfig: // If the resource already exists, it replaces the resource with a new copy. func ExampleSimpleProcessor_generateReplace() { input := bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList # items are provided as nodes items: @@ -150,7 +150,7 @@ metadata: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -471,7 +471,7 @@ spec: // The second resource will be treated as a patch since its metadata matches the resource // generated by ResourceTemplates and MergeResources is true. rw := kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -501,7 +501,7 @@ functionConfig: } // Output: - // apiVersion: config.kubernetes.io/v1alpha1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -543,7 +543,7 @@ func ExampleSelector_templatizeKinds() { } rw := &kio.ByteReadWriter{ Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1beta1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: kindName: Deployment @@ -575,7 +575,7 @@ items: } // Output: - // apiVersion: config.kubernetes.io/v1beta1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -595,7 +595,7 @@ func ExampleSelector_templatizeAnnotations() { Value string `yaml:"value"` } rw := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1beta1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: value: bar @@ -629,7 +629,7 @@ items: } // Output: - // apiVersion: config.kubernetes.io/v1beta1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 @@ -995,7 +995,7 @@ func ExampleVersionedAPIProcessor() { }}} source := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1beta1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: apiVersion: example.com/v1alpha1 @@ -1011,7 +1011,7 @@ functionConfig: } // Output: - // apiVersion: config.kubernetes.io/v1beta1 + // apiVersion: config.kubernetes.io/v1 // kind: ResourceList // items: // - apiVersion: apps/v1 diff --git a/kyaml/fn/framework/framework_test.go b/kyaml/fn/framework/framework_test.go index 0a4eb1b8f34..4fd39debf87 100644 --- a/kyaml/fn/framework/framework_test.go +++ b/kyaml/fn/framework/framework_test.go @@ -48,7 +48,7 @@ func TestExecute_Result(t *testing.T) { out := new(bytes.Buffer) source := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` kind: ResourceList -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 items: - kind: Deployment apiVersion: v1 @@ -63,7 +63,7 @@ items: [error] : some error`) assert.Equal(t, 1, err.(*framework.Result).ExitCode()) - assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1 + assert.Equal(t, `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment diff --git a/kyaml/fn/framework/processors_test.go b/kyaml/fn/framework/processors_test.go index 0b3e9f9d3c3..82506a47f6d 100644 --- a/kyaml/fn/framework/processors_test.go +++ b/kyaml/fn/framework/processors_test.go @@ -35,7 +35,7 @@ func TestTemplateProcessor_ResourceTemplates(t *testing.T) { out := new(bytes.Buffer) rw := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -47,7 +47,7 @@ functionConfig: require.NoError(t, framework.Execute(p, rw)) require.Equal(t, strings.TrimSpace(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -98,7 +98,7 @@ metadata: out := new(bytes.Buffer) rw := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -130,7 +130,7 @@ functionConfig: require.NoError(t, framework.Execute(p, rw)) require.Equal(t, strings.TrimSpace(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -194,7 +194,7 @@ env: out := new(bytes.Buffer) rw := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -231,7 +231,7 @@ functionConfig: require.NoError(t, framework.Execute(p, rw)) require.Equal(t, strings.TrimSpace(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -300,7 +300,7 @@ func TestTemplateProcessor_ContainerPatchTemplates_MultipleWorkloadKinds(t *test out := new(bytes.Buffer) rw := &kio.ByteReadWriter{Writer: out, Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: [] functionConfig: @@ -591,7 +591,7 @@ func TestTemplateProcessor_AdditionalSchemas(t *testing.T) { out := new(bytes.Buffer) rw := &kio.ByteReadWriter{Reader: bytes.NewBufferString(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: example.com/v1 @@ -606,7 +606,7 @@ items: Writer: out} require.NoError(t, framework.Execute(p, rw)) require.Equal(t, strings.TrimSpace(` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: example.com/v1 diff --git a/kyaml/fn/framework/testdata/validation/error/input.yaml b/kyaml/fn/framework/testdata/validation/error/input.yaml index 41052ae8d35..ad461dfd782 100644 --- a/kyaml/fn/framework/testdata/validation/error/input.yaml +++ b/kyaml/fn/framework/testdata/validation/error/input.yaml @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 kind: ResourceList -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 functionConfig: apiVersion: example.com/v1alpha1 kind: JavaSpringBoot diff --git a/kyaml/fn/runtime/runtimeutil/runtimeutil_test.go b/kyaml/fn/runtime/runtimeutil/runtimeutil_test.go index b5bb651bc20..e107c13c341 100644 --- a/kyaml/fn/runtime/runtimeutil/runtimeutil_test.go +++ b/kyaml/fn/runtime/runtimeutil/runtimeutil_test.go @@ -62,7 +62,7 @@ func TestFunctionFilter_Filter(t *testing.T) { name: "default_file_path_annotation", run: testRun{ output: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -103,7 +103,7 @@ metadata: name: "no_default_file_path_annotation", run: testRun{ output: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -146,7 +146,7 @@ metadata: name: "write_read", run: testRun{ output: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -203,7 +203,7 @@ metadata: { name: "write_results_file", run: testRun{ - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -283,7 +283,7 @@ metadata: run: testRun{ err: fmt.Errorf("failed"), output: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -363,7 +363,7 @@ metadata: run: testRun{ err: fmt.Errorf("failed"), output: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -440,7 +440,7 @@ metadata: noMakeResultsFile: true, run: testRun{ output: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -487,7 +487,7 @@ metadata: { name: "scope_resources_by_directory", run: testRun{ - expectedInput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedInput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -506,7 +506,7 @@ functionConfig: annotations: config.kubernetes.io/path: 'foo/bar.yaml' `, - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -578,7 +578,7 @@ metadata: { name: "scope_resources_by_directory_resources_missing_path", run: testRun{ - expectedInput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedInput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -597,7 +597,7 @@ functionConfig: annotations: config.kubernetes.io/path: 'foo/bar.yaml' `, - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -666,7 +666,7 @@ metadata: name: "scope_resources_global", instance: FunctionFilter{GlobalScope: true}, run: testRun{ - expectedInput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedInput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -693,7 +693,7 @@ functionConfig: annotations: config.kubernetes.io/path: 'foo/bar.yaml' `, - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -770,7 +770,7 @@ metadata: { name: "scope_no_resources", run: testRun{ - expectedInput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedInput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: [] functionConfig: @@ -781,7 +781,7 @@ functionConfig: annotations: config.kubernetes.io/path: 'foo/bar.yaml' `, - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: [] functionConfig: @@ -840,7 +840,7 @@ metadata: { name: "scope_functions_dir", run: testRun{ - expectedInput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedInput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -859,7 +859,7 @@ functionConfig: annotations: config.kubernetes.io/path: 'foo/functions/bar.yaml' `, - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: v1 @@ -931,7 +931,7 @@ metadata: { name: "copy_comments", run: testRun{ - expectedInput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedInput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 @@ -959,7 +959,7 @@ functionConfig: config.kubernetes.io/path: 'foo/f.yaml' `, // delete the comment - output: `apiVersion: config.kubernetes.io/v1alpha1 + output: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - apiVersion: apps/v1 diff --git a/kyaml/kio/byteio_reader.go b/kyaml/kio/byteio_reader.go index fd0c45c6a24..65a46d8228c 100644 --- a/kyaml/kio/byteio_reader.go +++ b/kyaml/kio/byteio_reader.go @@ -18,7 +18,7 @@ import ( const ( ResourceListKind = "ResourceList" - ResourceListAPIVersion = "config.kubernetes.io/v1alpha1" + ResourceListAPIVersion = "config.kubernetes.io/v1" ) // ByteReadWriter reads from an input and writes to an output. diff --git a/kyaml/kio/byteio_reader_test.go b/kyaml/kio/byteio_reader_test.go index 83358c06392..79734ce765b 100644 --- a/kyaml/kio/byteio_reader_test.go +++ b/kyaml/kio/byteio_reader_test.go @@ -33,7 +33,7 @@ func TestByteReader(t *testing.T) { // { name: "wrapped_resource_list", - input: `apiVersion: config.kubernetes.io/v1alpha1 + input: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -64,7 +64,7 @@ spec: // { name: "wrapped_resource_list_function_config", - input: `apiVersion: config.kubernetes.io/v1alpha1 + input: `apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: foo: bar @@ -105,7 +105,7 @@ elems: // { name: "wrapped_resource_list_function_config_without_items", - input: `apiVersion: config.kubernetes.io/v1alpha1 + input: `apiVersion: config.kubernetes.io/v1 kind: ResourceList functionConfig: foo: bar diff --git a/kyaml/kio/byteio_readwriter_test.go b/kyaml/kio/byteio_readwriter_test.go index 1d9cb11b4b9..ce0c4e5c665 100644 --- a/kyaml/kio/byteio_readwriter_test.go +++ b/kyaml/kio/byteio_readwriter_test.go @@ -26,7 +26,7 @@ func TestByteReadWriter(t *testing.T) { { name: "round_trip", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -38,7 +38,7 @@ items: foo: bar `, expectedOutput: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -54,7 +54,7 @@ items: { name: "function_config", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -68,7 +68,7 @@ functionConfig: a: b # something `, expectedOutput: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -86,7 +86,7 @@ functionConfig: { name: "results", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -100,7 +100,7 @@ results: a: b # something `, expectedOutput: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -118,7 +118,7 @@ results: { name: "drop_invalid_resource_list_field", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -132,7 +132,7 @@ foo: a: b # something `, expectedOutput: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -233,7 +233,7 @@ metadata: { name: "manual_override_wrap", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -262,7 +262,7 @@ spec: { name: "manual_override_function_config", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -276,7 +276,7 @@ functionConfig: a: b # something `, expectedOutput: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment @@ -499,7 +499,7 @@ env: { name: "unwrap ResourceList with annotations", input: ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - kind: Deployment diff --git a/kyaml/kio/byteio_writer_test.go b/kyaml/kio/byteio_writer_test.go index 60bebf7165a..835ed20cb41 100644 --- a/kyaml/kio/byteio_writer_test.go +++ b/kyaml/kio/byteio_writer_test.go @@ -45,7 +45,7 @@ g: h: - i # has a list - j`, - expectedOutput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedOutput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - a: b #first @@ -477,7 +477,7 @@ metadata: }`, }, - expectedOutput: `apiVersion: config.kubernetes.io/v1alpha1 + expectedOutput: `apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - {"a": "b", "metadata": {"annotations": {"internal.config.kubernetes.io/path": "test.json"}}} diff --git a/kyaml/kio/kio_test.go b/kyaml/kio/kio_test.go index 60027108eba..8fccf4b07fb 100644 --- a/kyaml/kio/kio_test.go +++ b/kyaml/kio/kio_test.go @@ -97,7 +97,7 @@ func TestEmptyInput(t *testing.T) { } expected := ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: [] ` @@ -138,7 +138,7 @@ func TestEmptyInputWithFilter(t *testing.T) { } expected := ` -apiVersion: config.kubernetes.io/v1alpha1 +apiVersion: config.kubernetes.io/v1 kind: ResourceList items: - foo: bar From b4a69f08c0cd63d0865e037d72f6d84d9116ef74 Mon Sep 17 00:00:00 2001 From: natasha41575 Date: Wed, 20 Oct 2021 11:43:52 -0700 Subject: [PATCH 2/2] provide utility helpers for preserving internal annotations --- api/resource/resource.go | 1 + cmd/config/internal/commands/cat.go | 1 + cmd/config/internal/commands/sink.go | 1 + kyaml/kio/kioutil/kioutil.go | 102 ++++++++++- kyaml/kio/kioutil/kioutil_test.go | 250 +++++++++++++++++++++++++++ 5 files changed, 348 insertions(+), 7 deletions(-) diff --git a/api/resource/resource.go b/api/resource/resource.go index 9e1e753fbbb..4985f725568 100644 --- a/api/resource/resource.go +++ b/api/resource/resource.go @@ -26,6 +26,7 @@ type Resource struct { refVarNames []string } +// nolint var BuildAnnotations = []string{ utils.BuildAnnotationPreviousKinds, utils.BuildAnnotationPreviousNames, diff --git a/cmd/config/internal/commands/cat.go b/cmd/config/internal/commands/cat.go index 62e8f3d968f..53ccdc906e8 100644 --- a/cmd/config/internal/commands/cat.go +++ b/cmd/config/internal/commands/cat.go @@ -166,6 +166,7 @@ func (r *CatRunner) catFilters() []kio.Filter { return fltrs } +// nolint func (r *CatRunner) out(w io.Writer) ([]kio.Writer, error) { var outputs []kio.Writer var functionConfig *yaml.RNode diff --git a/cmd/config/internal/commands/sink.go b/cmd/config/internal/commands/sink.go index 653c0530227..3efd381de83 100644 --- a/cmd/config/internal/commands/sink.go +++ b/cmd/config/internal/commands/sink.go @@ -46,6 +46,7 @@ See discussion in https://github.com/kubernetes-sigs/kustomize/issues/3953.`) return err } +// nolint func (r *SinkRunner) runE(c *cobra.Command, args []string) error { var outputs []kio.Writer if len(args) == 1 { diff --git a/kyaml/kio/kioutil/kioutil.go b/kyaml/kio/kioutil/kioutil.go index bfe2e9334c3..12cf85b11ee 100644 --- a/kyaml/kio/kioutil/kioutil.go +++ b/kyaml/kio/kioutil/kioutil.go @@ -17,25 +17,29 @@ import ( type AnnotationKey = string const ( + // internalPrefix is the prefix given to internal annotations that are used + // internally by the orchestrator + internalPrefix string = "internal.config.kubernetes.io/" + // IndexAnnotation records the index of a specific resource in a file or input stream. - IndexAnnotation AnnotationKey = "internal.config.kubernetes.io/index" + IndexAnnotation AnnotationKey = internalPrefix + "index" // PathAnnotation records the path to the file the Resource was read from - PathAnnotation AnnotationKey = "internal.config.kubernetes.io/path" + PathAnnotation AnnotationKey = internalPrefix + "path" // SeqIndentAnnotation records the sequence nodes indentation of the input resource - SeqIndentAnnotation AnnotationKey = "internal.config.kubernetes.io/seqindent" + SeqIndentAnnotation AnnotationKey = internalPrefix + "seqindent" // IdAnnotation records the id of the resource to map inputs to outputs - IdAnnotation = "internal.config.kubernetes.io/id" + IdAnnotation AnnotationKey = internalPrefix + "id" - // LegacyIndexAnnotation is the deprecated annotation key for resource index + // Deprecated: Use IndexAnnotation instead. LegacyIndexAnnotation AnnotationKey = "config.kubernetes.io/index" - // LegacyPathAnnotation is the deprecated annotation key for resource path + // Deprecated: use PathAnnotation instead. LegacyPathAnnotation AnnotationKey = "config.kubernetes.io/path" - // LegacyIdAnnotation is the deprecated annotation key for resource ids + // Deprecated: use IdAnnotation instead. LegacyIdAnnotation = "config.k8s.io/id" ) @@ -311,3 +315,87 @@ func SortNodes(nodes []*yaml.RNode) error { }) return errors.Wrap(err) } + +// CopyInternalAnnotations copies the annotations that begin with the prefix +// `internal.config.kubernetes.io` from the source RNode to the destination RNode. +// It takes a parameter exclusions, which is a list of annotation keys to ignore. +func CopyInternalAnnotations(src *yaml.RNode, dst *yaml.RNode, exclusions ...AnnotationKey) error { + srcAnnotations := GetInternalAnnotations(src) + for k, v := range srcAnnotations { + if stringSliceContains(exclusions, k) { + continue + } + if err := dst.PipeE(yaml.SetAnnotation(k, v)); err != nil { + return err + } + } + return nil +} + +// ConfirmInternalAnnotationUnchanged compares the annotations of the RNodes that begin with the prefix +// `internal.config.kubernetes.io`, throwing an error if they differ. It takes a parameter exclusions, +// which is a list of annotation keys to ignore. +func ConfirmInternalAnnotationUnchanged(r1 *yaml.RNode, r2 *yaml.RNode, exclusions ...AnnotationKey) error { + r1Annotations := GetInternalAnnotations(r1) + r2Annotations := GetInternalAnnotations(r2) + + // this is a map to prevent duplicates + diffAnnos := make(map[string]bool) + + for k, v1 := range r1Annotations { + if stringSliceContains(exclusions, k) { + continue + } + if v2, ok := r2Annotations[k]; !ok || v1 != v2 { + diffAnnos[k] = true + } + } + + for k, v2 := range r2Annotations { + if stringSliceContains(exclusions, k) { + continue + } + if v1, ok := r1Annotations[k]; !ok || v2 != v1 { + diffAnnos[k] = true + } + } + + if len(diffAnnos) > 0 { + keys := make([]string, 0, len(diffAnnos)) + for k := range diffAnnos { + keys = append(keys, k) + } + sort.Strings(keys) + + errorString := "internal annotations differ: " + for _, key := range keys { + errorString = errorString + key + ", " + } + return errors.Errorf(errorString[0 : len(errorString)-2]) + } + + return nil +} + +// GetInternalAnnotations returns a map of all the annotations of the provided RNode that begin +// with the prefix `internal.config.kubernetes.io` +func GetInternalAnnotations(rn *yaml.RNode) map[string]string { + annotations := rn.GetAnnotations() + result := make(map[string]string) + for k, v := range annotations { + if strings.HasPrefix(k, internalPrefix) { + result[k] = v + } + } + return result +} + +// stringSliceContains returns true if the slice has the string. +func stringSliceContains(slice []string, str string) bool { + for _, s := range slice { + if s == str { + return true + } + } + return false +} diff --git a/kyaml/kio/kioutil/kioutil_test.go b/kyaml/kio/kioutil/kioutil_test.go index bf6c07b4eaa..3bbdea26a95 100644 --- a/kyaml/kio/kioutil/kioutil_test.go +++ b/kyaml/kio/kioutil/kioutil_test.go @@ -451,3 +451,253 @@ metadata: assert.Equal(t, tc.expected, nodes[0].MustString()) } } + +func TestCopyInternalAnnotations(t *testing.T) { + var tests = []struct { + input string + exclusions []kioutil.AnnotationKey + expected string + }{ + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: src + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' + internal.config.kubernetes.io/foo: 'bar' +--- +apiVersion: v1 +kind: Foo +metadata: + name: dst + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' +`, + expected: `apiVersion: v1 +kind: Foo +metadata: + name: dst + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' + internal.config.kubernetes.io/foo: 'bar' +`, + }, + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: src + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' + internal.config.kubernetes.io/foo: 'bar-src' +--- +apiVersion: v1 +kind: Foo +metadata: + name: dst + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' + internal.config.kubernetes.io/foo: 'bar-dst' +`, + exclusions: []kioutil.AnnotationKey{ + kioutil.PathAnnotation, + kioutil.IndexAnnotation, + }, + expected: `apiVersion: v1 +kind: Foo +metadata: + name: dst + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' + internal.config.kubernetes.io/foo: 'bar-src' +`, + }, + } + + for _, tc := range tests { + rw := kio.ByteReadWriter{ + Reader: bytes.NewBufferString(tc.input), + OmitReaderAnnotations: true, + } + nodes, err := rw.Read() + assert.NoError(t, err) + assert.NoError(t, kioutil.CopyInternalAnnotations(nodes[0], nodes[1], tc.exclusions...)) + assert.Equal(t, tc.expected, nodes[1].MustString()) + } +} + +func TestConfirmInternalAnnotationUnchanged(t *testing.T) { + var tests = []struct { + input string + exclusions []kioutil.AnnotationKey + expectedErr string + }{ + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: foo-1 + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' +--- +apiVersion: v1 +kind: Foo +metadata: + name: foo-2 + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' +`, + expectedErr: `internal annotations differ: internal.config.kubernetes.io/index, internal.config.kubernetes.io/path`, + }, + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: foo-1 + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' +--- +apiVersion: v1 +kind: Foo +metadata: + name: foo-2 + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' +`, + exclusions: []kioutil.AnnotationKey{ + kioutil.PathAnnotation, + kioutil.IndexAnnotation, + }, + expectedErr: ``, + }, + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: foo-1 + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' + internal.config.kubernetes.io/foo: 'bar-1' +--- +apiVersion: v1 +kind: Foo +metadata: + name: foo-2 + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' + internal.config.kubernetes.io/foo: 'bar-2' +`, + exclusions: []kioutil.AnnotationKey{ + kioutil.PathAnnotation, + kioutil.IndexAnnotation, + }, + expectedErr: `internal annotations differ: internal.config.kubernetes.io/foo`, + }, + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: foo-1 + annotations: + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' + internal.config.kubernetes.io/foo: 'bar-1' +--- +apiVersion: v1 +kind: Foo +metadata: + name: foo-2 + annotations: + internal.config.kubernetes.io/path: 'c/d.yaml' + internal.config.kubernetes.io/index: '10' + internal.config.kubernetes.io/foo: 'bar-1' +`, + expectedErr: `internal annotations differ: internal.config.kubernetes.io/index, internal.config.kubernetes.io/path`, + }, + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: foo-1 + annotations: + internal.config.kubernetes.io/a: 'b' + internal.config.kubernetes.io/c: 'd' +--- +apiVersion: v1 +kind: Foo +metadata: + name: foo-2 + annotations: + 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`, + }, + } + + for _, tc := range tests { + rw := kio.ByteReadWriter{ + Reader: bytes.NewBufferString(tc.input), + OmitReaderAnnotations: true, + } + nodes, err := rw.Read() + assert.NoError(t, err) + err = kioutil.ConfirmInternalAnnotationUnchanged(nodes[0], nodes[1], tc.exclusions...) + if tc.expectedErr == "" { + assert.NoError(t, err) + } else { + if err == nil { + t.Fatalf("expected error: %s\n", tc.expectedErr) + } + assert.Equal(t, tc.expectedErr, err.Error()) + } + } +} + +func TestGetInternalAnnotations(t *testing.T) { + var tests = []struct { + input string + expected map[string]string + }{ + { + input: `apiVersion: v1 +kind: Foo +metadata: + name: foobar + annotations: + foo: bar + internal.config.kubernetes.io/path: 'a/b.yaml' + internal.config.kubernetes.io/index: '5' + internal.config.kubernetes.io/foo: 'bar' +`, + expected: map[string]string{ + "internal.config.kubernetes.io/path": "a/b.yaml", + "internal.config.kubernetes.io/index": "5", + "internal.config.kubernetes.io/foo": "bar", + }, + }, + } + + for _, tc := range tests { + rw := kio.ByteReadWriter{ + Reader: bytes.NewBufferString(tc.input), + OmitReaderAnnotations: true, + } + nodes, err := rw.Read() + assert.NoError(t, err) + assert.Equal(t, tc.expected, kioutil.GetInternalAnnotations(nodes[0])) + } +}