Skip to content

Commit

Permalink
[Remove] References to legacy annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
varshaprasad96 committed Nov 13, 2023
1 parent e219b88 commit a5075b5
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 881 deletions.
4 changes: 0 additions & 4 deletions api/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/config/internal/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
31 changes: 6 additions & 25 deletions kyaml/fn/runtime/runtimeutil/runtimeutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions kyaml/fn/runtime/starlark/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -264,7 +261,6 @@ run(ctx.resource_list["items"])
Writer: output,
ClearAnnotations: []string{
kioutil.PathAnnotation,
kioutil.LegacyPathAnnotation,
},
}}}.Execute()
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions kyaml/inpututil/inpututil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 0 additions & 5 deletions kyaml/kio/byteio_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions kyaml/kio/byteio_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ i: j
c: d
metadata:
annotations:
config.kubernetes.io/index: '0'
internal.config.kubernetes.io/index: '0'
`,
`# second resource
Expand All @@ -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'
`,
},
Expand Down Expand Up @@ -262,7 +259,6 @@ a: b # first resource
c: d
metadata:
annotations:
config.kubernetes.io/index: '0'
internal.config.kubernetes.io/index: '0'
`,
`
Expand All @@ -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'
`,
},
Expand Down Expand Up @@ -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{},
Expand Down
2 changes: 0 additions & 2 deletions kyaml/kio/byteio_readwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ spec:
replicas: 1
metadata:
annotations:
config.kubernetes.io/index: '0'
internal.config.kubernetes.io/index: '0'
---
kind: Service
Expand All @@ -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},
Expand Down
5 changes: 0 additions & 5 deletions kyaml/kio/byteio_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions kyaml/kio/byteio_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
`,
},

Expand Down Expand Up @@ -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'
`,
},

Expand Down
10 changes: 0 additions & 10 deletions kyaml/kio/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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])
}
Expand All @@ -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])
}
}
Expand Down
6 changes: 0 additions & 6 deletions kyaml/kio/filters/merge3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit a5075b5

Please sign in to comment.