Skip to content

Commit

Permalink
fix bug with migrating annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Oct 12, 2021
1 parent 67c58ad commit f665898
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions kyaml/kio/byteio_reader.go
Expand Up @@ -316,8 +316,14 @@ func (r *ByteReader) decode(originalYAML string, index int, decoder *yaml.Decode
r.SetAnnotations = map[string]string{}
}
if !r.OmitReaderAnnotations {
r.SetAnnotations[kioutil.IndexAnnotation] = fmt.Sprintf("%d", index)
r.SetAnnotations[kioutil.LegacyIndexAnnotation] = fmt.Sprintf("%d", index)
err := kioutil.CopyLegacyAnnotations(n)
if err != nil {
return nil, err
}
if val, ok := n.GetAnnotations()[kioutil.IndexAnnotation]; !ok || val == "" {
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
3 changes: 3 additions & 0 deletions kyaml/kio/kioutil/kioutil.go
Expand Up @@ -55,6 +55,9 @@ func GetFileAnnotations(rn *yaml.RNode) (string, string, error) {
func CopyLegacyAnnotations(rn *yaml.RNode) error {
meta, err := rn.GetMeta()
if err != nil {
if err != yaml.ErrMissingMetadata {
return nil
}
return err
}
if err := copyAnnotations(meta, rn, LegacyPathAnnotation, PathAnnotation); err != nil {
Expand Down

0 comments on commit f665898

Please sign in to comment.