Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kyaml/fn/framework ensures the annotation output format matches the input #4297

Merged
merged 7 commits into from Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KnVerey this is something we should discuss before the next release of the api module to decide if we are okay with the change.

What's happening is to migrate the annotations, kyaml/kio adds a new annotation to help keep track of the migration, then runs the filter, then removes the annotation. In the case that the filter errors, it includes in its error message the contents of the failing RNode. Unfortunately that means that this annotation gets included in the error message before we can remove it.

Because this is blocking kpt and doesn't show up in the output of kustomize (we've added the annotation to kustomize's BuildAnnotations so that it will get removed), I'm approving this PR to go in so that they can use an unreleased version of kyaml until we have a better solution/decision.

No changes need to be made if we decide we're okay with these annotations showing up in the output of api and cmd/config tests.

One option I was considering was to change the error message for the filters to just have the object's GVKNN, rather than the entire content of the RNode.

Another option is to clear the annotation in the filter functions before generating the error message, but we'd need to do that in several places, which doesn't seem ideal to me.

: 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'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the command test.
I'm not sure why it will need this change to pass.

`,
}
},
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)
natasha41575 marked this conversation as resolved.
Show resolved Hide resolved
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