-
Notifications
You must be signed in to change notification settings - Fork 17
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
Changes from all commits
c0045ef
622feaa
974cf34
6a6baae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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{} | ||
|
||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`. | ||
|
Uh oh!
There was an error while loading. Please reload this page.