Skip to content

Commit f6e5a2f

Browse files
authored
Merge pull request kubernetes-sigs#13 from fabianvf/no-go-mod-changes
Drop use of kcp-dev fork of kubernetes
2 parents 6ae831c + 6a6baae commit f6e5a2f

File tree

13 files changed

+89
-74
lines changed

13 files changed

+89
-74
lines changed

go.mod

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/fsnotify/fsnotify v1.5.1
88
github.com/go-logr/logr v1.2.0
99
github.com/go-logr/zapr v1.2.0
10-
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55
10+
github.com/kcp-dev/apimachinery v0.0.0-20220621200107-3d03cbbc3770
1111
github.com/kcp-dev/logicalcluster v1.0.0
1212
github.com/onsi/ginkgo v1.16.5
1313
github.com/onsi/gomega v1.17.0
@@ -66,9 +66,3 @@ require (
6666
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
6767
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
6868
)
69-
70-
replace (
71-
k8s.io/api => github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf
72-
k8s.io/apimachinery => github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf
73-
k8s.io/client-go => github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf
74-
)

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
292292
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
293293
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
294294
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
295-
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55 h1:nwrXHxVkTQ9BI6slgqWgg8CVC+7AbJR02byYq+iBOUg=
296-
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55/go.mod h1:FIzhTU6DM3HYZhGv8w/1S/mbmSv1HzulZpjr/1/6i/I=
297-
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf h1:b3UxxmQEB0ZGXGmlGOhFPElpaLPoEEjNneH6ipn4WdE=
298-
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:YaTOAfRXJ+yMgQtYx2JxXdxGGoAonb1tg1rTLU0IT54=
299-
github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf h1:BiQgcrehqYiTG507kL3GFJtR5ni/fztwll9VodvlEd4=
300-
github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:O3MicknNAEIDH6QnfbYhov76VLccl2SLhbR1odSgttE=
301-
github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf h1:+8s2nSOTIZvG1kCxfDGQaq0aTkXJGsWhda1tyn3/bdc=
302-
github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:9wQfirZbMt4ylVsssW6p1Q1YUzB3Mk9LgcCzmExzE8A=
295+
github.com/kcp-dev/apimachinery v0.0.0-20220621200107-3d03cbbc3770 h1:vO2xIamfv7laTXwf8x+WZKugB1JTF62gHZgf+D0OY9E=
296+
github.com/kcp-dev/apimachinery v0.0.0-20220621200107-3d03cbbc3770/go.mod h1:FIzhTU6DM3HYZhGv8w/1S/mbmSv1HzulZpjr/1/6i/I=
303297
github.com/kcp-dev/logicalcluster v1.0.0 h1:qCnoUNaqJ0Tgefkj3vXn17EC76AP44WZwnIuHLw6yGQ=
304298
github.com/kcp-dev/logicalcluster v1.0.0/go.mod h1:M0CBFkJTW29XtIP5XIkDfhYQ8LU6HrnseRb4zmgBltE=
305299
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
@@ -931,9 +925,15 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
931925
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
932926
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
933927
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
928+
k8s.io/api v0.23.5 h1:zno3LUiMubxD/V1Zw3ijyKO3wxrhbUF1Ck+VjBvfaoA=
929+
k8s.io/api v0.23.5/go.mod h1:Na4XuKng8PXJ2JsploYYrivXrINeTaycCGcYgF91Xm8=
934930
k8s.io/apiextensions-apiserver v0.23.5 h1:5SKzdXyvIJKu+zbfPc3kCbWpbxi+O+zdmAJBm26UJqI=
935931
k8s.io/apiextensions-apiserver v0.23.5/go.mod h1:ntcPWNXS8ZPKN+zTXuzYMeg731CP0heCTl6gYBxLcuQ=
932+
k8s.io/apimachinery v0.23.5 h1:Va7dwhp8wgkUPWsEXk6XglXWU4IKYLKNlv8VkX7SDM0=
933+
k8s.io/apimachinery v0.23.5/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
936934
k8s.io/apiserver v0.23.5/go.mod h1:7wvMtGJ42VRxzgVI7jkbKvMbuCbVbgsWFT7RyXiRNTw=
935+
k8s.io/client-go v0.23.5 h1:zUXHmEuqx0RY4+CsnkOn5l0GU+skkRXKGJrhmE2SLd8=
936+
k8s.io/client-go v0.23.5/go.mod h1:flkeinTO1CirYgzMPRWxUCnV0G4Fbu2vLhYCObnt/r4=
937937
k8s.io/code-generator v0.23.5/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk=
938938
k8s.io/component-base v0.23.5 h1:8qgP5R6jG1BBSXmRYW+dsmitIrpk8F/fPEvgDenMCCE=
939939
k8s.io/component-base v0.23.5/go.mod h1:c5Nq44KZyt1aLl0IpHX82fhsn84Sb0jjzwjpcA42bY0=

