Skip to content

Drop use of kcp-dev fork of kubernetes #13

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
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1
github.com/go-logr/logr v1.2.0
github.com/go-logr/zapr v1.2.0
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55
github.com/kcp-dev/apimachinery v0.0.0-20220621200107-3d03cbbc3770
github.com/kcp-dev/logicalcluster v1.0.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.17.0
Expand Down Expand Up @@ -66,9 +66,3 @@ require (
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

replace (
k8s.io/api => github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf
k8s.io/apimachinery => github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf
k8s.io/client-go => github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55 h1:nwrXHxVkTQ9BI6slgqWgg8CVC+7AbJR02byYq+iBOUg=
github.com/kcp-dev/apimachinery v0.0.0-20220518152549-f62703561e55/go.mod h1:FIzhTU6DM3HYZhGv8w/1S/mbmSv1HzulZpjr/1/6i/I=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf h1:b3UxxmQEB0ZGXGmlGOhFPElpaLPoEEjNneH6ipn4WdE=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:YaTOAfRXJ+yMgQtYx2JxXdxGGoAonb1tg1rTLU0IT54=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf h1:BiQgcrehqYiTG507kL3GFJtR5ni/fztwll9VodvlEd4=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:O3MicknNAEIDH6QnfbYhov76VLccl2SLhbR1odSgttE=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf h1:+8s2nSOTIZvG1kCxfDGQaq0aTkXJGsWhda1tyn3/bdc=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/client-go v0.0.0-20220524063253-5bb0eeecf2cf/go.mod h1:9wQfirZbMt4ylVsssW6p1Q1YUzB3Mk9LgcCzmExzE8A=
github.com/kcp-dev/apimachinery v0.0.0-20220621200107-3d03cbbc3770 h1:vO2xIamfv7laTXwf8x+WZKugB1JTF62gHZgf+D0OY9E=
github.com/kcp-dev/apimachinery v0.0.0-20220621200107-3d03cbbc3770/go.mod h1:FIzhTU6DM3HYZhGv8w/1S/mbmSv1HzulZpjr/1/6i/I=
github.com/kcp-dev/logicalcluster v1.0.0 h1:qCnoUNaqJ0Tgefkj3vXn17EC76AP44WZwnIuHLw6yGQ=
github.com/kcp-dev/logicalcluster v1.0.0/go.mod h1:M0CBFkJTW29XtIP5XIkDfhYQ8LU6HrnseRb4zmgBltE=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down Expand Up @@ -931,9 +925,15 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.23.5 h1:zno3LUiMubxD/V1Zw3ijyKO3wxrhbUF1Ck+VjBvfaoA=
k8s.io/api v0.23.5/go.mod h1:Na4XuKng8PXJ2JsploYYrivXrINeTaycCGcYgF91Xm8=
k8s.io/apiextensions-apiserver v0.23.5 h1:5SKzdXyvIJKu+zbfPc3kCbWpbxi+O+zdmAJBm26UJqI=
k8s.io/apiextensions-apiserver v0.23.5/go.mod h1:ntcPWNXS8ZPKN+zTXuzYMeg731CP0heCTl6gYBxLcuQ=
k8s.io/apimachinery v0.23.5 h1:Va7dwhp8wgkUPWsEXk6XglXWU4IKYLKNlv8VkX7SDM0=
k8s.io/apimachinery v0.23.5/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
k8s.io/apiserver v0.23.5/go.mod h1:7wvMtGJ42VRxzgVI7jkbKvMbuCbVbgsWFT7RyXiRNTw=
k8s.io/client-go v0.23.5 h1:zUXHmEuqx0RY4+CsnkOn5l0GU+skkRXKGJrhmE2SLd8=
k8s.io/client-go v0.23.5/go.mod h1:flkeinTO1CirYgzMPRWxUCnV0G4Fbu2vLhYCObnt/r4=
k8s.io/code-generator v0.23.5/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk=
k8s.io/component-base v0.23.5 h1:8qgP5R6jG1BBSXmRYW+dsmitIrpk8F/fPEvgDenMCCE=
k8s.io/component-base v0.23.5/go.mod h1:c5Nq44KZyt1aLl0IpHX82fhsn84Sb0jjzwjpcA42bY0=
Expand Down
12 changes: 6 additions & 6 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ type Options struct {
// So that all informers will not send list requests simultaneously.
Resync *time.Duration

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

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

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

if opts.KeyFunction == nil {
opts.KeyFunction = cache.MetaNamespaceKeyFunc
if opts.NewInformerFunc == nil {
opts.NewInformerFunc = cache.NewSharedIndexInformer
}
return opts, nil
}
Expand Down
32 changes: 24 additions & 8 deletions pkg/cache/internal/cache_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// TODO(KCP) need to implement and plumb through our own cache reader

// CacheReader is a client.Reader.
var _ client.Reader = &CacheReader{}

Expand All @@ -57,11 +59,11 @@ type CacheReader struct {
}

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

// Lookup the object from the indexer cache
obj, exists, err := c.indexer.GetByKey(storeKey)
Expand Down Expand Up @@ -137,12 +139,18 @@ func (c *CacheReader) List(ctx context.Context, out client.ObjectList, opts ...c
// namespaced index key. Otherwise, ask for the non-namespaced variant by using the fake "all namespaces"
// namespace.
objs, err = c.indexer.ByIndex(FieldIndexName(field), KeyToNamespacedKey(listOpts.Namespace, val))
case listOpts.Cluster.Empty():
objs = c.indexer.List()
case listOpts.Namespace != "":
objs, err = c.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), listOpts.Namespace, ""))
if listOpts.Cluster.Empty() {
objs, err = c.indexer.ByIndex(cache.NamespaceIndex, listOpts.Namespace)
} else {
objs, err = c.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), listOpts.Namespace, ""))
}
default:
objs, err = c.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), "", ""))
if listOpts.Cluster.Empty() {
objs = c.indexer.List()
} else {
objs, err = c.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ToClusterAwareKey(listOpts.Cluster.String(), "", ""))
}
}
if err != nil {
return err
Expand Down Expand Up @@ -194,8 +202,16 @@ func (c *CacheReader) List(ctx context.Context, out client.ObjectList, opts ...c
// It's akin to MetaNamespaceKeyFunc. It's separate from
// String to allow keeping the key format easily in sync with
// MetaNamespaceKeyFunc.
func objectKeyToStoreKey(k client.ObjectKey) string {
return kcpcache.ToClusterAwareKey(k.Cluster.String(), k.Namespace, k.Name)
func objectKeyToStoreKey(ctx context.Context, k client.ObjectKey) string {
cluster, ok := kcpclient.ClusterFromContext(ctx)
if ok {
return kcpcache.ToClusterAwareKey(cluster.String(), k.Namespace, k.Name)
}
Comment on lines +206 to +209

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should support also the case when the context doesn't have the cluster set - in other words in a standard K8s/OpenShift environment. However, I'm afraid that it won't work if the cache reader still depends on the different keys. See the changes in my PR: #14

Copy link

@johnmcollier johnmcollier Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, assuming this works, this should unblock me.


if k.Namespace == "" {
return k.Name
}
return k.Namespace + "/" + k.Name
}

// requiresExactMatch checks if the given field selector is of the form `k=v` or `k==v`.
Expand Down
22 changes: 12 additions & 10 deletions pkg/cache/internal/deleg_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"

"sigs.k8s.io/controller-runtime/pkg/client"
)

// InformersMap create and caches Informers for (runtime.Object, schema.GroupVersionKind) pairs.
Expand All @@ -52,13 +54,13 @@ func NewInformersMap(config *rest.Config,
namespace string,
selectors SelectorsByGVK,
disableDeepCopy DisableDeepCopyByGVK,
keyFunc cache.KeyFunc,
newInformerFunc client.NewInformerFunc,
indexers cache.Indexers,
) *InformersMap {
return &InformersMap{
structured: newStructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, keyFunc, indexers),
unstructured: newUnstructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, keyFunc, indexers),
metadata: newMetadataInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, keyFunc, indexers),
structured: newStructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, newInformerFunc, indexers),
unstructured: newUnstructuredInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, newInformerFunc, indexers),
metadata: newMetadataInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, newInformerFunc, indexers),

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

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

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

// newMetadataInformersMap creates a new InformersMap for metadata-only objects.
func newMetadataInformersMap(config *rest.Config, scheme *runtime.Scheme, mapper meta.RESTMapper, resync time.Duration,
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, keyFunc cache.KeyFunc, indexers cache.Indexers) *specificInformersMap {
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createMetadataListWatch, keyFunc, indexers)
namespace string, selectors SelectorsByGVK, disableDeepCopy DisableDeepCopyByGVK, newInformerFunc client.NewInformerFunc, indexers cache.Indexers) *specificInformersMap {
return newSpecificInformersMap(config, scheme, mapper, resync, namespace, selectors, disableDeepCopy, createMetadataListWatch, newInformerFunc, indexers)
}
13 changes: 7 additions & 6 deletions pkg/cache/internal/informers_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

Expand All @@ -55,7 +56,7 @@ func newSpecificInformersMap(config *rest.Config,
selectors SelectorsByGVK,
disableDeepCopy DisableDeepCopyByGVK,
createListWatcher createListWatcherFunc,
keyFunction cache.KeyFunc,
newInformerFunc client.NewInformerFunc,
indexers cache.Indexers) *specificInformersMap {

ip := &specificInformersMap{
Expand All @@ -71,7 +72,7 @@ func newSpecificInformersMap(config *rest.Config,
namespace: namespace,
selectors: selectors.forGVK,
disableDeepCopy: disableDeepCopy,
keyFunction: keyFunction,
newInformerFunc: newInformerFunc,
additionalIndexers: indexers,
}
return ip
Expand Down Expand Up @@ -147,6 +148,8 @@ type specificInformersMap struct {
// additionalIndexers is the indexers that the informers will be configured to use.
// Will not allow overwriting the standard NamespaceIndex.
additionalIndexers cache.Indexers

newInformerFunc client.NewInformerFunc
}

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

ni := cache.NewSharedIndexInformerWithOptions(lw, obj,
cache.WithResyncPeriod(resyncPeriod(ip.resync)()),
cache.WithKeyFunction(ip.keyFunction),
cache.WithIndexers(indexers))
ni := ip.newInformerFunc(lw, obj, resyncPeriod(ip.resync)(), indexers)

rm, err := ip.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
return nil, false, err
Expand Down
16 changes: 8 additions & 8 deletions pkg/client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@ package client

import (
"context"

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

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/tools/cache"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)

type ObjectKey struct {
types.NamespacedName

Cluster logicalcluster.Name
}
type ObjectKey = types.NamespacedName

// ObjectKeyFromObject returns the ObjectKey given a runtime.Object.
func ObjectKeyFromObject(obj Object) ObjectKey {
return ObjectKey{NamespacedName: types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, Cluster: logicalcluster.From(obj)}
return ObjectKey{Namespace: obj.GetNamespace(), Name: obj.GetName()}
}

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

// NewInformerFunc describes a function that creates SharedIndexInformers.
// Its signature matches cache.NewSharedIndexInformer from client-go
type NewInformerFunc func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer

// TODO(directxman12): is there a sane way to deal with get/delete options?

// Reader knows how to read and list Kubernetes objects.
Expand Down
4 changes: 2 additions & 2 deletions pkg/envtest/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefin
crd := crd
log.V(1).Info("installing CRD", "crd", crd.GetName())
existingCrd := crd.DeepCopy()
err := cs.Get(context.TODO(), client.ObjectKey{NamespacedName: types.NamespacedName{Name: crd.GetName()}}, existingCrd)
err := cs.Get(context.TODO(), types.NamespacedName{Name: crd.GetName()}, existingCrd)
switch {
case apierrors.IsNotFound(err):
if err := cs.Create(context.TODO(), crd); err != nil {
Expand All @@ -264,7 +264,7 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefin
default:
log.V(1).Info("CRD already exists, updating", "crd", crd.GetName())
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
if err := cs.Get(context.TODO(), client.ObjectKey{NamespacedName: types.NamespacedName{Name: crd.GetName()}}, existingCrd); err != nil {
if err := cs.Get(context.TODO(), types.NamespacedName{Name: crd.GetName()}, existingCrd); err != nil {
return err
}
crd.SetResourceVersion(existingCrd.GetResourceVersion())
Expand Down
10 changes: 4 additions & 6 deletions pkg/envtest/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,9 @@ func (p *webhookPoller) poll() (done bool, err error) {
for _, name := range names.List() {
var obj = &unstructured.Unstructured{}
obj.SetGroupVersionKind(gvk)
err := c.Get(context.Background(), client.ObjectKey{
NamespacedName: types.NamespacedName{
Namespace: "",
Name: name,
},
err := c.Get(context.Background(), types.NamespacedName{
Namespace: "",
Name: name,
}, obj)

if err == nil {
Expand Down Expand Up @@ -318,7 +316,7 @@ func createWebhooks(config *rest.Config, mutHooks []*admissionv1.MutatingWebhook
// ensureCreated creates or update object if already exists in the cluster.
func ensureCreated(cs client.Client, obj client.Object) error {
existing := obj.DeepCopyObject().(client.Object)
err := cs.Get(context.Background(), client.ObjectKey{NamespacedName: types.NamespacedName{Name: obj.GetName()}}, existing)
err := cs.Get(context.Background(), types.NamespacedName{Name: obj.GetName()}, existing)
switch {
case apierrors.IsNotFound(err):
if err := cs.Create(context.Background(), obj); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/handler/enqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ func (e *EnqueueRequestForObject) Generic(evt event.GenericEvent, q workqueue.Ra
}

func request(obj client.Object) reconcile.Request {
return reconcile.Request{client.ObjectKey{
Cluster: logicalcluster.From(obj),
return reconcile.Request{
// TODO(kcp) Need to implement a non-kcp-specific way to support this
ClusterName: logicalcluster.From(obj).String(),
NamespacedName: types.NamespacedName{
Namespace: obj.GetNamespace(),
Name: obj.GetName(),
},
}}
}
}
9 changes: 3 additions & 6 deletions pkg/handler/enqueue_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -137,11 +136,9 @@ func (e *EnqueueRequestForOwner) getOwnerReconcileRequest(object metav1.Object,
if ref.Kind == e.groupKind.Kind && refGV.Group == e.groupKind.Group {
// Match found - add a Request for the object referred to in the OwnerReference
request := reconcile.Request{
ObjectKey: client.ObjectKey{
Cluster: logicalcluster.From(object),
NamespacedName: types.NamespacedName{
Name: ref.Name,
},
ClusterName: logicalcluster.From(object).String(),
NamespacedName: types.NamespacedName{
Name: ref.Name,
},
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/kcp/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
"github.com/kcp-dev/apimachinery/third_party/informers"
)

// NewClusterAwareManager returns a kcp-aware manager with appropriate defaults for cache and
Expand All @@ -57,7 +58,8 @@ func NewClusterAwareManager(cfg *rest.Config, options ctrl.Options) (manager.Man
func NewClusterAwareCache(config *rest.Config, opts cache.Options) (cache.Cache, error) {
c := rest.CopyConfig(config)
c.Host += "/clusters/*"
opts.KeyFunction = kcpcache.ClusterAwareKeyFunc
opts.NewInformerFunc = informers.NewSharedIndexInformer

opts.Indexers = k8scache.Indexers{
kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc,
kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc,
Expand Down
Loading