Skip to content

Commit 0097020

Browse files
Merge pull request #65 from p0lyn0mial/logicalcluster-v3
🌱 switch to logicalcluster.v3
2 parents d65878b + 703fb98 commit 0097020

15 files changed

+85
-88
lines changed

go.mod

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
1-
// This is a generated file. Do not edit directly.
2-
3-
module github.com/kcp-dev/apimachinery
1+
module github.com/kcp-dev/apimachinery/v2
42

53
go 1.18
64

75
require (
8-
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1
6+
github.com/google/go-cmp v0.5.5
7+
github.com/kcp-dev/logicalcluster/v3 v3.0.0
98
github.com/stretchr/testify v1.7.1
9+
k8s.io/api v0.24.3
1010
k8s.io/apimachinery v0.24.3
1111
k8s.io/client-go v0.24.3
1212
k8s.io/klog/v2 v2.60.1
1313
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
1414
)
1515

1616
require (
17-
github.com/PuerkitoBio/purell v1.1.1 // indirect
18-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
1917
github.com/davecgh/go-spew v1.1.1 // indirect
20-
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
2118
github.com/go-logr/logr v1.2.0 // indirect
22-
github.com/go-openapi/jsonpointer v0.19.5 // indirect
23-
github.com/go-openapi/jsonreference v0.19.5 // indirect
24-
github.com/go-openapi/swag v0.19.14 // indirect
2519
github.com/gogo/protobuf v1.3.2 // indirect
2620
github.com/golang/protobuf v1.5.2 // indirect
27-
github.com/google/gnostic v0.5.7-v3refs // indirect
28-
github.com/google/go-cmp v0.5.5 // indirect
2921
github.com/google/gofuzz v1.1.0 // indirect
30-
github.com/josharian/intern v1.0.0 // indirect
3122
github.com/json-iterator/go v1.1.12 // indirect
32-
github.com/mailru/easyjson v0.7.6 // indirect
3323
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3424
github.com/modern-go/reflect2 v1.0.2 // indirect
35-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3625
github.com/pmezard/go-difflib v1.0.0 // indirect
3726
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
3827
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
@@ -45,8 +34,6 @@ require (
4534
gopkg.in/inf.v0 v0.9.1 // indirect
4635
gopkg.in/yaml.v2 v2.4.0 // indirect
4736
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
48-
k8s.io/api v0.24.3 // indirect
49-
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
5037
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
5138
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
5239
sigs.k8s.io/yaml v1.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
186186
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
187187
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
188188
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
189-
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1 h1:6EMfOioekQNrpcHEK7k2ANBWogFMlf+3xTB3CC4k+2s=
190-
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1/go.mod h1:lfWJL764jKFJxZWOGuFuT3PCCLPo6lV5Cl8P7u9T05g=
189+
github.com/kcp-dev/logicalcluster/v3 v3.0.0 h1:tH6M2NuA11eLMsxii9IDOGo64X8B+P3e3pC6W2oEsx8=
190+
github.com/kcp-dev/logicalcluster/v3 v3.0.0/go.mod h1:6rb68Tntup98cRr9+50rvSDxUbfqrC1yQ/T6RiZcSgA=
191191
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
192192
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
193193
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

pkg/cache/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ package cache
1919
import (
2020
"fmt"
2121

22-
"github.com/kcp-dev/logicalcluster/v2"
22+
"github.com/kcp-dev/logicalcluster/v3"
23+
2324
"k8s.io/apimachinery/pkg/api/meta"
2425
)
2526

pkg/cache/controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package cache
1919
import (
2020
"testing"
2121

22-
"github.com/kcp-dev/logicalcluster/v2"
22+
"github.com/kcp-dev/logicalcluster/v3"
2323
"github.com/stretchr/testify/require"
24+
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
)
2627

pkg/cache/informers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ limitations under the License.
1717
package cache
1818

1919
import (
20-
"github.com/kcp-dev/logicalcluster/v2"
20+
"github.com/kcp-dev/logicalcluster/v3"
21+
2122
"k8s.io/client-go/tools/cache"
2223
)
2324

2425
// ScopeableSharedIndexInformer is an informer that knows how to scope itself down to one cluster,
2526
// or act as an informer across clusters.
2627
type ScopeableSharedIndexInformer interface {
27-
Cluster(cluster logicalcluster.Name) cache.SharedIndexInformer
28+
Cluster(clusterName logicalcluster.Name) cache.SharedIndexInformer
2829
cache.SharedIndexInformer
2930
}

pkg/cache/keyfunc.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
"fmt"
2121
"strings"
2222

23-
"github.com/kcp-dev/logicalcluster/v2"
23+
"github.com/kcp-dev/logicalcluster/v3"
24+
2425
"k8s.io/apimachinery/pkg/api/meta"
2526
"k8s.io/client-go/tools/cache"
2627
)
@@ -75,14 +76,14 @@ func SplitMetaClusterNamespaceKey(key string) (clusterName logicalcluster.Name,
7576
if err != nil {
7677
err = invalidKey
7778
}
78-
return logicalcluster.Name{}, namespace, name, err
79+
return "", namespace, name, err
7980
case 2:
8081
namespace, name, err := cache.SplitMetaNamespaceKey(outerParts[1])
8182
if err != nil {
8283
err = invalidKey
8384
}
84-
return logicalcluster.New(outerParts[0]), namespace, name, err
85+
return logicalcluster.Name(outerParts[0]), namespace, name, err
8586
default:
86-
return logicalcluster.Name{}, "", "", invalidKey
87+
return "", "", "", invalidKey
8788
}
8889
}

