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

✨ Switch to cluster-aware k8s clients, listers & informers #2104

Merged
merged 27 commits into from
Oct 21, 2022

Conversation

stevekuznetsov
Copy link
Contributor

No description provided.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2022
@openshift-ci openshift-ci bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Sep 29, 2022
@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch 3 times, most recently from dc388b5 to 9a09395 Compare October 6, 2022 12:58
@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch 2 times, most recently from 502785a to a54c7a1 Compare October 17, 2022 17:25
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 17, 2022

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ncdc for approval by writing /assign @ncdc in a comment. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch 3 times, most recently from dfbd0ff to 73d7d54 Compare October 20, 2022 13:57
}

source = c.factory(cluster)
c.sources[cluster] = source
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this map ever being cleaned up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not - seems like a good follow-up. We need the rebase to 1.25 to get resource event handler function cleanup on the (shared, cross-cluster) list.

@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch from 73d7d54 to 504302c Compare October 20, 2022 14:14
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 20, 2022
@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch from 504302c to 3908bfc Compare October 20, 2022 14:25
@stevekuznetsov
Copy link
Contributor Author

go.mod now points at kcp-dev/kubernetes#105

pkg/server/handler.go Show resolved Hide resolved
pkg/server/handler.go Show resolved Hide resolved
pkg/server/handler.go Show resolved Hide resolved
pkg/cache/server/crd_lister.go Show resolved Hide resolved
pkg/server/handler.go Show resolved Hide resolved

func (c *crdClusterLister) Cluster(name logicalcluster.Name) kcp.ClusterAwareCRDLister {
if name != bootstrap.SystemCRDLogicalCluster {
klog.Background().Error(fmt.Errorf("cluster-unaware crd lister got asked for %v cluster", name), "programmer error")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need 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.

Hmmm ... good question - it must have come from somewhere previous. Do you know? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it's only ever valid to use this particular cluster - maybe we don't need a Cluster() call here at all, let me remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see - when it's the APIBinding-aware one, this does not apply. I am just carrying forward the previous impl IUIC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(and it was your first-pass impl that hard-coded this value, and has a TODO for future improvements ;) )

Copy link
Contributor

Choose a reason for hiding this comment

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

i'd like to see how the apiextention server will be using crdClusterLister, could you please provide me with a link to your fork?

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, clarified with Steve in a gmeet.

@p0lyn0mial
Copy link
Contributor

reconciler/cache: make tests cluster-aware lgtm

Makefile Outdated
@@ -208,6 +208,9 @@ GO_TEST = $(GOTESTSUM) $(GOTESTSUM_ARGS) --
endif

COUNT ?= 1
Copy link
Member

Choose a reason for hiding this comment

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

What if instead we defaulted to unset, and if it's not empty, then set TEST_COUNT? Otherwise, you can't specify COUNT=1 and have it force running a test w/o hitting the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ACK - can drop this commit & do it stand-alone

@@ -189,30 +189,30 @@ require (

replace (
github.com/kcp-dev/kcp/pkg/apis => ./pkg/apis
k8s.io/api => github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20221005071841-6cfb7d485cbf
Copy link
Member

Choose a reason for hiding this comment

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

I assume you'll drop/replace this commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the last commit & will be replaced with the fork once we merge the k8s PR

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 20, 2022
@stevekuznetsov
Copy link
Contributor Author

Almost forgot ... TODO:

=== Skipped
=== SKIP: pkg/virtual/workspaces/registry TestDeleteWorkspace (0.00s)
    rest_test.go:1065: fake client does not support DeleteCollection, so this test never worked 

Daniel Smith suggested not implementing delete collection in the fake, said it was not well supported in k8s as it were ... can we get away with not using that verb?

@@ -112,7 +112,7 @@ func (c *controller) reconcile(ctx context.Context, apiBinding *apisv1alpha1.API
}

claimLogger.V(4).Info("listing resources")
objs, err := informer.Informer().GetIndexer().ByIndex(indexers.ByLogicalCluster, clusterName.String())
objs, err := informer.Lister().ByCluster(clusterName).List(labels.Everything())
Copy link
Contributor

Choose a reason for hiding this comment

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

where can I check the new interface of a lister?
what is ByCluster? an index?
how does it differ from configMapInformer.Lister().Cluster(cluster).ConfigMaps(namespace).Get(name)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was following the pattern of dynamic/generic listers doing ByNamespace() - but perhaps we should not do that and make it .Cluster()? You can see the implementation used in this PR already published to kcp-dev/client-go - https://github.com/kcp-dev/client-go/blob/272de79b2a7ab1d29e7d0db2d458258d035124d4/clients/metadata/metadatalister/shim.go#L54-L56

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I'd prefer to have Cluster() method on the dynamic client

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
We turned off the controller upstream, so we can stop serving the types
entirely.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch from 61cfd4c to fd306c5 Compare October 21, 2022 13:58
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2022
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/clients-listers-informers branch from fd306c5 to c948a85 Compare October 21, 2022 14:15
@ncdc ncdc changed the title [PROOF] use cluster-aware k8s clients, listers & informers ✨ Switch to cluster-aware k8s clients, listers & informers Oct 21, 2022
@ncdc ncdc merged commit c8f1c4c into kcp-dev:main Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants