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

🐛 Add cross-version compatibility with client-go 1.27 #2223

Merged
merged 1 commit into from Mar 15, 2023

Conversation

howardjohn
Copy link
Contributor

@howardjohn howardjohn commented Mar 3, 2023

Fixes #2222

I have manually verified this compiles with client-go 1.26 and 1.27, but I am not sure how to get test coverage of this; likely we will not be able to.

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 3, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 3, 2023
}
}
}
return true
Copy link

Choose a reason for hiding this comment

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

seems like this will give a problematic answer with the old client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would expect an old client can never call this since they would see a type ResourceEventHandlerRegistration interface{} as the return type. Of course they could attempt to type-cast that and would always get true, but that seems pretty obscure?

Copy link

Choose a reason for hiding this comment

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

I see, gotcha

for ns, informer := range i.namespaceToInformer {
registration, err := informer.AddEventHandler(handler)
if err != nil {
return nil, err
}
handles[ns] = registration
handles.handles[ns] = registration
Copy link

Choose a reason for hiding this comment

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

won't the multiple informers collide and overwrite the prior one's handle?

Copy link

Choose a reason for hiding this comment

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

wait, there's a different informer per namespace? ok nvm, sorry.

}

func (e eventHandlerWrapper) OnAdd(obj interface{}) {
if m, ok := e.handler.(modernResourceEventHandler); ok {
Copy link

Choose a reason for hiding this comment

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

clever, lol

@lavalamp
Copy link

lavalamp commented Mar 3, 2023

LGTM but I'm not a reviewer here :)

@howardjohn howardjohn marked this pull request as ready for review March 3, 2023 18:53
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 3, 2023
@k8s-ci-robot k8s-ci-robot requested a review from inteon March 3, 2023 18:53
@howardjohn
Copy link
Contributor Author

/assign @alvaroaleman

// eventHandlerWrapper wraps a ResourceEventHandler in a manner that is compatible with client-go 1.27+ and older.
// The interface was changed in these versions.
type eventHandlerWrapper struct {
handler any
Copy link
Member

Choose a reason for hiding this comment

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

Can we use generics to type this to one of the two interfaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, or at least do not know how to. See golang/go#49054


// HasSynced asserts that the handler has been called for the full initial state of the informer.
// This uses syncer to be compatible between client-go 1.27+ and older versions when the interface changed.
func (h handlerRegistration) HasSynced() bool {
Copy link
Member

Choose a reason for hiding this comment

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

I think I am blind, where do we call this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't call this, if allows the interface to be implemented on 0.27

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since they added this function

@howardjohn howardjohn requested review from alvaroaleman and removed request for vincepri, inteon and varshaprasad96 March 15, 2023 15:33
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 15, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, howardjohn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 15, 2023
@k8s-ci-robot k8s-ci-robot merged commit a26de2d into kubernetes-sigs:main Mar 15, 2023
7 checks passed
flavio-fernandes added a commit to flavio-fernandes/cluster-network-operator that referenced this pull request May 17, 2023
Ref fix: kubernetes-sigs/controller-runtime#2223

vendor/sigs.k8s.io/controller-runtime/pkg/cache/multi_namespace_cache.go:308:9: cannot use handles (variable of type map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration) as "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration value in return statement: map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing method HasSynced)
vendor/sigs.k8s.io/controller-runtime/pkg/cache/multi_namespace_cache.go:321:9: cannot use handles (variable of type map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration) as "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration value in return statement: map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing method HasSynced)
vendor/sigs.k8s.io/controller-runtime/pkg/cache/multi_namespace_cache.go:326:17: impossible type assertion: h.(map[string]toolscache.ResourceEventHandlerRegistration)
        map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing method HasSynced)
make: *** [vendor/github.com/openshift/build-machinery-go/make/targets/golang/build.mk:16: build] Error 1

Signed-off-by: Flavio Fernandes <flaviof@redhat.com>
flavio-fernandes added a commit to flavio-fernandes/cluster-network-operator that referenced this pull request May 17, 2023
go get sigs.k8s.io/controller-runtime@v0.15.0-alpha.1
go mod tidy
go mod vendor

Reference fix: kubernetes-sigs/controller-runtime#2223

to address the following build issue:

vendor/sigs.k8s.io/controller-runtime/pkg/cache/multi_namespace_cache.go:308:9: cannot use handles (variable of type map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration) as "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration value in return statement: map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing method HasSynced)
vendor/sigs.k8s.io/controller-runtime/pkg/cache/multi_namespace_cache.go:321:9: cannot use handles (variable of type map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration) as "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration value in return statement: map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing method HasSynced)
vendor/sigs.k8s.io/controller-runtime/pkg/cache/multi_namespace_cache.go:326:17: impossible type assertion: h.(map[string]toolscache.ResourceEventHandlerRegistration)
        map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing method HasSynced)
make: *** [vendor/github.com/openshift/build-machinery-go/make/targets/golang/build.mk:16: build] Error 1

Signed-off-by: Flavio Fernandes <flaviof@redhat.com>
nathanjsweet pushed a commit to cilium/cilium that referenced this pull request May 23, 2023
Updating k8s libs to v1.27.1 requires updating
sigs.k8s.io/controller-runtime to an unreleased version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
nathanjsweet pushed a commit to cilium/cilium that referenced this pull request May 26, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
sayboras pushed a commit to cilium/cilium that referenced this pull request May 29, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
nathanjsweet pushed a commit to cilium/cilium that referenced this pull request Jun 6, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
nathanjsweet pushed a commit to cilium/cilium that referenced this pull request Jun 9, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
nathanjsweet pushed a commit to cilium/cilium that referenced this pull request Jun 14, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
nathanjsweet pushed a commit to cilium/cilium that referenced this pull request Jun 14, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
romanspb80 pushed a commit to romanspb80/cilium that referenced this pull request Jun 22, 2023
Updating k8s libs to v1.27.2 requires updating
sigs.k8s.io/controller-runtime to the 0.15 version with
kubernetes-sigs/controller-runtime#2223 in
place. This in turn requires some additional adjustments to changed APIs
in the controller-runtime, mainly in operator/pkg/gateway-api. Specifically,
around request methods and testing.

The service.kubernetes.io/topology-aware-hints annotation got deprecated
with k8s 1.27 in favor of service.kubernetes.io/topology-mode (see
kubernetes/kubernetes#116522). This change keeps
support for the deprecated annotation. Support for the new annotation
will be added in a successive commit.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adapt to breaking changes in 1.27 client-go
4 participants