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

Vendor k/*@v0.20 and controller-runtime@v0.8 #3651

Merged
merged 4 commits into from Mar 15, 2021

Conversation

rfranzke
Copy link
Member

@rfranzke rfranzke commented Mar 3, 2021

How to categorize this PR?

/area open-source quality
/kind task
/priority normal

What this PR does / why we need it:
This PR vendors all the Kubernetes dependencies in version v0.20.2 and controller-runtime version v0.8.3.

Special notes for your reviewer:
/invite @timebertt @ialidzhikov
/squash

I got rid of our fork of k8s.io/kube-openapi and our pinning of sigs.k8s.io/structured-merge-diff/v4 - do you see issues with this?

Release note:

⚠️ Go dependencies to `kubernetes/*` and `kubernetes-sigs/controller-runtime` were updated to `v0.20.2` and `v0.8.3` respectively.

@rfranzke rfranzke requested a review from a team as a code owner March 3, 2021 08:12
@gardener-robot gardener-robot added area/open-source Open Source (community, enablement, contributions, conferences, CNCF, etc.) related area/quality Output qualification (tests, checks, scans, automation in general, etc.) related kind/task General task merge/squash size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 3, 2021
Comment on lines -289 to -512
// TODO: Inefficient conversion - can we improve it?
if err := s.Convert(*in, *out, 0); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Due to this, I had to introduce https://github.com/gardener/gardener/pull/3651/files#diff-c7b64578d2ac95623dfd44edeb4a58700b755fa9bda6b8267965ec156363a6e6R76-R83. I'm not sure why the generation does not find the functions here:

// Convert_v1beta1_SeedTemplate_To_core_SeedTemplate is an autogenerated conversion function.
func Convert_v1beta1_SeedTemplate_To_core_SeedTemplate(in *SeedTemplate, out *core.SeedTemplate, s conversion.Scope) error {
return autoConvert_v1beta1_SeedTemplate_To_core_SeedTemplate(in, out, s)
}

I played with --extra-peer-dirs but without success. Any pointers are appreciated.

/cc @stoyanr @ialidzhikov

Copy link

@schrodit schrodit Mar 9, 2021

Choose a reason for hiding this comment

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

We also ran into a similar problem with k8s 1.20.
It looks like a regression in the code generator for k8s 1.20: kubernetes/kubernetes#98380

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @schrodit for pointing this out. Then I guess the workaround I applied is fine for now until a fix was released, right?

@ialidzhikov
Copy link
Member

I got rid of our fork of k8s.io/kube-openapi and our pinning of sigs.k8s.io/structured-merge-diff/v4 - do you see issues with this?

Yes. I guess we will be able to get rid of the replace for sigs.k8s.io/structured-merge-diff/v4 only after kubernetes/kubernetes#99038.

@rfranzke
Copy link
Member Author

rfranzke commented Mar 4, 2021

OK, thanks @ialidzhikov. Also, @timuthy mentioned that we now should be able to get rid of https://github.com/gardener/gardener/tree/master/third_party/forked/kubernetes, so I will look into that.
/status author-action

@gardener-robot
Copy link

@rfranzke The pull request was assigned to you under author-action. Please unassign yourself when you are done. Thank you.

@gardener-robot gardener-robot added priority/3 Priority (lower number equals higher priority) and removed priority/normal priority/3 Priority (lower number equals higher priority) labels Mar 8, 2021
@gardener-robot
Copy link

@rfranzke Label priority/normal does not exist.

@rfranzke
Copy link
Member Author

rfranzke commented Mar 9, 2021

OK, thanks to @ialidzhikov and @timuthy I've updated the PR now (and also use the latest, just released v0.8.3 version of the controller-runtime library).

@ialidzhikov
Copy link
Member

/assign


c.EXPECT().Patch(ctx, worker, client.MergeFrom(workerWithAnnotation))
ctx := context.TODO()
test.EXPECTPatch(ctx, c, expectedWorker, workerWithAnnotation)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is odd. I really liked the way it was before this PR (without any helper func for expecting patch)

			c.EXPECT().Patch(ctx, worker, client.MergeFrom(workerWithAnnotation))

I see that the old way fails with error like:

    Unexpected call to *client.MockClient.Patch([context.TODO 0xc00025ad80 0xc000899da0]) at /go/src/github.com/gardener/gardener/extensions/pkg/controller/utils.go:193 because:
    expected call at /go/src/github.com/gardener/gardener/extensions/pkg/controller/utils_test.go:171 doesn't match the argument at index 2.
    Got: &{application/merge-patch+json 0x1e25600 0xc00025b200 {false}}
    Want: is equal to &{application/merge-patch+json 0x1e25600 0xc00025afc0 {false}}

Do you know why with the new version of controller-runtime it now fails with similar error ? I see kubernetes-sigs/controller-runtime#1406 but I cannot correlate it to the failure.

The reason I am asking is that currently the helper func test.EXPECTPatch is always expecting a MergeFrom PatchOption and I assume this func won't be useful if there is usage of StrategicMergeFrom or anything other PatchOption.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know why with the new version of controller-runtime it now fails with similar error ? I see kubernetes-sigs/controller-runtime#1406 but I cannot correlate it to the failure.

This is explained in the commit message of 0fdab6e:

Due to kubernetes-sigs/controller-runtime#1413,
naive gomock expectations don't work anymore. The reason is that the
mergeFromPatch struct has now a function attribute (createPatch),
and as gomega is using reflect.DeepEqual under the hood, the
comparison now fails:

Func values are deeply equal if both are nil; otherwise they are not deeply equal.
(from https://golang.org/pkg/reflect/#DeepEqual)

Hence, we introduce our own test.EXPECTPatch() function.

Thanks to @timuthy for pointing this out.

I'm also not too happy with it and am very much open for better ideas.

The reason I am asking is that currently the helper func test.EXPECTPatch is always expecting a MergeFrom PatchOption and I assume this func won't be useful if there is usage of StrategicMergeFrom or anything other PatchOption.

Maybe, but we don't use StrategicMergeFrom or any PatchOption yet, so the function can be extended as soon as we need it.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, thanks for explaining. I guess the proper way to fix this is to adapt the createPatch field from func to an interface in the upstream. I can have a look into this one with some lower prio. But yeah, it seems that it is out of the scope of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, probably @timebertt can help here as the initial author of this change in k-sigs/controller-runtime :)

Copy link
Member

Choose a reason for hiding this comment

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

I now opened kubernetes-sigs/controller-runtime#1439. Let me know if you have more elegant solution to the problem in mind.

ialidzhikov
ialidzhikov previously approved these changes Mar 10, 2021
Copy link
Member

@ialidzhikov ialidzhikov left a comment

Choose a reason for hiding this comment

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

/lgtm
/needs second-opinion

Due to kubernetes-sigs/controller-runtime#1413,
naive gomock expectations don't work anymore. The reason is that the
`mergeFromPatch` struct has now a function attribute (`createPatch`),
and as `gomega` is using `reflect.DeepEqual` under the hood, the
comparison now fails:

> Func values are deeply equal if both are nil; otherwise they are not deeply equal.
(from https://golang.org/pkg/reflect/#DeepEqual)

Hence, we introduce our own `test.EXPECTPatch()` function.

Thanks to @timuthy for pointing this out.
@rfranzke
Copy link
Member Author

Rebased to resolve the conflicts.

Copy link
Member

@ialidzhikov ialidzhikov left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Contributor

@timuthy timuthy left a comment

Choose a reason for hiding this comment

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

/lgtm
Thanks for cleaning up the forked code as well 👍

@timuthy timuthy merged commit 06242c9 into gardener:master Mar 15, 2021
@rfranzke rfranzke deleted the enh/ctrlruntime-upgrade branch March 15, 2021 13:28
krgostev pushed a commit to krgostev/gardener that referenced this pull request Apr 21, 2022
* make revendor generate

* Get rid of third_party/forked/kubernetes

* Adapt Patch() expectations of MockClient

Due to kubernetes-sigs/controller-runtime#1413,
naive gomock expectations don't work anymore. The reason is that the
`mergeFromPatch` struct has now a function attribute (`createPatch`),
and as `gomega` is using `reflect.DeepEqual` under the hood, the
comparison now fails:

> Func values are deeply equal if both are nil; otherwise they are not deeply equal.
(from https://golang.org/pkg/reflect/#DeepEqual)

Hence, we introduce our own `test.EXPECTPatch()` function.

Thanks to @timuthy for pointing this out.

* Adapt kubelet config
krgostev pushed a commit to krgostev/gardener that referenced this pull request Jul 5, 2022
* make revendor generate

* Get rid of third_party/forked/kubernetes

* Adapt Patch() expectations of MockClient

Due to kubernetes-sigs/controller-runtime#1413,
naive gomock expectations don't work anymore. The reason is that the
`mergeFromPatch` struct has now a function attribute (`createPatch`),
and as `gomega` is using `reflect.DeepEqual` under the hood, the
comparison now fails:

> Func values are deeply equal if both are nil; otherwise they are not deeply equal.
(from https://golang.org/pkg/reflect/#DeepEqual)

Hence, we introduce our own `test.EXPECTPatch()` function.

Thanks to @timuthy for pointing this out.

* Adapt kubelet config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/open-source Open Source (community, enablement, contributions, conferences, CNCF, etc.) related area/quality Output qualification (tests, checks, scans, automation in general, etc.) related kind/task General task size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants