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
fix bug with migrating kyaml reader path, index, and id annotations #4227
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,3 +374,80 @@ 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When both exist and don't match, should we error it out somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is handled in If the input resource to an orchestrator has both set but they differ, the orchestrator will prefer the internal annotation over the legacy one. Do you believe it should throw an error instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should error when the input to the function has both new and legacy annotations, the function modify both annotations and they mismatch. In this case, we can't infer the user's intend, we should error. It should be fine in other cases as long as we can infer user's intend. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good. I will update it to throw an error instead. |
||
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()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reordering is undoing the reordering done by the original PR https://github.com/kubernetes-sigs/kustomize/pull/4190/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this considered as a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't considered a breaking change in #4190 when the reordering occurred, so I don't think it would be considered a breaking change to reverse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these annotations cause an ordering change, and under what circumstances? Any reordering that surfaces in Kustomize itself should be considered breaking. But judging by this being the only test where it surfaces, I take it only direct kyaml use is affected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree and this change only surfaced directly in kyaml. The reordering occurred in the test case where the nodes were being ordered - specifically in this case, some of the resources had the path/index annotations while this one did not. My guess (though I haven't done any investigation to back this up) is that the bug (introduced in #4190) which caused the legacy annotations to be sometimes overwritten or ignored caused the reordering, and this PR fixed it along with its other fixes.