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

🐛 cache: stop reporting an error from a CRD lister on incorrect cluster name #2592

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pkg/cache/server/crd_lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ package server

import (
"context"
"fmt"

"github.com/kcp-dev/logicalcluster/v3"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
kcpapiextensionsv1listers "k8s.io/apiextensions-apiserver/pkg/client/kcp/listers/apiextensions/v1"
"k8s.io/apiextensions-apiserver/pkg/kcp"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"

"github.com/kcp-dev/kcp/pkg/cache/server/bootstrap"
)
Expand All @@ -36,10 +34,10 @@ type crdClusterLister struct {
lister kcpapiextensionsv1listers.CustomResourceDefinitionClusterLister
}

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")
}
func (c *crdClusterLister) Cluster(_ logicalcluster.Name) kcp.ClusterAwareCRDLister {
// since all available CRDs are stored in bootstrap.SystemCRDLogicalCluster
// and there is only a single registry per a CRD
// there is no need to filter by the given cluster
return &crdLister{
crdClusterLister: c,
cluster: bootstrap.SystemCRDLogicalCluster,
Expand All @@ -58,7 +56,9 @@ var _ kcp.ClusterAwareCRDLister = &crdLister{}

// List lists all CustomResourceDefinitions.
func (c *crdLister) List(ctx context.Context, selector labels.Selector) ([]*apiextensionsv1.CustomResourceDefinition, error) {
// TODO: make it shard and cluster aware, for now just return what we have in the system ws
// since all available CRDs are stored in bootstrap.SystemCRDLogicalCluster
// and there is only a single registry per a CRD
// there is no need to filter by a shard or a cluster
return c.lister.List(selector)
}

Expand All @@ -68,6 +68,8 @@ func (c *crdLister) Refresh(crd *apiextensionsv1.CustomResourceDefinition) (*api

// Get gets a CustomResourceDefinition.
func (c *crdLister) Get(ctx context.Context, name string) (*apiextensionsv1.CustomResourceDefinition, error) {
// TODO: make it shard and cluster aware, for now just return what we have in the system ws
// since all available CRDs are stored in bootstrap.SystemCRDLogicalCluster
// and there is only a single registry per a CRD
// there is no need to filter by a shard or a cluster
return c.lister.Cluster(c.cluster).Get(name)
}