pkg/cache/cache.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ type Options struct {
109109
// So that all informers will not send list requests simultaneously.
110110
Resync *time.Duration
111111

112-
// KeyFunction is the cache.KeyFunc that the informers will be configured to use.
113-
// Defaults to cache.MetaNamespaceKeyFunc from client-go
114-
KeyFunction cache.KeyFunc
112+
// NewInformerFunc is a function that is used to create SharedIndexInformers.
113+
// Defaults to cache.NewSharedIndexInformer from client-go
114+
NewInformerFunc client.NewInformerFunc
115115

116116
// Indexers is the indexers that the informers will be configured to use.
117117
// Will always have the standard NamespaceIndex.
@@ -155,7 +155,7 @@ func New(config *rest.Config, opts Options) (Cache, error) {
155155
if err != nil {
156156
return nil, err
157157
}
158-
im := internal.NewInformersMap(config, opts.Scheme, opts.Mapper, *opts.Resync, opts.Namespace, selectorsByGVK, disableDeepCopyByGVK, opts.KeyFunction, opts.Indexers)
158+
im := internal.NewInformersMap(config, opts.Scheme, opts.Mapper, *opts.Resync, opts.Namespace, selectorsByGVK, disableDeepCopyByGVK, opts.NewInformerFunc, opts.Indexers)
159159
return &informerCache{InformersMap: im}, nil
160160
}
161161

@@ -209,8 +209,8 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
209209
opts.Resync = &defaultResyncTime
210210
}
211211

212-
if opts.KeyFunction == nil {
213-
opts.KeyFunction = cache.MetaNamespaceKeyFunc
212+
if opts.NewInformerFunc == nil {
213+
opts.NewInformerFunc = cache.NewSharedIndexInformer
214214
}
215215
return opts, nil
216216
}

pkg/cache/internal/cache_reader.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
)
3838

39+
// TODO(KCP) need to implement and plumb through our own cache reader
40+
3941
// CacheReader is a client.Reader.
4042
var _ client.Reader = &CacheReader{}
4143

@@ -57,11 +59,11 @@ type CacheReader struct {
5759
}
5860

5961
// Get checks the indexer for the object and writes a copy of it if found.
60-
func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Object) error {
62+
func (c *CacheReader) Get(ctx context.Context, key client.ObjectKey, out client.Object) error {
6163
if c.scopeName == apimeta.RESTScopeNameRoot {
6264
key.Namespace = ""
6365
}
64-
storeKey := objectKeyToStoreKey(key)
66+
storeKey := objectKeyToStoreKey(ctx, key)
6567

6668
// Lookup the object from the indexer cache
6769
obj, exists, err := c.indexer.GetByKey(storeKey)
@@ -137,12 +139,18 @@ func (c *CacheReader) List(ctx context.Context, out client.ObjectList, opts ...c
137139
// namespaced index key. Otherwise, ask for the non-namespaced variant by using the fake "all namespaces"
138140
// namespace.
139141
objs, err = c.indexer.ByIndex(FieldIndexName(field), KeyToNamespacedKey(listOpts.Namespace, val))
140-
case listOpts.Cluster.Empty():
141-
objs = c.indexer.List()
142142
case listOpts.Namespace != "":
143-
objs, err = c.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), listOpts.Namespace, ""))
143+
if listOpts.Cluster.Empty() {
144+
objs, err = c.indexer.ByIndex(cache.NamespaceIndex, listOpts.Namespace)
145+
} else {
146+
objs, err = c.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), listOpts.Namespace, ""))
147+
}
144148
default:
145-
objs, err = c.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), "", ""))
149+
if listOpts.Cluster.Empty() {
150+
objs = c.indexer.List()
151+
} else {
152+
objs, err = c.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), "", ""))
153+
}
146154
}
147155
if err != nil {
148156
return err
@@ -194,8 +202,16 @@ func (c *CacheReader) List(ctx context.Context, out client.ObjectList, opts ...c
194202
// It's akin to MetaNamespaceKeyFunc. It's separate from
195203
// String to allow keeping the key format easily in sync with
196204
// MetaNamespaceKeyFunc.
197-
func objectKeyToStoreKey(k client.ObjectKey) string {
198-
return kcpcache.ToClusterAwareKey(k.Cluster.String(), k.Namespace, k.Name)
205+
func objectKeyToStoreKey(ctx context.Context, k client.ObjectKey) string {
206+
cluster, ok := kcpclient.ClusterFromContext(ctx)
207+
if ok {
208+
return kcpcache.ToClusterAwareKey(cluster.String(), k.Namespace, k.Name)
209+
}
210+
211+
if k.Namespace == "" {
212+
return k.Name
213+
}
214+
return k.Namespace + "/" + k.Name
199215
}
200216

201217
// requiresExactMatch checks if the given field selector is of the form `k=v` or `k==v`.

pkg/cache/internal/deleg_map.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"k8s.io/apimachinery/pkg/runtime/schema"
2828
"k8s.io/client-go/rest"
2929
"k8s.io/client-go/tools/cache"
30+
31+
"sigs.k8s.io/controller-runtime/pkg/client"
3032
)
3133

3234
// InformersMap create and caches Informers for (runtime.Object, schema.GroupVersionKind) pairs.
@@ -52,13 +54,13 @@ func NewInformersMap(config *rest.Config,
5254
namespace string,
5355
selectors SelectorsByGVK,
5456
disableDeepCopy DisableDeepCopyByGVK,
55-
keyFunc cache.KeyFunc,
57+
newInformerFunc client.NewInformerFunc,
5658
indexers cache.Indexers,
5759
) *InformersMap {
5860
return &InformersMap{
59-
structured: newStructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, keyFunc, indexers),
60-
unstructured: newUnstructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, keyFunc, indexers),
61-
metadata: newMetadataInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, keyFunc, indexers),
61+
structured: newStructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, newInformerFunc, indexers),
62+
unstructured: newUnstructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, newInformerFunc, indexers),
63+
metadata: newMetadataInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, newInformerFunc, indexers),
6264

6365
Scheme: scheme,
6466
}
@@ -110,18 +112,18 @@ func (m *InformersMap) Get(ctx context.Context, gvk schema.GroupVersionKind, obj
110112

111113
// newStructuredInformersMap creates a new InformersMap for structured objects.
112114
func newStructuredInformersMap(config *rest.Config, scheme *runtime.Scheme, mapper meta.RESTMapper, resync time.Duration,
113-
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, keyFunc cache.KeyFunc, indexers cache.Indexers) *specificInformersMap {
114-
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createStructuredListWatch, keyFunc, indexers)
115+
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, newInformerFunc client.NewInformerFunc, indexers cache.Indexers) *specificInformersMap {
116+
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createStructuredListWatch, newInformerFunc, indexers)
115117
}
116118

117119
// newUnstructuredInformersMap creates a new InformersMap for unstructured objects.
118120
func newUnstructuredInformersMap(config *rest.Config, scheme *runtime.Scheme, mapper meta.RESTMapper, resync time.Duration,
119-
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, keyFunc cache.KeyFunc, indexers cache.Indexers) *specificInformersMap {
120-
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createUnstructuredListWatch, keyFunc, indexers)
121+
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, newInformerFunc client.NewInformerFunc, indexers cache.Indexers) *specificInformersMap {
122+
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createUnstructuredListWatch, newInformerFunc, indexers)
121123
}
122124

123125
// newMetadataInformersMap creates a new InformersMap for metadata-only objects.
124126
func newMetadataInformersMap(config *rest.Config, scheme *runtime.Scheme, mapper meta.RESTMapper, resync time.Duration,
125-
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, keyFunc cache.KeyFunc, indexers cache.Indexers) *specificInformersMap {
126-
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createMetadataListWatch, keyFunc, indexers)
127+
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, newInformerFunc client.NewInformerFunc, indexers cache.Indexers) *specificInformersMap {
128+
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createMetadataListWatch, newInformerFunc, indexers)
127129
}

pkg/cache/internal/informers_map.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"k8s.io/client-go/rest"
3636
"k8s.io/client-go/tools/cache"
3737

38+
"sigs.k8s.io/controller-runtime/pkg/client"
3839
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
3940
)
4041

