-
Notifications
You must be signed in to change notification settings - Fork 111
✨ Allow RFC6902 patches and strategic merge patches for provider manifests #937
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
base: main
Are you sure you want to change the base?
✨ Allow RFC6902 patches and strategic merge patches for provider manifests #937
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Welcome @hjoshi123! |
|
Hi @hjoshi123. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
✅ Deploy Preview for kubernetes-sigs-cluster-api-operator ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
5fbe651 to
06a4c41
Compare
nalum
left a comment
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.
Looking good, just a few comments.
One question I have on the merge patch is around the requirement for the apiVersion key. I know you don't likely have an answer for the reasoning behind that but is that still the case for the new patching setup?
| patches: []*operatorv1.Patch{ | ||
| { | ||
| Patch: addServiceAccoungPatchRBAC, | ||
| Target: &operatorv1.PatchSelector{ | ||
| Group: "rbac.authorization.k8s.io", | ||
| Kind: "ClusterRoleBinding", | ||
| }, | ||
| }, |
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 looks like it will fail the test based on the existing test.
I would update this to use it's own set of patch data as you want to test all patch types that this supports.
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.
Yes I am writing more tests. The one I added was just a basic test to see if merge patch works.. and I ran the tests in local and it does patch and tests pass.. I will add more for RFC6902 patches
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 did add a test regarding jsonpatch and it passed.. let me know if the code looks good.
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.
@hjoshi123 thanks for this, it's looking better. I would suggest a change though, this does not match the existing test structure.
Could you update to follow that?
As an example:
testCases := []struct {
name string
objectsToPatchYaml string
patches []*operatorv1.Patch
expectedOutput string
}{
{
name: "strategic merge test",
objectsToPatchYaml: testObjectsToPatchYaml,
expectedOutput: expectedTestPatchedObjectsYaml,
patches: []*operatorv1.Patch{
{
Patch: addServiceAccoungPatchRBAC,
Target: &operatorv1.PatchSelector{
Group: "rbac.authorization.k8s.io",
Kind: "ClusterRoleBinding",
},
},
// ... leaving out for brevity
},
},
{
name: "rfc6902 patch test add",
objectsToPatchYaml: testObjectsToPatchYaml,
expectedOutput: expectedRFC6902Output,
patches: []*operatorv1.Patch{
{
Patch: rfc6902PatchAdd,
Target: &operatorv1.PatchSelector{
Group: "rbac.authorization.k8s.io",
Kind: "ClusterRoleBinding",
},
},
// ... leaving out for brevity
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
objectToPatch, err := utilyaml.ToUnstructured([]byte(tc.objectsToPatchYaml))
g.Expect(err).NotTo(HaveOccurred())
result, err := ApplyGenericPatches(objectToPatch, tc.patches)
if tc.expectedError {
g.Expect(err).To(HaveOccurred())
}
g.Expect(err).NotTo(HaveOccurred())
resultYaml, err := utilyaml.FromUnstructured(result)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(string(resultYaml)).To(Equal(tc.expectedOutput))
})
}I would also add an additional test that shows the output of the existing spec.manifestPatches matches the expected output of that and the output of the new spec.patches.
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.
And a test that checks that either spec.patches or spec.manifestPatches is set, not both of them.
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.
Yup will definitely add more tests.. just wanted to get the feedback on the logic itself.. and the tests are failing because of outdated generate files and log package (will fix it later this evening)
The way I wrote the logic if both are put in then spec.patches gets the priority. We can change the behavior but I feel if we document it, it should be fine.
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.
The way I wrote the logic if both are put in then spec.patches gets the priority.
It should be one or the other. If a user sets both, then the webhook validation should fail. The reason is that this makes the migration and deprecation of the old field easier.
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.
@richardcase I did add the kubebuilder validations to check if both of them are present to error out... I am not sure about how to test it.. Should it be part of phases_test?
@nalum I did fix the test to match the existing behavior for both merge and json patches.
|
Should also update the patching provider manifests page. |
06a4c41 to
3834a50
Compare
|
/ok-to-test |
3834a50 to
8f30c82
Compare
Signed-off-by: Hemant Joshi <mail@hjoshi.me>
8f30c82 to
d09d80c
Compare
What this PR does / why we need it:
Allow JSON merge patches and RFC6902 for provider manifests, this makes it possible to modify provider manifests consistently across releases, for example, if the user needs to change labels/annotations on objects, example usage:
This still uses the same patch library. This PR doesn't remove the existing field but introduces a new one and in the future versions of the operator we can deprecate the existing
manifestPatchesfield in favor of a more genericpatchesfield.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #792