Skip to content

Commit

Permalink
cache: stop reporting an error from a CRD lister on incorrect cluster…
Browse files Browse the repository at this point in the history
… name

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
  • Loading branch information
p0lyn0mial committed Jan 11, 2023
1 parent b9cedbd commit 21e02a7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/cache/server/crd_lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@ package server

import (
"context"
"fmt"

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

"github.com/kcp-dev/kcp/pkg/cache/server/bootstrap"
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"
)

// crdClusterLister is a CRD lister.
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 +54,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 +66,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)
}

0 comments on commit 21e02a7

Please sign in to comment.