@@ -55,7 +56,7 @@ func newSpecificInformersMap(config *rest.Config,
5556
selectors SelectorsByGVK,
5657
disableDeepCopy DisableDeepCopyByGVK,
5758
createListWatcher createListWatcherFunc,
58-
keyFunction cache.KeyFunc,
59+
newInformerFunc client.NewInformerFunc,
5960
indexers cache.Indexers) *specificInformersMap {
6061

6162
ip := &specificInformersMap{
@@ -71,7 +72,7 @@ func newSpecificInformersMap(config *rest.Config,
7172
namespace: namespace,
7273
selectors: selectors.forGVK,
7374
disableDeepCopy: disableDeepCopy,
74-
keyFunction: keyFunction,
75+
newInformerFunc: newInformerFunc,
7576
additionalIndexers: indexers,
7677
}
7778
return ip
@@ -147,6 +148,8 @@ type specificInformersMap struct {
147148
// additionalIndexers is the indexers that the informers will be configured to use.
148149
// Will not allow overwriting the standard NamespaceIndex.
149150
additionalIndexers cache.Indexers
151+
152+
newInformerFunc client.NewInformerFunc
150153
}
151154

152155
// Start calls Run on each of the informers and sets started to true. Blocks on the context.
@@ -242,10 +245,8 @@ func (ip *specificInformersMap) addInformerToMap(gvk schema.GroupVersionKind, ob
242245
}
243246
indexers[cache.NamespaceIndex] = cache.MetaNamespaceIndexFunc
244247

245-
ni := cache.NewSharedIndexInformerWithOptions(lw, obj,
246-
cache.WithResyncPeriod(resyncPeriod(ip.resync)()),
247-
cache.WithKeyFunction(ip.keyFunction),
248-
cache.WithIndexers(indexers))
248+
ni := ip.newInformerFunc(lw, obj, resyncPeriod(ip.resync)(), indexers)
249+
249250
rm, err := ip.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
250251
if err != nil {
251252
return nil, false, err

pkg/client/interfaces.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,22 @@ package client
1818

1919
import (
2020
"context"
21-
22-
"github.com/kcp-dev/logicalcluster"
21+
"time"
2322

2423
apierrors "k8s.io/apimachinery/pkg/api/errors"
24+
"k8s.io/client-go/tools/cache"
2525

2626
"k8s.io/apimachinery/pkg/api/meta"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
"k8s.io/apimachinery/pkg/types"
2929
"k8s.io/apimachinery/pkg/watch"
3030
)
3131

32-
type ObjectKey struct {
33-
types.NamespacedName
34-
35-
Cluster logicalcluster.Name
36-
}
32+
type ObjectKey = types.NamespacedName
3733

3834
// ObjectKeyFromObject returns the ObjectKey given a runtime.Object.
3935
func ObjectKeyFromObject(obj Object) ObjectKey {
40-
return ObjectKey{NamespacedName: types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, Cluster: logicalcluster.From(obj)}
36+
return ObjectKey{Namespace: obj.GetNamespace(), Name: obj.GetName()}
4137
}
4238

4339
// Patch is a patch that can be applied to a Kubernetes object.
@@ -48,6 +44,10 @@ type Patch interface {
4844
Data(obj Object) ([]byte, error)
4945
}
5046

47+
// NewInformerFunc describes a function that creates SharedIndexInformers.
48+
// Its signature matches cache.NewSharedIndexInformer from client-go
49+
type NewInformerFunc func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer
50+
5151
// TODO(directxman12): is there a sane way to deal with get/delete options?
5252

5353
// Reader knows how to read and list Kubernetes objects.

pkg/envtest/crd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefin
253253
crd := crd
254254
log.V(1).Info("installing CRD", "crd", crd.GetName())
255255
existingCrd := crd.DeepCopy()
256-
err := cs.Get(context.TODO(), client.ObjectKey{NamespacedName: types.NamespacedName{Name: crd.GetName()}}, existingCrd)
256+
err := cs.Get(context.TODO(), types.NamespacedName{Name: crd.GetName()}, existingCrd)
257257
switch {
258258
case apierrors.IsNotFound(err):
259259
if err := cs.Create(context.TODO(), crd); err != nil {
@@ -264,7 +264,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefin
264264
default:
265265
log.V(1).Info("CRD already exists, updating", "crd", crd.GetName())
266266
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
267-
if err := cs.Get(context.TODO(), client.ObjectKey{NamespacedName: types.NamespacedName{Name: crd.GetName()}}, existingCrd); err != nil {
267+
if err := cs.Get(context.TODO(), types.NamespacedName{Name: crd.GetName()}, existingCrd); err != nil {
268268
return err
269269
}
270270
crd.SetResourceVersion(existingCrd.GetResourceVersion())

pkg/envtest/webhook.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,9 @@ func (p *webhookPoller) poll() (done bool, err error) {
234234
for _, name := range names.List() {
235235
var obj = &unstructured.Unstructured{}
236236
obj.SetGroupVersionKind(gvk)
237-
err := c.Get(context.Background(), client.ObjectKey{
238-
NamespacedName: types.NamespacedName{
239-
Namespace: "",
240-
Name: name,
241-
},
237+
err := c.Get(context.Background(), types.NamespacedName{
238+
Namespace: "",
239+
Name: name,
242240
}, obj)
243241

244242
if err == nil {
@@ -318,7 +316,7 @@ func createWebhooks(config *rest.Config, mutHooks []*admissionv1.MutatingWebhook
318316
// ensureCreated creates or update object if already exists in the cluster.
319317
func ensureCreated(cs client.Client, obj client.Object) error {
320318
existing := obj.DeepCopyObject().(client.Object)
321-
err := cs.Get(context.Background(), client.ObjectKey{NamespacedName: types.NamespacedName{Name: obj.GetName()}}, existing)
319+
err := cs.Get(context.Background(), types.NamespacedName{Name: obj.GetName()}, existing)
322320
switch {
323321
case apierrors.IsNotFound(err):
324322
if err := cs.Create(context.Background(), obj); err != nil {

pkg/handler/enqueue.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ func (e *EnqueueRequestForObject) Generic(evt event.GenericEvent, q workqueue.Ra
7777
}
7878

7979
func request(obj client.Object) reconcile.Request {
80-
return reconcile.Request{client.ObjectKey{
81-
Cluster: logicalcluster.From(obj),
80+
return reconcile.Request{
81+
// TODO(kcp) Need to implement a non-kcp-specific way to support this
82+
ClusterName: logicalcluster.From(obj).String(),
8283
NamespacedName: types.NamespacedName{
8384
Namespace: obj.GetNamespace(),
8485
Name: obj.GetName(),
8586
},
86-
}}
87+
}
8788
}

pkg/handler/enqueue_owner.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"k8s.io/apimachinery/pkg/runtime/schema"
2727
"k8s.io/apimachinery/pkg/types"
2828
"k8s.io/client-go/util/workqueue"
29-
"sigs.k8s.io/controller-runtime/pkg/client"
3029
"sigs.k8s.io/controller-runtime/pkg/event"
3130
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
3231
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -137,11 +136,9 @@ func (e *EnqueueRequestForOwner) getOwnerReconcileRequest(object metav1.Object,
137136
if ref.Kind == e.groupKind.Kind && refGV.Group == e.groupKind.Group {
138137
// Match found - add a Request for the object referred to in the OwnerReference
139138
request := reconcile.Request{
140-
ObjectKey: client.ObjectKey{
141-
Cluster: logicalcluster.From(object),
142-
NamespacedName: types.NamespacedName{
143-
Name: ref.Name,
144-
},
139+
ClusterName: logicalcluster.From(object).String(),
140+
NamespacedName: types.NamespacedName{
141+
Name: ref.Name,
145142
},
146143
}
147144

pkg/kcp/wrappers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333

3434
kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
3535
kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
36+
"github.com/kcp-dev/apimachinery/third_party/informers"
3637
)
3738

3839
// NewClusterAwareManager returns a kcp-aware manager with appropriate defaults for cache and
@@ -57,7 +58,8 @@ func NewClusterAwareManager(cfg *rest.Config, options ctrl.Options) (manager.Man
5758
func NewClusterAwareCache(config *rest.Config, opts cache.Options) (cache.Cache, error) {
5859
c := rest.CopyConfig(config)
5960
c.Host += "/clusters/*"
60-
opts.KeyFunction = kcpcache.ClusterAwareKeyFunc
61+
opts.NewInformerFunc = informers.NewSharedIndexInformer
62+
6163
opts.Indexers = k8scache.Indexers{
6264
kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc,
6365
kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc,

0 commit comments

Comments
 (0)