pkg/cache/keyfunc_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
"testing"
2222

2323
"github.com/google/go-cmp/cmp"
24-
"github.com/kcp-dev/logicalcluster/v2"
24+
"github.com/kcp-dev/logicalcluster/v3"
25+
2526
corev1 "k8s.io/api/core/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/client-go/tools/cache"
@@ -156,14 +157,14 @@ func TestSplitMetaClusterNamespaceKey(t *testing.T) {
156157
{
157158
name: "fully populated key",
158159
key: "clusterName|namespace/name",
159-
expectedCluster: logicalcluster.New("clusterName"),
160+
expectedCluster: logicalcluster.Name("clusterName"),
160161
expectedNamespace: "namespace",
161162
expectedName: "name",
162163
},
163164
{
164165
name: "cluster-scoped resource",
165166
key: "clusterName|name",
166-
expectedCluster: logicalcluster.New("clusterName"),
167+
expectedCluster: logicalcluster.Name("clusterName"),
167168
expectedName: "name",
168169
},
169170
{
@@ -185,7 +186,7 @@ func TestSplitMetaClusterNamespaceKey(t *testing.T) {
185186
{
186187
name: "valid cluster, invalid key",
187188
key: "root:something|//2",
188-
expectedCluster: logicalcluster.New("root:something"),
189+
expectedCluster: logicalcluster.Name("root:something"),
189190
expectedErr: errors.New(`unexpected key format: "root:something|//2"`),
190191
},
191192
}
@@ -196,7 +197,7 @@ func TestSplitMetaClusterNamespaceKey(t *testing.T) {
196197
t.Errorf("%s: invalid error: %v", testCase.name, diff)
197198
return
198199
}
199-
if diff := cmp.Diff(actualCluster, testCase.expectedCluster, cmp.AllowUnexported(logicalcluster.Name{})); diff != "" {
200+
if diff := cmp.Diff(actualCluster, testCase.expectedCluster); diff != "" {
200201
t.Errorf("%s: invalid cluster: %v", testCase.name, diff)
201202
}
202203
if diff := cmp.Diff(actualNamespace, testCase.expectedNamespace); diff != "" {

pkg/cache/listers.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@ limitations under the License.
1717
package cache
1818

1919
import (
20-
"github.com/kcp-dev/logicalcluster/v2"
21-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
"k8s.io/apimachinery/pkg/util/sets"
23-
"k8s.io/klog/v2"
20+
"github.com/kcp-dev/logicalcluster/v3"
2421

2522
"k8s.io/apimachinery/pkg/api/errors"
2623
"k8s.io/apimachinery/pkg/api/meta"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2725
"k8s.io/apimachinery/pkg/labels"
2826
"k8s.io/apimachinery/pkg/runtime"
2927
"k8s.io/apimachinery/pkg/runtime/schema"
28+
"k8s.io/apimachinery/pkg/util/sets"
3029
"k8s.io/client-go/tools/cache"
30+
"k8s.io/klog/v2"
3131
)
3232

3333
// ListAllByCluster used to list items belongs to a cluster from Indexer.
34-
func ListAllByCluster(indexer cache.Indexer, cluster logicalcluster.Name, selector labels.Selector, appendFn cache.AppendFunc) error {
35-
return listAllByIndexWithBackup(indexer, ClusterIndexName, ClusterIndexKey(cluster), ClusterIndexFunc, selector, appendFn)
34+
func ListAllByCluster(indexer cache.Indexer, clusterName logicalcluster.Name, selector labels.Selector, appendFn cache.AppendFunc) error {
35+
return listAllByIndexWithBackup(indexer, ClusterIndexName, ClusterIndexKey(clusterName), ClusterIndexFunc, selector, appendFn)
3636
}
3737

3838
// ListAllByClusterAndNamespace used to list items belongs to a cluster and namespace from Indexer.
39-
func ListAllByClusterAndNamespace(indexer cache.Indexer, cluster logicalcluster.Name, namespace string, selector labels.Selector, appendFn cache.AppendFunc) error {
39+
func ListAllByClusterAndNamespace(indexer cache.Indexer, clusterName logicalcluster.Name, namespace string, selector labels.Selector, appendFn cache.AppendFunc) error {
4040
if namespace == metav1.NamespaceAll {
41-
return ListAllByCluster(indexer, cluster, selector, appendFn)
41+
return ListAllByCluster(indexer, clusterName, selector, appendFn)
4242
}
43-
return listAllByIndexWithBackup(indexer, ClusterAndNamespaceIndexName, ClusterAndNamespaceIndexKey(cluster, namespace), ClusterAndNamespaceIndexFunc, selector, appendFn)
43+
return listAllByIndexWithBackup(indexer, ClusterAndNamespaceIndexName, ClusterAndNamespaceIndexKey(clusterName, namespace), ClusterAndNamespaceIndexFunc, selector, appendFn)
4444
}
4545

4646
// listAllByIndexWithBackup used to list items from the Indexer using an index, or falling back to a func if no index is registered.
@@ -99,7 +99,7 @@ type GenericClusterLister interface {
9999
// List will return all objects across logical clusters and all namespaces
100100
List(selector labels.Selector) (ret []runtime.Object, err error)
101101
// ByCluster will give you a cache.GenericLister for one logical cluster
102-
ByCluster(cluster logicalcluster.Name) cache.GenericLister
102+
ByCluster(clusterName logicalcluster.Name) cache.GenericLister
103103
}
104104

105105
// ClusterLister is a lister that supports multiple logical clusters. It can list the entire contents of the backing store, and return individual cache.GenericListers that are scoped to individual logical clusters.
@@ -118,29 +118,29 @@ func (s *ClusterLister) List(selector labels.Selector) (ret []runtime.Object, er
118118
return ret, err
119119
}
120120

121-
func (s *ClusterLister) ByCluster(cluster logicalcluster.Name) cache.GenericLister {
121+
func (s *ClusterLister) ByCluster(clusterName logicalcluster.Name) cache.GenericLister {
122122
return &genericLister{
123-
indexer: s.indexer,
124-
resource: s.resource,
125-
cluster: cluster,
123+
indexer: s.indexer,
124+
resource: s.resource,
125+
clusterName: clusterName,
126126
}
127127
}
128128

129129
type genericLister struct {
130-
indexer cache.Indexer
131-
cluster logicalcluster.Name
132-
resource schema.GroupResource
130+
indexer cache.Indexer
131+
clusterName logicalcluster.Name
132+
resource schema.GroupResource
133133
}
134134

135135
func (s *genericLister) List(selector labels.Selector) (ret []runtime.Object, err error) {
136-
err = ListAllByCluster(s.indexer, s.cluster, selector, func(i interface{}) {
136+
err = ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) {
137137
ret = append(ret, i.(runtime.Object))
138138
})
139139
return ret, err
140140
}
141141

142142
func (s *genericLister) Get(name string) (runtime.Object, error) {
143-
key := ToClusterAwareKey(s.cluster.String(), "", name)
143+
key := ToClusterAwareKey(s.clusterName.String(), "", name)
144144
obj, exists, err := s.indexer.GetByKey(key)
145145
if err != nil {
146146
return nil, err
@@ -156,7 +156,7 @@ func (s *genericLister) ByNamespace(namespace string) cache.GenericNamespaceList
156156
indexer: s.indexer,
157157
namespace: namespace,
158158
resource: s.resource,
159-
cluster: s.cluster,
159+
cluster: s.clusterName,
160160
}
161161
}
162162

pkg/cache/listers_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package cache
1919
import (
2020
"testing"
2121

22-
"github.com/kcp-dev/logicalcluster/v2"
22+
"github.com/kcp-dev/logicalcluster/v3"
2323
"github.com/stretchr/testify/require"
24+
2425
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2526
"k8s.io/apimachinery/pkg/labels"
2627
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -112,7 +113,7 @@ func TestGenericLister(t *testing.T) {
112113

113114
for name, tt := range tests {
114115
t.Run(name, func(t *testing.T) {
115-
lister := l.ByCluster(logicalcluster.New(tt.cluster))
116+
lister := l.ByCluster(logicalcluster.Name(tt.cluster))
116117

117118
if tt.name == "" {
118119
list, err := lister.List(tt.selector)
@@ -151,7 +152,7 @@ func TestGenericNamespaceLister(t *testing.T) {
151152

152153
cluster := "c1"
153154

154-
l := NewGenericClusterLister(indexer, schema.GroupResource{}).ByCluster(logicalcluster.New(cluster))
155+
l := NewGenericClusterLister(indexer, schema.GroupResource{}).ByCluster(logicalcluster.Name(cluster))
155156

156157
tests := map[string]struct {
157158
namespace string

pkg/client/cluster_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package client
1919
import (
2020
"net/http"
2121

22-
"github.com/kcp-dev/logicalcluster/v2"
22+
"github.com/kcp-dev/logicalcluster/v3"
2323

2424
"k8s.io/client-go/rest"
2525
)
@@ -40,7 +40,7 @@ func SetMultiClusterRoundTripper(cfg *rest.Config) *rest.Config {
4040
// cluster endpoint.
4141
//
4242
// Note: it is the caller responsibility to make a copy of the rest config
43-
func SetCluster(cfg *rest.Config, clusterName logicalcluster.Name) *rest.Config {
44-
cfg.Host = cfg.Host + clusterName.Path()
43+
func SetCluster(cfg *rest.Config, clusterPath logicalcluster.Path) *rest.Config {
44+
cfg.Host = cfg.Host + clusterPath.RequestPath()
4545
return cfg
4646
}

0 commit comments

Comments
 (0)