From a5075b5287005657b8359de11e510f0d4b9cd9d8 Mon Sep 17 00:00:00 2001 From: Varsha Prasad Narsing Date: Mon, 13 Nov 2023 16:17:35 -0500 Subject: [PATCH] [Remove] References to legacy annotations --- api/resource/resource.go | 4 - cmd/config/internal/commands/cat.go | 2 +- kyaml/fn/runtime/runtimeutil/runtimeutil.go | 31 +- kyaml/fn/runtime/starlark/example_test.go | 4 - kyaml/inpututil/inpututil.go | 6 - kyaml/kio/byteio_reader.go | 5 - kyaml/kio/byteio_reader_test.go | 8 +- kyaml/kio/byteio_readwriter_test.go | 2 - kyaml/kio/byteio_writer.go | 5 - kyaml/kio/byteio_writer_test.go | 8 - kyaml/kio/filters/filters.go | 10 - kyaml/kio/filters/merge3.go | 6 - kyaml/kio/kio.go | 174 +-------- kyaml/kio/kio_test.go | 410 +------------------- kyaml/kio/kioutil/kioutil.go | 70 +--- kyaml/kio/kioutil/kioutil_test.go | 92 ----- kyaml/kio/pkgio_reader.go | 1 - kyaml/kio/pkgio_reader_test.go | 56 --- kyaml/kio/pkgio_writer.go | 1 - kyaml/kio/pkgio_writer_test.go | 6 - kyaml/kio/tree.go | 5 - kyaml/runfn/runfn.go | 9 - 22 files changed, 34 insertions(+), 881 deletions(-) diff --git a/api/resource/resource.go b/api/resource/resource.go index ae1a98be0e..0bb5bc5b15 100644 --- a/api/resource/resource.go +++ b/api/resource/resource.go @@ -43,10 +43,6 @@ var BuildAnnotations = []string{ kioutil.SeqIndentAnnotation, kioutil.IdAnnotation, kioutil.InternalAnnotationsMigrationResourceIDAnnotation, - - kioutil.LegacyPathAnnotation, - kioutil.LegacyIndexAnnotation, - kioutil.LegacyIdAnnotation, } func (r *Resource) ResetRNode(incoming *Resource) { diff --git a/cmd/config/internal/commands/cat.go b/cmd/config/internal/commands/cat.go index 62e8f3d968..1280b3122e 100644 --- a/cmd/config/internal/commands/cat.go +++ b/cmd/config/internal/commands/cat.go @@ -183,7 +183,7 @@ func (r *CatRunner) out(w io.Writer) ([]kio.Writer, error) { // remove this annotation explicitly, the ByteWriter won't clear it by // default because it doesn't set it - clear := []string{kioutil.LegacyPathAnnotation, kioutil.PathAnnotation} + clear := []string{kioutil.PathAnnotation} if r.KeepAnnotations { clear = nil } diff --git a/kyaml/fn/runtime/runtimeutil/runtimeutil.go b/kyaml/fn/runtime/runtimeutil/runtimeutil.go index 6a06b81c39..33b05ce672 100644 --- a/kyaml/fn/runtime/runtimeutil/runtimeutil.go +++ b/kyaml/fn/runtime/runtimeutil/runtimeutil.go @@ -70,10 +70,7 @@ func (c *FunctionFilter) getFunctionScope() (string, error) { var found bool p, found = m.Annotations[kioutil.PathAnnotation] if !found { - p, found = m.Annotations[kioutil.LegacyPathAnnotation] - if !found { - return "", nil - } + return "", nil } functionDir := path.Clean(path.Dir(p)) @@ -110,13 +107,10 @@ func (c *FunctionFilter) scope(dir string, nodes []*yaml.RNode) ([]*yaml.RNode, var found bool p, found = m.Annotations[kioutil.PathAnnotation] if !found { - p, found = m.Annotations[kioutil.LegacyPathAnnotation] - if !found { - // this Resource isn't scoped under the function -- don't know where it came from - // consider it out of scope - saved = append(saved, nodes[i]) - continue - } + // this Resource isn't scoped under the function -- don't know where it came from + // consider it out of scope + saved = append(saved, nodes[i]) + continue } resourceDir := path.Clean(path.Dir(p)) @@ -214,10 +208,6 @@ func (c *FunctionFilter) setIds(nodes []*yaml.RNode) error { if err != nil { return errors.Wrap(err) } - err = nodes[i].PipeE(yaml.SetAnnotation(kioutil.LegacyIdAnnotation, idStr)) - if err != nil { - return errors.Wrap(err) - } c.ids[idStr] = nodes[i] } return nil @@ -231,13 +221,7 @@ func (c *FunctionFilter) copyCommentsAndSyncOrder(nodes []*yaml.RNode) error { return errors.Wrap(err) } if anID == nil { - anID, err = node.Pipe(yaml.GetAnnotation(kioutil.LegacyIdAnnotation)) - if err != nil { - return errors.Wrap(err) - } - if anID == nil { - continue - } + continue } var in *yaml.RNode @@ -254,9 +238,6 @@ func (c *FunctionFilter) copyCommentsAndSyncOrder(nodes []*yaml.RNode) error { if err := node.PipeE(yaml.ClearAnnotation(kioutil.IdAnnotation)); err != nil { return errors.Wrap(err) } - if err := node.PipeE(yaml.ClearAnnotation(kioutil.LegacyIdAnnotation)); err != nil { - return errors.Wrap(err) - } } return nil } diff --git a/kyaml/fn/runtime/starlark/example_test.go b/kyaml/fn/runtime/starlark/example_test.go index 5dc979c58e..3c2b7d4423 100644 --- a/kyaml/fn/runtime/starlark/example_test.go +++ b/kyaml/fn/runtime/starlark/example_test.go @@ -77,7 +77,6 @@ run(ctx.resource_list["items"]) // annotations: // foo: bar // internal.config.kubernetes.io/path: 'deployment_deployment-1.yaml' - // config.kubernetes.io/path: 'deployment_deployment-1.yaml' // spec: // template: // spec: @@ -92,7 +91,6 @@ run(ctx.resource_list["items"]) // annotations: // foo: bar // internal.config.kubernetes.io/path: 'deployment_deployment-2.yaml' - // config.kubernetes.io/path: 'deployment_deployment-2.yaml' // spec: // template: // spec: @@ -186,7 +184,6 @@ run(ctx.resource_list["items"], ctx.resource_list["functionConfig"]["spec"]["val // annotations: // foo: hello world // internal.config.kubernetes.io/path: 'deployment_deployment-2.yaml' - // config.kubernetes.io/path: 'deployment_deployment-2.yaml' // spec: // template: // spec: @@ -264,7 +261,6 @@ run(ctx.resource_list["items"]) Writer: output, ClearAnnotations: []string{ kioutil.PathAnnotation, - kioutil.LegacyPathAnnotation, }, }}}.Execute() if err != nil { diff --git a/kyaml/inpututil/inpututil.go b/kyaml/inpututil/inpututil.go index be7d497f0a..b3636132ff 100644 --- a/kyaml/inpututil/inpututil.go +++ b/kyaml/inpututil/inpututil.go @@ -53,12 +53,6 @@ func WrapErrorWithFile(err error, meta yaml.ResourceMeta) error { } path := meta.Annotations[kioutil.PathAnnotation] index := meta.Annotations[kioutil.IndexAnnotation] - if path == "" { - path = meta.Annotations[kioutil.LegacyPathAnnotation] - } - if index == "" { - index = meta.Annotations[kioutil.LegacyPathAnnotation] - } return errors.WrapPrefixf(err, "%s [%s]", meta.Annotations[path], meta.Annotations[index]) diff --git a/kyaml/kio/byteio_reader.go b/kyaml/kio/byteio_reader.go index 230ab891bb..831cd595ba 100644 --- a/kyaml/kio/byteio_reader.go +++ b/kyaml/kio/byteio_reader.go @@ -319,12 +319,7 @@ func (r *ByteReader) decode(originalYAML string, index int, decoder *yaml.Decode r.SetAnnotations = map[string]string{} } if !r.OmitReaderAnnotations { - err := kioutil.CopyLegacyAnnotations(n) - if err != nil { - return nil, err - } r.SetAnnotations[kioutil.IndexAnnotation] = fmt.Sprintf("%d", index) - r.SetAnnotations[kioutil.LegacyIndexAnnotation] = fmt.Sprintf("%d", index) if r.PreserveSeqIndent { // derive and add the seqindent annotation diff --git a/kyaml/kio/byteio_reader_test.go b/kyaml/kio/byteio_reader_test.go index 9bd2b58b07..57fae54847 100644 --- a/kyaml/kio/byteio_reader_test.go +++ b/kyaml/kio/byteio_reader_test.go @@ -181,7 +181,6 @@ i: j c: d metadata: annotations: - config.kubernetes.io/index: '0' internal.config.kubernetes.io/index: '0' `, `# second resource @@ -190,13 +189,11 @@ g: - h metadata: annotations: - config.kubernetes.io/index: '1' internal.config.kubernetes.io/index: '1' `, `i: j metadata: annotations: - config.kubernetes.io/index: '2' internal.config.kubernetes.io/index: '2' `, }, @@ -262,7 +259,6 @@ a: b # first resource c: d metadata: annotations: - config.kubernetes.io/index: '0' internal.config.kubernetes.io/index: '0' `, ` @@ -272,14 +268,12 @@ g: - h metadata: annotations: - config.kubernetes.io/index: '1' internal.config.kubernetes.io/index: '1' `, ` i: j metadata: annotations: - config.kubernetes.io/index: '2' internal.config.kubernetes.io/index: '2' `, }, @@ -375,7 +369,7 @@ metadata: `, expectedItems: []string{ ` -{"a": "b", "c": [1, 2], metadata: {annotations: {config.kubernetes.io/index: '0', internal.config.kubernetes.io/index: '0'}}} +{"a": "b", "c": [1, 2], metadata: {annotations: {internal.config.kubernetes.io/index: '0'}}} `, }, instance: ByteReader{}, diff --git a/kyaml/kio/byteio_readwriter_test.go b/kyaml/kio/byteio_readwriter_test.go index 9a70570b02..f7ed3c6813 100644 --- a/kyaml/kio/byteio_readwriter_test.go +++ b/kyaml/kio/byteio_readwriter_test.go @@ -215,7 +215,6 @@ spec: replicas: 1 metadata: annotations: - config.kubernetes.io/index: '0' internal.config.kubernetes.io/index: '0' --- kind: Service @@ -224,7 +223,6 @@ spec: foo: bar metadata: annotations: - config.kubernetes.io/index: '1' internal.config.kubernetes.io/index: '1' `, instance: kio.ByteReadWriter{KeepReaderAnnotations: true}, diff --git a/kyaml/kio/byteio_writer.go b/kyaml/kio/byteio_writer.go index ec4cafe303..db73128af5 100644 --- a/kyaml/kio/byteio_writer.go +++ b/kyaml/kio/byteio_writer.go @@ -76,11 +76,6 @@ func (w ByteWriter) Write(inputNodes []*yaml.RNode) error { if err != nil { return errors.Wrap(err) } - _, err = nodes[i].Pipe(yaml.ClearAnnotation(kioutil.LegacyIndexAnnotation)) - if err != nil { - return errors.Wrap(err) - } - _, err = nodes[i].Pipe(yaml.ClearAnnotation(kioutil.SeqIndentAnnotation)) if err != nil { return errors.Wrap(err) diff --git a/kyaml/kio/byteio_writer_test.go b/kyaml/kio/byteio_writer_test.go index 4897287b04..d1108e0f29 100644 --- a/kyaml/kio/byteio_writer_test.go +++ b/kyaml/kio/byteio_writer_test.go @@ -248,16 +248,12 @@ metadata: annotations: internal.config.kubernetes.io/index: 0 internal.config.kubernetes.io/path: "a/b/a_test.yaml" - config.kubernetes.io/path: 'a/b/a_test.yaml' - config.kubernetes.io/index: '0' --- c: d # second metadata: annotations: internal.config.kubernetes.io/index: 1 internal.config.kubernetes.io/path: "a/b/a_test.yaml" - config.kubernetes.io/path: 'a/b/a_test.yaml' - config.kubernetes.io/index: '1' --- e: f g: @@ -268,8 +264,6 @@ metadata: annotations: internal.config.kubernetes.io/index: 0 internal.config.kubernetes.io/path: "a/b/b_test.yaml" - config.kubernetes.io/path: 'a/b/b_test.yaml' - config.kubernetes.io/index: '0' `, }, @@ -309,13 +303,11 @@ a: b #first metadata: annotations: internal.config.kubernetes.io/path: "a/b/a_test.yaml" - config.kubernetes.io/path: 'a/b/a_test.yaml' --- c: d # second metadata: annotations: internal.config.kubernetes.io/path: "a/b/a_test.yaml" - config.kubernetes.io/path: 'a/b/a_test.yaml' `, }, diff --git a/kyaml/kio/filters/filters.go b/kyaml/kio/filters/filters.go index 8d7968b3c6..ccabf02810 100644 --- a/kyaml/kio/filters/filters.go +++ b/kyaml/kio/filters/filters.go @@ -165,9 +165,6 @@ func (f *FileSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) { resources := map[string][]*yaml.RNode{} for i := range input { - if err := kioutil.CopyLegacyAnnotations(input[i]); err != nil { - return nil, err - } m, err := input[i].GetMeta() if err != nil { @@ -182,9 +179,6 @@ func (f *FileSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) { if _, err := input[i].Pipe(yaml.SetAnnotation(kioutil.PathAnnotation, file)); err != nil { return nil, err } - if _, err := input[i].Pipe(yaml.SetAnnotation(kioutil.LegacyPathAnnotation, file)); err != nil { - return nil, err - } } resources[file] = append(resources[file], input[i]) } @@ -199,10 +193,6 @@ func (f *FileSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) { yaml.SetAnnotation(kioutil.IndexAnnotation, fmt.Sprintf("%d", j))); err != nil { return nil, err } - if _, err := resources[i][j].Pipe( - yaml.SetAnnotation(kioutil.LegacyIndexAnnotation, fmt.Sprintf("%d", j))); err != nil { - return nil, err - } output = append(output, resources[i][j]) } } diff --git a/kyaml/kio/filters/merge3.go b/kyaml/kio/filters/merge3.go index de8bf6f67a..26ff863017 100644 --- a/kyaml/kio/filters/merge3.go +++ b/kyaml/kio/filters/merge3.go @@ -173,12 +173,6 @@ func (dm *DefaultGVKNNMatcher) IsSameResource(node1, node2 *yaml.RNode) bool { if node1 == nil || node2 == nil { return false } - if err := kioutil.CopyLegacyAnnotations(node1); err != nil { - return false - } - if err := kioutil.CopyLegacyAnnotations(node2); err != nil { - return false - } meta1, err := node1.GetMeta() if err != nil { diff --git a/kyaml/kio/kio.go b/kyaml/kio/kio.go index 9e00509ebe..a76cd2a598 100644 --- a/kyaml/kio/kio.go +++ b/kyaml/kio/kio.go @@ -186,40 +186,10 @@ func PreprocessResourcesForInternalAnnotationMigration(result []*yaml.RNode) (ma return nil, err } idToAnnosMap[idStr] = kioutil.GetInternalAnnotations(result[i]) - if err = kioutil.CopyLegacyAnnotations(result[i]); err != nil { - return nil, err - } - meta, _ := result[i].GetMeta() - if err = checkMismatchedAnnos(meta.Annotations); err != nil { - return nil, err - } } return idToAnnosMap, nil } -func checkMismatchedAnnos(annotations map[string]string) error { - path := annotations[kioutil.PathAnnotation] - index := annotations[kioutil.IndexAnnotation] - id := annotations[kioutil.IdAnnotation] - - legacyPath := annotations[kioutil.LegacyPathAnnotation] - legacyIndex := annotations[kioutil.LegacyIndexAnnotation] - legacyId := annotations[kioutil.LegacyIdAnnotation] - - // if prior to running the functions, the legacy and internal annotations differ, - // throw an error as we cannot infer the user's intent. - if path != "" && legacyPath != "" && path != legacyPath { - return fmt.Errorf("resource input to function has mismatched legacy and internal path annotations") - } - if index != "" && legacyIndex != "" && index != legacyIndex { - return fmt.Errorf("resource input to function has mismatched legacy and internal index annotations") - } - if id != "" && legacyId != "" && id != legacyId { - return fmt.Errorf("resource input to function has mismatched legacy and internal id annotations") - } - return nil -} - type nodeAnnotations struct { path string index string @@ -230,19 +200,14 @@ type nodeAnnotations struct { // It will ensure the output annotation format matches the format in the input. e.g. if the input // format uses the legacy format and the output will be converted to the legacy format if it's not. func ReconcileInternalAnnotations(result []*yaml.RNode, nodeAnnosMap map[string]map[string]string) error { - useInternal, useLegacy, err := determineAnnotationsFormat(nodeAnnosMap) + useInternal, err := determineAnnotationsFormat(nodeAnnosMap) if err != nil { return err } for i := range result { - // if only one annotation is set, set the other. - err = missingInternalOrLegacyAnnotations(result[i]) - if err != nil { - return err - } - // we must check to see if the function changed either the new internal annotations - // or the old legacy annotations. If one is changed, the change must be reflected + // we must check to see if the function changed the new internal annotations + // If one is changed, the change must be reflected // in the other. err = checkAnnotationsAltered(result[i], nodeAnnosMap) if err != nil { @@ -251,17 +216,10 @@ func ReconcileInternalAnnotations(result []*yaml.RNode, nodeAnnosMap map[string] // We invoke determineAnnotationsFormat to find out if the original annotations // use the internal or (and) the legacy format. We format the resources to // make them consistent with original format. - err = formatInternalAnnotations(result[i], useInternal, useLegacy) - if err != nil { - return err - } - // if the annotations are still somehow out of sync, throw an error - meta, _ := result[i].GetMeta() - err = checkMismatchedAnnos(meta.Annotations) + err = formatInternalAnnotations(result[i], useInternal) if err != nil { return err } - if _, err = result[i].Pipe(yaml.ClearAnnotation(kioutil.InternalAnnotationsMigrationResourceIDAnnotation)); err != nil { return err } @@ -269,25 +227,22 @@ func ReconcileInternalAnnotations(result []*yaml.RNode, nodeAnnosMap map[string] return nil } -// 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) (bool, bool, error) { - var useInternal, useLegacy bool +// determineAnnotationsFormat determines if the resources are using internal annotations. +func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (bool, error) { + var useInternal bool var err error if len(nodeAnnosMap) == 0 { - return true, true, nil + return true, nil } - var internal, legacy *bool + var internal *bool for _, annos := range nodeAnnosMap { _, foundPath := annos[kioutil.PathAnnotation] _, foundIndex := annos[kioutil.IndexAnnotation] _, foundId := annos[kioutil.IdAnnotation] - _, foundLegacyPath := annos[kioutil.LegacyPathAnnotation] - _, foundLegacyIndex := annos[kioutil.LegacyIndexAnnotation] - _, foundLegacyId := annos[kioutil.LegacyIdAnnotation] - if !(foundPath || foundIndex || foundId || foundLegacyPath || foundLegacyIndex || foundLegacyId) { + if !(foundPath || foundIndex || foundId ) { continue } @@ -298,64 +253,13 @@ func determineAnnotationsFormat(nodeAnnosMap map[string]map[string]string) (bool } if (foundOneOf && !*internal) || (!foundOneOf && *internal) { err = fmt.Errorf("the annotation formatting in the input resources is not consistent") - return useInternal, useLegacy, err - } - - foundOneOf = foundLegacyPath || foundLegacyIndex || foundLegacyId - if legacy == nil { - f := foundOneOf - legacy = &f - } - if (foundOneOf && !*legacy) || (!foundOneOf && *legacy) { - err = fmt.Errorf("the annotation formatting in the input resources is not consistent") - return useInternal, useLegacy, err + return useInternal, err } } if internal != nil { useInternal = *internal } - if legacy != nil { - useLegacy = *legacy - } - return useInternal, useLegacy, err -} - -func missingInternalOrLegacyAnnotations(rn *yaml.RNode) error { - if err := missingInternalOrLegacyAnnotation(rn, kioutil.PathAnnotation, kioutil.LegacyPathAnnotation); err != nil { - return err - } - if err := missingInternalOrLegacyAnnotation(rn, kioutil.IndexAnnotation, kioutil.LegacyIndexAnnotation); err != nil { - return err - } - if err := missingInternalOrLegacyAnnotation(rn, kioutil.IdAnnotation, kioutil.LegacyIdAnnotation); err != nil { - return err - } - return nil -} - -func missingInternalOrLegacyAnnotation(rn *yaml.RNode, newKey string, legacyKey string) error { - meta, _ := rn.GetMeta() - annotations := meta.Annotations - value := annotations[newKey] - legacyValue := annotations[legacyKey] - - if value == "" && legacyValue == "" { - // do nothing - return nil - } - - if value == "" { - // new key is not set, copy from legacy key - if err := rn.PipeE(yaml.SetAnnotation(newKey, legacyValue)); err != nil { - return err - } - } else if legacyValue == "" { - // legacy key is not set, copy from new key - if err := rn.PipeE(yaml.SetAnnotation(legacyKey, value)); err != nil { - return err - } - } - return nil + return useInternal, err } func checkAnnotationsAltered(rn *yaml.RNode, nodeAnnosMap map[string]map[string]string) error { @@ -368,59 +272,34 @@ func checkAnnotationsAltered(rn *yaml.RNode, nodeAnnosMap map[string]map[string] id: annotations[kioutil.IdAnnotation], } - // get the resource's current path, index, and ids from the legacy annotations - legacy := nodeAnnotations{ - path: annotations[kioutil.LegacyPathAnnotation], - index: annotations[kioutil.LegacyIndexAnnotation], - id: annotations[kioutil.LegacyIdAnnotation], - } - rid := annotations[kioutil.InternalAnnotationsMigrationResourceIDAnnotation] originalAnnotations, found := nodeAnnosMap[rid] if !found { return nil } originalPath, found := originalAnnotations[kioutil.PathAnnotation] - if !found { - originalPath = originalAnnotations[kioutil.LegacyPathAnnotation] - } - if originalPath != "" { - 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") - case originalPath != internal.path: - if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.LegacyPathAnnotation, internal.path)); err != nil { - return err - } - case originalPath != legacy.path: - if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.PathAnnotation, legacy.path)); err != nil { + + if found && originalPath != "" { + if originalPath != internal.path{ + if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.PathAnnotation, internal.path)); err != nil { return err } } } originalIndex, found := originalAnnotations[kioutil.IndexAnnotation] - if !found { - originalIndex = originalAnnotations[kioutil.LegacyIndexAnnotation] - } - if originalIndex != "" { - 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") - case originalIndex != internal.index: - if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.LegacyIndexAnnotation, internal.index)); err != nil { - return err - } - case originalIndex != legacy.index: - if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.IndexAnnotation, legacy.index)); err != nil { + if found && originalIndex != "" { + if originalIndex != internal.index{ + if _, err := rn.Pipe(yaml.SetAnnotation(kioutil.IndexAnnotation, internal.index)); err != nil { return err } } } + return nil } -func formatInternalAnnotations(rn *yaml.RNode, useInternal, useLegacy bool) error { +func formatInternalAnnotations(rn *yaml.RNode, useInternal bool) error { if !useInternal { if err := rn.PipeE(yaml.ClearAnnotation(kioutil.IdAnnotation)); err != nil { return err @@ -432,16 +311,5 @@ func formatInternalAnnotations(rn *yaml.RNode, useInternal, useLegacy bool) erro return err } } - if !useLegacy { - if err := rn.PipeE(yaml.ClearAnnotation(kioutil.LegacyIdAnnotation)); err != nil { - return err - } - if err := rn.PipeE(yaml.ClearAnnotation(kioutil.LegacyPathAnnotation)); err != nil { - return err - } - if err := rn.PipeE(yaml.ClearAnnotation(kioutil.LegacyIndexAnnotation)); err != nil { - return err - } - } return nil } diff --git a/kyaml/kio/kio_test.go b/kyaml/kio/kio_test.go index fb399ad98f..46cd647c4b 100644 --- a/kyaml/kio/kio_test.go +++ b/kyaml/kio/kio_test.go @@ -204,48 +204,21 @@ func TestLegacyAnnotationReconciliation(t *testing.T) { } return nodes, nil } - changeLegacyAnnos := func(nodes []*yaml.RNode) ([]*yaml.RNode, error) { - for _, rn := range nodes { - if err := rn.PipeE(yaml.SetAnnotation(kioutil.LegacyPathAnnotation, "new")); err != nil { - return nil, err - } - if err := rn.PipeE(yaml.SetAnnotation(kioutil.LegacyIndexAnnotation, "new")); err != nil { - return nil, err - } - } - return nodes, nil - } changeBothPathAnnosMatch := func(nodes []*yaml.RNode) ([]*yaml.RNode, error) { for _, rn := range nodes { - if err := rn.PipeE(yaml.SetAnnotation(kioutil.LegacyPathAnnotation, "new")); err != nil { - return nil, err - } if err := rn.PipeE(yaml.SetAnnotation(kioutil.PathAnnotation, "new")); err != nil { return nil, err } } return nodes, nil } - changeBothPathAnnosMismatch := func(nodes []*yaml.RNode) ([]*yaml.RNode, error) { - for _, rn := range nodes { - if err := rn.PipeE(yaml.SetAnnotation(kioutil.LegacyPathAnnotation, "foo")); err != nil { - return nil, err - } - if err := rn.PipeE(yaml.SetAnnotation(kioutil.PathAnnotation, "bar")); err != nil { - return nil, err - } - } - return nodes, nil - } noops := []Filter{ FilterFunc(noopFilter1), FilterFunc(noopFilter2), } internal := []Filter{FilterFunc(changeInternalAnnos)} - legacy := []Filter{FilterFunc(changeLegacyAnnos)} changeBothMatch := []Filter{FilterFunc(changeBothPathAnnosMatch), FilterFunc(noopFilter1)} - changeBothMismatch := []Filter{FilterFunc(changeBothPathAnnosMismatch), FilterFunc(noopFilter1)} testCases := map[string]struct { input string @@ -253,9 +226,8 @@ func TestLegacyAnnotationReconciliation(t *testing.T) { expected string expectedErr string }{ - // the orchestrator should copy the legacy annotations to the new - // annotations - "legacy annotations only": { + // the orchestrator should copy the annotations correctly + "new annotations only": { input: `apiVersion: v1 kind: ConfigMap metadata: @@ -296,96 +268,6 @@ metadata: config.kubernetes.io/index: '1' data: grpcPort: 8081 -`, - }, - // the orchestrator should copy the new annotations to the - // legacy annotations - "new annotations only": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - internal.config.kubernetes.io/path: 'configmap.yaml' - internal.config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: noops, - expected: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - internal.config.kubernetes.io/path: 'configmap.yaml' - internal.config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - }, - // the orchestrator should detect that the legacy annotations - // have been changed by the function - "change only legacy annotations": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'configmap.yaml' - config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: legacy, - expected: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'new' - config.kubernetes.io/index: 'new' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: 'new' -data: - grpcPort: 8081 `, }, // the orchestrator should detect that the new internal annotations @@ -431,149 +313,6 @@ metadata: internal.config.kubernetes.io/index: 'new' data: grpcPort: 8081 -`, - }, - // the orchestrator should detect that the legacy annotations - // have been changed by the function - "change only internal annotations while input is legacy annotations": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'configmap.yaml' - config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: internal, - expected: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'new' - config.kubernetes.io/index: 'new' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: 'new' -data: - grpcPort: 8081 -`, - }, - // the orchestrator should detect that the new internal annotations - // have been changed by the function - "change only legacy annotations while input is internal annotations": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - internal.config.kubernetes.io/path: 'configmap.yaml' - internal.config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: legacy, - expected: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - internal.config.kubernetes.io/path: 'new' - internal.config.kubernetes.io/index: 'new' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - internal.config.kubernetes.io/path: "new" - internal.config.kubernetes.io/index: 'new' -data: - grpcPort: 8081 -`, - }, - // the orchestrator should detect that the legacy annotations - // have been changed by the function - "change only legacy annotations while input has both": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'configmap.yaml' - config.kubernetes.io/index: '0' - internal.config.kubernetes.io/path: 'configmap.yaml' - internal.config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' - internal.config.kubernetes.io/path: 'configmap.yaml' - internal.config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: legacy, - expected: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'new' - config.kubernetes.io/index: 'new' - internal.config.kubernetes.io/path: 'new' - internal.config.kubernetes.io/index: 'new' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: 'new' - internal.config.kubernetes.io/path: 'new' - internal.config.kubernetes.io/index: 'new' -data: - grpcPort: 8081 `, }, // the orchestrator should detect that the new internal annotations @@ -584,8 +323,6 @@ kind: ConfigMap metadata: name: ports-from annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'configmap.yaml' internal.config.kubernetes.io/index: '0' data: @@ -596,8 +333,6 @@ kind: ConfigMap metadata: name: ports-to annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: "configmap.yaml" internal.config.kubernetes.io/index: '1' data: @@ -609,8 +344,6 @@ kind: ConfigMap metadata: name: ports-from annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: 'new' internal.config.kubernetes.io/path: 'new' internal.config.kubernetes.io/index: 'new' data: @@ -621,8 +354,6 @@ kind: ConfigMap metadata: name: ports-to annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: 'new' internal.config.kubernetes.io/path: "new" internal.config.kubernetes.io/index: 'new' data: @@ -637,8 +368,6 @@ kind: ConfigMap metadata: name: ports-from annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'configmap.yaml' internal.config.kubernetes.io/index: '0' data: @@ -649,8 +378,6 @@ kind: ConfigMap metadata: name: ports-to annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: "configmap.yaml" internal.config.kubernetes.io/index: '1' data: @@ -662,8 +389,6 @@ kind: ConfigMap metadata: name: ports-from annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'new' internal.config.kubernetes.io/index: '0' data: @@ -674,57 +399,10 @@ kind: ConfigMap metadata: name: ports-to annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: "new" internal.config.kubernetes.io/index: '1' data: grpcPort: 8081 -`, - }, - // the orchestrator should detect that the new internal annotations - // have been changed by the function - "change both to matching value while input is legacy": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: changeBothMatch, - expected: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "new" - config.kubernetes.io/index: '1' -data: - grpcPort: 8081 `, }, // the orchestrator should detect that the new internal annotations @@ -772,90 +450,6 @@ data: grpcPort: 8081 `, }, - // the function changes both the legacy and new path annotation, and they mismatch, - // so we should get an error - "change both but mismatch while input is legacy": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'configmap.yaml' - config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: changeBothMismatch, - expectedErr: "resource input to function has mismatched legacy and internal path annotations", - }, - // the function changes both the legacy and new path annotation, and they mismatch, - // so we should get an error - "change both but mismatch while input is internal": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: changeBothMismatch, - expectedErr: "resource input to function has mismatched legacy and internal path annotations", - }, - // the function changes both the legacy and new path annotation, and they mismatch, - // so we should get an error - "change both but mismatch while input has both": { - input: `apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-from - annotations: - config.kubernetes.io/path: 'configmap.yaml' - config.kubernetes.io/index: '0' - config.k8s.io/id: '1' - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '0' -data: - grpcPort: 8080 ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: ports-to - annotations: - config.kubernetes.io/path: "configmap.yaml" - config.kubernetes.io/index: '1' - config.k8s.io/id: '2' - internal.config.kubernetes.io/path: "configmap.yaml" - internal.config.kubernetes.io/index: '1' -data: - grpcPort: 8081 -`, - filters: changeBothMismatch, - expectedErr: "resource input to function has mismatched legacy and internal path annotations", - }, } for tn, tc := range testCases { diff --git a/kyaml/kio/kioutil/kioutil.go b/kyaml/kio/kioutil/kioutil.go index 510ecae18f..41316be322 100644 --- a/kyaml/kio/kioutil/kioutil.go +++ b/kyaml/kio/kioutil/kioutil.go @@ -33,15 +33,6 @@ const ( // IdAnnotation records the id of the resource to map inputs to outputs IdAnnotation AnnotationKey = internalPrefix + "id" - // Deprecated: Use IndexAnnotation instead. - LegacyIndexAnnotation AnnotationKey = "config.kubernetes.io/index" - - // Deprecated: use PathAnnotation instead. - LegacyPathAnnotation AnnotationKey = "config.kubernetes.io/path" - - // Deprecated: use IdAnnotation instead. - LegacyIdAnnotation = "config.k8s.io/id" - // InternalAnnotationsMigrationResourceIDAnnotation is used to uniquely identify // resources during round trip to and from a function execution. We will use it // to track the internal annotations and reconcile them if needed. @@ -51,46 +42,13 @@ const ( func GetFileAnnotations(rn *yaml.RNode) (string, string, error) { rm, _ := rn.GetMeta() annotations := rm.Annotations - path, found := annotations[PathAnnotation] - if !found { - path = annotations[LegacyPathAnnotation] - } - index, found := annotations[IndexAnnotation] - if !found { - index = annotations[LegacyIndexAnnotation] - } - return path, index, nil + return annotations[PathAnnotation], annotations[IndexAnnotation], nil } func GetIdAnnotation(rn *yaml.RNode) string { rm, _ := rn.GetMeta() annotations := rm.Annotations - id, found := annotations[IdAnnotation] - if !found { - id = annotations[LegacyIdAnnotation] - } - return id -} - -func CopyLegacyAnnotations(rn *yaml.RNode) error { - meta, err := rn.GetMeta() - if err != nil { - if err == yaml.ErrMissingMetadata { - // resource has no metadata, this should be a no-op - return nil - } - return err - } - if err := copyAnnotations(meta, rn, LegacyPathAnnotation, PathAnnotation); err != nil { - return err - } - if err := copyAnnotations(meta, rn, LegacyIndexAnnotation, IndexAnnotation); err != nil { - return err - } - if err := copyAnnotations(meta, rn, LegacyIdAnnotation, IdAnnotation); err != nil { - return err - } - return nil + return annotations[IdAnnotation] } func copyAnnotations(meta yaml.ResourceMeta, rn *yaml.RNode, legacyKey string, newKey string) error { @@ -142,9 +100,6 @@ func DefaultPathAndIndexAnnotation(dir string, nodes []*yaml.RNode) error { // check each node for the path annotation for i := range nodes { - if err := CopyLegacyAnnotations(nodes[i]); err != nil { - return err - } m, err := nodes[i].GetMeta() if err != nil { return err @@ -169,9 +124,6 @@ func DefaultPathAndIndexAnnotation(dir string, nodes []*yaml.RNode) error { if err := nodes[i].PipeE(yaml.SetAnnotation(PathAnnotation, path)); err != nil { return err } - if err := nodes[i].PipeE(yaml.SetAnnotation(LegacyPathAnnotation, path)); err != nil { - return err - } } // set the index annotations @@ -194,10 +146,6 @@ func DefaultPathAndIndexAnnotation(dir string, nodes []*yaml.RNode) error { yaml.SetAnnotation(IndexAnnotation, fmt.Sprintf("%d", c))); err != nil { return err } - if err := nodes[i].PipeE( - yaml.SetAnnotation(LegacyIndexAnnotation, fmt.Sprintf("%d", c))); err != nil { - return err - } } return nil } @@ -207,9 +155,6 @@ func DefaultPathAndIndexAnnotation(dir string, nodes []*yaml.RNode) error { func DefaultPathAnnotation(dir string, nodes []*yaml.RNode) error { // check each node for the path annotation for i := range nodes { - if err := CopyLegacyAnnotations(nodes[i]); err != nil { - return err - } m, err := nodes[i].GetMeta() if err != nil { return err @@ -225,9 +170,6 @@ func DefaultPathAnnotation(dir string, nodes []*yaml.RNode) error { if err := nodes[i].PipeE(yaml.SetAnnotation(PathAnnotation, path)); err != nil { return err } - if err := nodes[i].PipeE(yaml.SetAnnotation(LegacyPathAnnotation, path)); err != nil { - return err - } } return nil } @@ -276,12 +218,6 @@ func SortNodes(nodes []*yaml.RNode) error { if err != nil { return false } - if err := CopyLegacyAnnotations(nodes[i]); err != nil { - return false - } - if err := CopyLegacyAnnotations(nodes[j]); err != nil { - return false - } var iMeta, jMeta yaml.ResourceMeta if iMeta, _ = nodes[i].GetMeta(); err != nil { return false @@ -402,7 +338,7 @@ func GetInternalAnnotations(rn *yaml.RNode) map[string]string { annotations := meta.Annotations result := make(map[string]string) for k, v := range annotations { - if strings.HasPrefix(k, internalPrefix) || k == LegacyPathAnnotation || k == LegacyIndexAnnotation || k == LegacyIdAnnotation { + if strings.HasPrefix(k, internalPrefix) { result[k] = v } } diff --git a/kyaml/kio/kioutil/kioutil_test.go b/kyaml/kio/kioutil/kioutil_test.go index d054626527..e94259b757 100644 --- a/kyaml/kio/kioutil/kioutil_test.go +++ b/kyaml/kio/kioutil/kioutil_test.go @@ -99,7 +99,6 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'foo/b/bar_a.yaml' - config.kubernetes.io/path: 'foo/b/bar_a.yaml' `, `with namespace`}, { `foo`, @@ -114,7 +113,6 @@ metadata: name: a annotations: internal.config.kubernetes.io/path: 'foo/bar_a.yaml' - config.kubernetes.io/path: 'foo/bar_a.yaml' `, `without namespace`}, { @@ -132,7 +130,6 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'b/bar_a.yaml' - config.kubernetes.io/path: 'b/bar_a.yaml' `, `without dir`}, { ``, @@ -143,7 +140,6 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/path: 'a/b.yaml' `, `apiVersion: v1 kind: Bar @@ -152,7 +148,6 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/path: 'a/b.yaml' `, `skip`}, } @@ -190,9 +185,7 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'foo/b/bar_a.yaml' - config.kubernetes.io/path: 'foo/b/bar_a.yaml' internal.config.kubernetes.io/index: '0' - config.kubernetes.io/index: '0' `, `with namespace`}, { `foo`, @@ -207,9 +200,7 @@ metadata: name: a annotations: internal.config.kubernetes.io/path: 'foo/bar_a.yaml' - config.kubernetes.io/path: 'foo/bar_a.yaml' internal.config.kubernetes.io/index: '0' - config.kubernetes.io/index: '0' `, `without namespace`}, { @@ -227,9 +218,7 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'b/bar_a.yaml' - config.kubernetes.io/path: 'b/bar_a.yaml' internal.config.kubernetes.io/index: '0' - config.kubernetes.io/index: '0' `, `without dir`}, { ``, @@ -240,9 +229,7 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/path: 'a/b.yaml' internal.config.kubernetes.io/index: '5' - config.kubernetes.io/index: '5' `, `apiVersion: v1 kind: Bar @@ -251,9 +238,7 @@ metadata: namespace: b annotations: internal.config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/path: 'a/b.yaml' internal.config.kubernetes.io/index: '5' - config.kubernetes.io/index: '5' `, `skip`}, } @@ -375,83 +360,6 @@ func TestCreatePathAnnotationValue(t *testing.T) { } } -func TestCopyLegacyAnnotations(t *testing.T) { - var tests = []struct { - input string - expected string - }{ - { - input: `apiVersion: v1 -kind: Foo -metadata: - name: foobar - annotations: - config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/index: '5' -`, - expected: `apiVersion: v1 -kind: Foo -metadata: - name: foobar - annotations: - config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/index: '5' - internal.config.kubernetes.io/path: 'a/b.yaml' - internal.config.kubernetes.io/index: '5' -`, - }, - { - input: `apiVersion: v1 -kind: Foo -metadata: - name: foobar - annotations: - internal.config.kubernetes.io/path: 'a/b.yaml' - internal.config.kubernetes.io/index: '5' -`, - expected: `apiVersion: v1 -kind: Foo -metadata: - name: foobar - annotations: - internal.config.kubernetes.io/path: 'a/b.yaml' - internal.config.kubernetes.io/index: '5' - config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/index: '5' -`, - }, - { - input: `apiVersion: v1 -kind: Foo -metadata: - name: foobar - annotations: - internal.config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/path: 'c/d.yaml' -`, - expected: `apiVersion: v1 -kind: Foo -metadata: - name: foobar - annotations: - internal.config.kubernetes.io/path: 'a/b.yaml' - config.kubernetes.io/path: 'c/d.yaml' -`, - }, - } - - 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.CopyLegacyAnnotations(nodes[0])) - assert.Equal(t, tc.expected, nodes[0].MustString()) - } -} - func TestCopyInternalAnnotations(t *testing.T) { var tests = []struct { input string diff --git a/kyaml/kio/pkgio_reader.go b/kyaml/kio/pkgio_reader.go index 609a791f39..b5d67c3935 100644 --- a/kyaml/kio/pkgio_reader.go +++ b/kyaml/kio/pkgio_reader.go @@ -336,7 +336,6 @@ func (r *LocalPackageReader) initReaderAnnotations(path string, _ os.FileInfo) { } if !r.OmitReaderAnnotations { r.SetAnnotations[kioutil.PathAnnotation] = path - r.SetAnnotations[kioutil.LegacyPathAnnotation] = path } } diff --git a/kyaml/kio/pkgio_reader_test.go b/kyaml/kio/pkgio_reader_test.go index 721f15c604..c54273d275 100644 --- a/kyaml/kio/pkgio_reader_test.go +++ b/kyaml/kio/pkgio_reader_test.go @@ -77,16 +77,12 @@ func TestLocalPackageReader_Read_pkg(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a_test.yaml' `, @@ -98,24 +94,18 @@ g: - j metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'b_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'b_test.yaml' `, `a: b #third metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'c_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'c_test.yaml' `, `a: b #forth metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'd_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'd_test.yaml' `, @@ -150,16 +140,12 @@ func TestLocalPackageReader_Read_pkgAndSkipFile(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a_test.yaml' `, @@ -171,16 +157,12 @@ g: - j metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'b_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'b_test.yaml' `, `a: b #third metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'c_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'c_test.yaml' `, @@ -221,15 +203,11 @@ func TestLocalPackageReader_Read_JSON(t *testing.T) { 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'}}} `, `{"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'}}} `, @@ -261,16 +239,12 @@ func TestLocalPackageReader_Read_file(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a_test.yaml' `, @@ -340,8 +314,6 @@ func TestLocalPackageReader_Read_PreserveSeqIndent(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/seqindent: 'compact' @@ -349,8 +321,6 @@ metadata: `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a_test.yaml' internal.config.kubernetes.io/seqindent: 'compact' @@ -363,8 +333,6 @@ g: - j metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'b_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'b_test.yaml' internal.config.kubernetes.io/seqindent: 'compact' @@ -397,16 +365,12 @@ func TestLocalPackageReader_Read_nestedDirs(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, @@ -418,8 +382,6 @@ g: - j metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a${SEP}b${SEP}b_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}b_test.yaml' `, @@ -454,16 +416,12 @@ func TestLocalPackageReader_Read_matchRegex(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, @@ -500,16 +458,12 @@ func TestLocalPackageReader_Read_skipSubpackage(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, @@ -547,16 +501,12 @@ func TestLocalPackageReader_Read_includeSubpackage(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, `c: d # second metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'a${SEP}b${SEP}a_test.yaml' `, @@ -568,8 +518,6 @@ g: - j metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'a${SEP}c${SEP}c_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'a${SEP}c${SEP}c_test.yaml' `, @@ -651,8 +599,6 @@ func TestLocalPackageReader_ReadBareSeqNodes(t *testing.T) { `a: b #first metadata: annotations: - config.kubernetes.io/index: '0' - config.kubernetes.io/path: 'e_test.yaml' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'e_test.yaml' `, @@ -661,8 +607,6 @@ metadata: - bar metadata: annotations: - config.kubernetes.io/index: '1' - config.kubernetes.io/path: 'e_test.yaml' internal.config.kubernetes.io/index: '1' internal.config.kubernetes.io/path: 'e_test.yaml' `, diff --git a/kyaml/kio/pkgio_writer.go b/kyaml/kio/pkgio_writer.go index ce6fa45a5e..a31abacb28 100644 --- a/kyaml/kio/pkgio_writer.go +++ b/kyaml/kio/pkgio_writer.go @@ -66,7 +66,6 @@ func (r LocalPackageWriter) Write(nodes []*yaml.RNode) error { if !r.KeepReaderAnnotations { r.ClearAnnotations = append(r.ClearAnnotations, kioutil.PathAnnotation) - r.ClearAnnotations = append(r.ClearAnnotations, kioutil.LegacyPathAnnotation) } // validate outputs before writing any diff --git a/kyaml/kio/pkgio_writer_test.go b/kyaml/kio/pkgio_writer_test.go index 0676ca9336..6ab2117653 100644 --- a/kyaml/kio/pkgio_writer_test.go +++ b/kyaml/kio/pkgio_writer_test.go @@ -75,16 +75,12 @@ func TestLocalPackageWriter_Write_keepReaderAnnotations(t *testing.T) { require.Equal(t, `a: b #first metadata: annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: "a/b/a_test.yaml" internal.config.kubernetes.io/path: 'a/b/a_test.yaml' internal.config.kubernetes.io/index: '0' --- c: d # second metadata: annotations: - config.kubernetes.io/index: "1" - config.kubernetes.io/path: "a/b/a_test.yaml" internal.config.kubernetes.io/path: 'a/b/a_test.yaml' internal.config.kubernetes.io/index: '1' `, string(b)) @@ -98,8 +94,6 @@ g: - j metadata: annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: "a/b/b_test.yaml" internal.config.kubernetes.io/path: 'a/b/b_test.yaml' internal.config.kubernetes.io/index: '0' `, string(b)) diff --git a/kyaml/kio/tree.go b/kyaml/kio/tree.go index a14181578e..9f362ec908 100644 --- a/kyaml/kio/tree.go +++ b/kyaml/kio/tree.go @@ -49,11 +49,6 @@ type TreeWriterField struct { } func (p TreeWriter) packageStructure(nodes []*yaml.RNode) error { - for i := range nodes { - if err := kioutil.CopyLegacyAnnotations(nodes[i]); err != nil { - return err - } - } indexByPackage := p.index(nodes) // create the new tree diff --git a/kyaml/runfn/runfn.go b/kyaml/runfn/runfn.go index 6b36d7d3a9..e31d170fad 100644 --- a/kyaml/runfn/runfn.go +++ b/kyaml/runfn/runfn.go @@ -349,12 +349,6 @@ func sortFns(buff *kio.PackageBuffer) error { // sort the nodes so that we traverse them depth first // functions deeper in the file system tree should be run first sort.Slice(buff.Nodes, func(i, j int) bool { - if err := kioutil.CopyLegacyAnnotations(buff.Nodes[i]); err != nil { - return false - } - if err := kioutil.CopyLegacyAnnotations(buff.Nodes[j]); err != nil { - return false - } mi, _ := buff.Nodes[i].GetMeta() pi := filepath.ToSlash(mi.Annotations[kioutil.PathAnnotation]) @@ -506,9 +500,6 @@ func (r *RunFns) ffp(spec runtimeutil.FunctionSpec, api *yaml.RNode, currentUser var p string if spec.Starlark.Path != "" { pathAnno := m.Annotations[kioutil.PathAnnotation] - if pathAnno == "" { - pathAnno = m.Annotations[kioutil.LegacyPathAnnotation] - } p = filepath.ToSlash(path.Clean(pathAnno)) spec.Starlark.Path = filepath.ToSlash(path.Clean(spec.Starlark.Path))