Skip to content

Commit

Permalink
Merge pull request #4297 from mengqiy/anno
Browse files Browse the repository at this point in the history
kyaml/fn/framework ensures the annotation output format matches the input
  • Loading branch information
natasha41575 committed Nov 19, 2021
2 parents 2f11522 + bd7bad1 commit d113424
Show file tree
Hide file tree
Showing 10 changed files with 591 additions and 190 deletions.
6 changes: 6 additions & 0 deletions api/filters/fieldspec/fieldspec_test.go
Expand Up @@ -63,6 +63,9 @@ xxx:
apiVersion: foo/v1
kind: Bar
xxx:
metadata:
annotations:
internal.config.k8s.io/annotations-migration-resource-id: '0'
: cannot set or create an empty field name`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
Expand Down Expand Up @@ -220,6 +223,9 @@ a:
kind: Bar
a:
b: a
metadata:
annotations:
internal.config.k8s.io/annotations-migration-resource-id: '0'
: expected sequence or mapping node`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
Expand Down
2 changes: 2 additions & 0 deletions api/filters/refvar/refvar_test.go
Expand Up @@ -251,6 +251,7 @@ metadata:
annotations:
config.kubernetes.io/index: '0'
internal.config.kubernetes.io/index: '0'
internal.config.k8s.io/annotations-migration-resource-id: '0'
data:
slice:
- false
Expand Down Expand Up @@ -278,6 +279,7 @@ metadata:
annotations:
config.kubernetes.io/index: '0'
internal.config.kubernetes.io/index: '0'
internal.config.k8s.io/annotations-migration-resource-id: '0'
data:
1: str
: invalid map key: value='1', tag='` + yaml.NodeTagInt + `'`,
Expand Down
3 changes: 3 additions & 0 deletions api/resource/resource.go
Expand Up @@ -42,9 +42,12 @@ var BuildAnnotations = []string{
kioutil.PathAnnotation,
kioutil.IndexAnnotation,
kioutil.SeqIndentAnnotation,
kioutil.IdAnnotation,
kioutil.InternalAnnotationsMigrationResourceIDAnnotation,

kioutil.LegacyPathAnnotation,
kioutil.LegacyIndexAnnotation,
kioutil.LegacyIdAnnotation,
}

func (r *Resource) ResetRNode(incoming *Resource) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/config/internal/commands/e2e/e2e_test.go
Expand Up @@ -293,6 +293,8 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
annotations:
internal.config.k8s.io/annotations-migration-resource-id: '1'
`,
}
},
Expand Down
13 changes: 13 additions & 0 deletions kyaml/fn/framework/framework.go
Expand Up @@ -116,8 +116,21 @@ func Execute(p ResourceListProcessor, rlSource *kio.ByteReadWriter) error {
}
rl.FunctionConfig = rlSource.FunctionConfig

// We store the original
nodeAnnos, err := kio.PreprocessResourcesForInternalAnnotationMigration(rl.Items)
if err != nil {
return err
}

retErr := p.Process(&rl)

// If either the internal annotations for path, index, and id OR the legacy
// annotations for path, index, and id are changed, we have to update the other.
err = kio.ReconcileInternalAnnotations(rl.Items, nodeAnnos)
if err != nil {
return err
}

// Write the results
// Set the ResourceList.results for validating functions
if len(rl.Results) > 0 {
Expand Down
7 changes: 6 additions & 1 deletion kyaml/fn/framework/result.go
Expand Up @@ -64,7 +64,12 @@ func (i Result) String() string {
}
}
formatString := "[%s]"
list := []interface{}{i.Severity}
severity := i.Severity
// We default Severity to Info when converting a result to a message.
if i.Severity == "" {
severity = Info
}
list := []interface{}{severity}
if len(idStringList) > 0 {
formatString += " %s"
list = append(list, strings.Join(idStringList, "/"))
Expand Down
3 changes: 0 additions & 3 deletions kyaml/kio/byteio_writer_test.go
Expand Up @@ -400,7 +400,6 @@ metadata:
"a": "a long string that would certainly see a newline introduced by the YAML marshaller abcd123",
"metadata": {
"annotations": {
"config.kubernetes.io/path": "test.json",
"internal.config.kubernetes.io/path": "test.json"
}
}
Expand Down Expand Up @@ -429,7 +428,6 @@ metadata:
"a": "a long string that would certainly see a newline introduced by the YAML marshaller abcd123",
"metadata": {
"annotations": {
"config.kubernetes.io/path": "test.json",
"internal.config.kubernetes.io/path": "test.json"
}
}
Expand All @@ -449,7 +447,6 @@ metadata:
"a": "b",
"metadata": {
"annotations": {
"config.kubernetes.io/path": "test.json",
"internal.config.kubernetes.io/path": "test.json"
}
}
Expand Down

0 comments on commit d113424

Please sign in to comment.