Skip to content

🌱 switch to logicalcluster.v3 #20

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

Merged
merged 6 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ GOBIN_DIR=$(abspath ./bin )
PATH := $(GOBIN_DIR):$(TOOLS_GOBIN_DIR):$(PATH)
TMPDIR := $(shell mktemp -d)

CODE_GENERATOR_VER := 2dc1248118a7f2337c6374ff5778c0880e1a4226
CODE_GENERATOR_VER := v2.0.0-alpha.1
CODE_GENERATOR_BIN := code-generator
CODE_GENERATOR := $(TOOLS_DIR)/$(CODE_GENERATOR_BIN)-$(CODE_GENERATOR_VER)
export CODE_GENERATOR # so hack scripts can use it

$(CODE_GENERATOR):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/kcp-dev/code-generator $(CODE_GENERATOR_BIN) $(CODE_GENERATOR_VER)
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/kcp-dev/code-generator/v2 $(CODE_GENERATOR_BIN) $(CODE_GENERATOR_VER)

OPENSHIFT_GOIMPORTS_VER := c72f1dc2e3aacfa00aece3391d938c9bc734e791
OPENSHIFT_GOIMPORTS_BIN := openshift-goimports
Expand Down
4 changes: 2 additions & 2 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package main

import (
_ "github.com/kcp-dev/apimachinery/pkg/cache"
_ "github.com/kcp-dev/logicalcluster/v2"
_ "github.com/kcp-dev/apimachinery/v2/pkg/cache"
_ "github.com/kcp-dev/logicalcluster/v3"

_ "k8s.io/api/core/v1"
_ "k8s.io/apimachinery/pkg/labels"
Expand Down
8 changes: 4 additions & 4 deletions discovery/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"fmt"
"net/http"

kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
"github.com/kcp-dev/logicalcluster/v2"
kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
Expand All @@ -36,8 +36,8 @@ type ClusterClientset struct {
}

// Cluster scopes the client down to a particular cluster.
func (c *ClusterClientset) Cluster(name logicalcluster.Name) discovery.DiscoveryInterface {
return c.clientCache.ClusterOrDie(name)
func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) discovery.DiscoveryInterface {
return c.clientCache.ClusterOrDie(clusterPath)
}

// NewForConfig creates a new ClusterClientset for the given config.
Expand Down
4 changes: 2 additions & 2 deletions discovery/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package discovery

import (
"github.com/kcp-dev/logicalcluster/v2"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/client-go/discovery"
)

type DiscoveryClusterInterface interface {
Cluster(logicalcluster.Name) discovery.DiscoveryInterface
Cluster(logicalcluster.Path) discovery.DiscoveryInterface
discovery.DiscoveryInterface
}
16 changes: 8 additions & 8 deletions dynamic/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"fmt"
"net/http"

kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
"github.com/kcp-dev/logicalcluster/v2"
kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client"
"github.com/kcp-dev/logicalcluster/v3"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -42,8 +42,8 @@ type ClusterClientset struct {
}

// Cluster scopes the client down to a particular cluster.
func (c *ClusterClientset) Cluster(name logicalcluster.Name) dynamic.Interface {
return c.clientCache.ClusterOrDie(name)
func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) dynamic.Interface {
return c.clientCache.ClusterOrDie(clusterPath)
}

func (c *ClusterClientset) Resource(resource schema.GroupVersionResource) ResourceClusterInterface {
Expand Down Expand Up @@ -87,7 +87,7 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli
cache := kcpclient.NewCache(c, httpClient, &kcpclient.Constructor[dynamic.Interface]{
NewForConfigAndClient: thirdpartydynamic.NewForConfigAndClient,
})
if _, err := cache.Cluster(logicalcluster.New("root")); err != nil {
if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil {
return nil, err
}

Expand All @@ -110,12 +110,12 @@ type ClusterResourceClient struct {
}

// Cluster scopes the client down to a particular cluster.
func (c *ClusterResourceClient) Cluster(name logicalcluster.Name) dynamic.NamespaceableResourceInterface {
if name == logicalcluster.Wildcard {
func (c *ClusterResourceClient) Cluster(clusterPath logicalcluster.Path) dynamic.NamespaceableResourceInterface {
if clusterPath == logicalcluster.Wildcard {
panic("A specific cluster must be provided when scoping, not the wildcard.")
}

return c.clientCache.ClusterOrDie(name).Resource(c.resource)
return c.clientCache.ClusterOrDie(clusterPath).Resource(c.resource)
}

// List returns the entire collection of all resources across all clusters.
Expand Down
12 changes: 6 additions & 6 deletions dynamic/dynamicinformer/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"sync"
"time"

kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
thirdpartyinformers "github.com/kcp-dev/apimachinery/third_party/informers"
"github.com/kcp-dev/logicalcluster/v2"
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
thirdpartyinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers"
"github.com/kcp-dev/logicalcluster/v3"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -164,10 +164,10 @@ func (d *dynamicClusterInformer) Lister() kcpcache.GenericClusterLister {
return kcpdynamiclisters.NewRuntimeObjectShim(kcpdynamiclisters.New(d.informer.GetIndexer(), d.gvr))
}

func (d *dynamicClusterInformer) Cluster(cluster logicalcluster.Name) upstreaminformers.GenericInformer {
func (d *dynamicClusterInformer) Cluster(clusterName logicalcluster.Name) upstreaminformers.GenericInformer {
return &dynamicInformer{
informer: d.Informer().Cluster(cluster),
lister: d.Lister().ByCluster(cluster),
informer: d.Informer().Cluster(clusterName),
lister: d.Lister().ByCluster(clusterName),
}
}

Expand Down
2 changes: 1 addition & 1 deletion dynamic/dynamiclister/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package dynamiclister

import (
"github.com/kcp-dev/logicalcluster/v2"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
Expand Down
34 changes: 17 additions & 17 deletions dynamic/dynamiclister/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package dynamiclister

import (
kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
"github.com/kcp-dev/logicalcluster/v2"
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -41,8 +41,8 @@ type dynamicClusterLister struct {
gvr schema.GroupVersionResource
}

func (l *dynamicClusterLister) Cluster(name logicalcluster.Name) dynamiclister.Lister {
return &dynamicLister{indexer: l.indexer, gvr: l.gvr, cluster: name}
func (l *dynamicClusterLister) Cluster(clusterName logicalcluster.Name) dynamiclister.Lister {
return &dynamicLister{indexer: l.indexer, gvr: l.gvr, clusterName: clusterName}
}

func (l *dynamicClusterLister) List(selector labels.Selector) (ret []*unstructured.Unstructured, err error) {
Expand All @@ -57,16 +57,16 @@ var _ dynamiclister.NamespaceLister = &dynamicNamespaceLister{}

// dynamicLister implements the Lister interface.
type dynamicLister struct {
indexer cache.Indexer
gvr schema.GroupVersionResource
cluster logicalcluster.Name
indexer cache.Indexer
gvr schema.GroupVersionResource
clusterName logicalcluster.Name
}

// List lists all resources in the indexer.
func (l *dynamicLister) List(selector labels.Selector) (ret []*unstructured.Unstructured, err error) {
selectAll := selector == nil || selector.Empty()

list, err := l.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ClusterIndexKey(l.cluster))
list, err := l.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ClusterIndexKey(l.clusterName))
if err != nil {
return nil, err
}
Expand All @@ -87,7 +87,7 @@ func (l *dynamicLister) List(selector labels.Selector) (ret []*unstructured.Unst

// Get retrieves a resource from the indexer with the given name
func (l *dynamicLister) Get(name string) (*unstructured.Unstructured, error) {
key := kcpcache.ToClusterAwareKey(l.cluster.String(), "", name)
key := kcpcache.ToClusterAwareKey(l.clusterName.String(), "", name)
obj, exists, err := l.indexer.GetByKey(key)
if err != nil {
return nil, err
Expand All @@ -100,15 +100,15 @@ func (l *dynamicLister) Get(name string) (*unstructured.Unstructured, error) {

// Namespace returns an object that can list and get resources from a given namespace.
func (l *dynamicLister) Namespace(namespace string) dynamiclister.NamespaceLister {
return &dynamicNamespaceLister{indexer: l.indexer, namespace: namespace, gvr: l.gvr, cluster: l.cluster}
return &dynamicNamespaceLister{indexer: l.indexer, namespace: namespace, gvr: l.gvr, clusterName: l.clusterName}
}

// dynamicNamespaceLister implements the NamespaceLister interface.
type dynamicNamespaceLister struct {
indexer cache.Indexer
namespace string
gvr schema.GroupVersionResource
cluster logicalcluster.Name
indexer cache.Indexer
namespace string
gvr schema.GroupVersionResource
clusterName logicalcluster.Name
}

// List lists all resources in the indexer for a given namespace.
Expand All @@ -117,9 +117,9 @@ func (l *dynamicNamespaceLister) List(selector labels.Selector) (ret []*unstruct

var list []interface{}
if l.namespace == metav1.NamespaceAll {
list, err = l.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ClusterIndexKey(l.cluster))
list, err = l.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ClusterIndexKey(l.clusterName))
} else {
list, err = l.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ClusterAndNamespaceIndexKey(l.cluster, l.namespace))
list, err = l.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ClusterAndNamespaceIndexKey(l.clusterName, l.namespace))
}
if err != nil {
return nil, err
Expand All @@ -140,7 +140,7 @@ func (l *dynamicNamespaceLister) List(selector labels.Selector) (ret []*unstruct

// Get retrieves a resource from the indexer for a given namespace and name.
func (l *dynamicNamespaceLister) Get(name string) (*unstructured.Unstructured, error) {
key := kcpcache.ToClusterAwareKey(l.cluster.String(), l.namespace, name)
key := kcpcache.ToClusterAwareKey(l.clusterName.String(), l.namespace, name)
obj, exists, err := l.indexer.GetByKey(key)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions dynamic/dynamiclister/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package dynamiclister

import (
kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
"github.com/kcp-dev/logicalcluster/v2"
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -51,6 +51,6 @@ func (s *dynamicClusterListerShim) List(selector labels.Selector) (ret []runtime
return ret, err
}

func (s *dynamicClusterListerShim) ByCluster(cluster logicalcluster.Name) cache.GenericLister {
return dynamiclister.NewRuntimeObjectShim(s.lister.Cluster(cluster))
func (s *dynamicClusterListerShim) ByCluster(clusterName logicalcluster.Name) cache.GenericLister {
return dynamiclister.NewRuntimeObjectShim(s.lister.Cluster(clusterName))
}
6 changes: 3 additions & 3 deletions dynamic/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package dynamic
import (
"context"

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

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -29,12 +29,12 @@ import (
)

type ClusterInterface interface {
Cluster(logicalcluster.Name) dynamic.Interface
Cluster(logicalcluster.Path) dynamic.Interface
Resource(resource schema.GroupVersionResource) ResourceClusterInterface
}

type ResourceClusterInterface interface {
Cluster(logicalcluster.Name) dynamic.NamespaceableResourceInterface
Cluster(logicalcluster.Path) dynamic.NamespaceableResourceInterface
List(ctx context.Context, opts metav1.ListOptions) (*unstructured.UnstructuredList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.18
require (
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/google/gnostic v0.5.7-v3refs
github.com/kcp-dev/apimachinery v0.0.0-20221102195355-d65878bc16be
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0
github.com/kcp-dev/logicalcluster/v3 v3.0.0
k8s.io/api v0.24.3
k8s.io/apimachinery v0.24.3
k8s.io/client-go v0.24.3
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,10 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kcp-dev/apimachinery v0.0.0-20221019133255-9e1e13940519 h1:eU1HvmmP8TbzS2pB9IX2Spky20n6V79/KgX4ssiG/A8=
github.com/kcp-dev/apimachinery v0.0.0-20221019133255-9e1e13940519/go.mod h1:qnvUHkdxOrNzX17yX+z8r81CZEBuFdveNzWqFlwZ55w=
github.com/kcp-dev/apimachinery v0.0.0-20221102195355-d65878bc16be h1:2uDzJ896+ojtzgr9HJL8+tZEoqhq8blwymGinWFrQ6E=
github.com/kcp-dev/apimachinery v0.0.0-20221102195355-d65878bc16be/go.mod h1:qnvUHkdxOrNzX17yX+z8r81CZEBuFdveNzWqFlwZ55w=
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1 h1:6EMfOioekQNrpcHEK7k2ANBWogFMlf+3xTB3CC4k+2s=
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1/go.mod h1:lfWJL764jKFJxZWOGuFuT3PCCLPo6lV5Cl8P7u9T05g=
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0 h1:fb+3CdDlxvnK+o1wm3IcDbD+MJndMUa17EUGqYORsvg=
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0/go.mod h1:dn1hXHMY9E6JbyOGa0qXt1Dq4akd/jHMZOpFhJoX7q4=
github.com/kcp-dev/logicalcluster/v3 v3.0.0 h1:tH6M2NuA11eLMsxii9IDOGo64X8B+P3e3pC6W2oEsx8=
github.com/kcp-dev/logicalcluster/v3 v3.0.0/go.mod h1:6rb68Tntup98cRr9+50rvSDxUbfqrC1yQ/T6RiZcSgA=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading