Skip to content

Commit 711f8e8

Browse files
Rename fileter.go to objectutil.go
Signed-off-by: varshaprasad96 <[email protected]>
1 parent 8c4b815 commit 711f8e8

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

pkg/cache/multi_namespace_cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
type NewCacheFunc func(config *rest.Config, opts Options) (Cache, error)
3737

3838
// a new global namespaced cache to handle cluster scoped resources
39-
var globalCache = "cluster-scope"
39+
const globalCache = "_cluster-scope"
4040

4141
// MultiNamespacedCacheBuilder - Builder function to create a new multi-namespaced cache.
4242
// This will scope the cache to a list of namespaces. Listing for all namespaces
@@ -135,7 +135,7 @@ func (c *multiNamespaceCache) IndexField(ctx context.Context, obj client.Object,
135135
}
136136

137137
func (c *multiNamespaceCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error {
138-
isNamespaced, err := objectutil.IsNamespacedObject(obj, c.Scheme, c.RESTMapper)
138+
isNamespaced, err := objectutil.IsAPINamespaced(obj, c.Scheme, c.RESTMapper)
139139
if err != nil {
140140
return err
141141
}
@@ -158,7 +158,7 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
158158
listOpts := client.ListOptions{}
159159
listOpts.ApplyOptions(opts)
160160

161-
isNamespaced, err := objectutil.IsNamespacedObject(list, c.Scheme, c.RESTMapper)
161+
isNamespaced, err := objectutil.IsAPINamespaced(list, c.Scheme, c.RESTMapper)
162162
if err != nil {
163163
return err
164164
}

pkg/client/namespaced_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (n *namespacedClient) RESTMapper() meta.RESTMapper {
5757

5858
// isNamespaced returns true if the object is namespace scoped.
5959
// For unstructured objects the gvk is found from the object itself.
60+
// TODO: this is repetitive code. Remove this and use ojectutil.IsNamespaced.
6061
func isNamespaced(c Client, obj runtime.Object) (bool, error) {
6162
var gvk schema.GroupVersionKind
6263
var err error

pkg/internal/objectutil/filter.go renamed to pkg/internal/objectutil/objectutil.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"k8s.io/apimachinery/pkg/api/meta"
2424
apimeta "k8s.io/apimachinery/pkg/api/meta"
25-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2625
"k8s.io/apimachinery/pkg/labels"
2726
"k8s.io/apimachinery/pkg/runtime"
2827
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -48,24 +47,12 @@ func FilterWithLabels(objs []runtime.Object, labelSel labels.Selector) ([]runtim
4847
return outItems, nil
4948
}
5049

51-
// IsNamespacedObject returns true if the object is namespace scoped.
50+
// IsAPINamespaced returns true if the object is namespace scoped.
5251
// For unstructured objects the gvk is found from the object itself.
53-
func IsNamespacedObject(obj runtime.Object, scheme *runtime.Scheme, restmapper apimeta.RESTMapper) (bool, error) {
54-
var gvk schema.GroupVersionKind
55-
var err error
56-
57-
_, isUnstructured := obj.(*unstructured.Unstructured)
58-
_, isUnstructuredList := obj.(*unstructured.UnstructuredList)
59-
60-
isUnstructured = isUnstructured || isUnstructuredList
61-
62-
if isUnstructured {
63-
gvk = obj.GetObjectKind().GroupVersionKind()
64-
} else {
65-
gvk, err = apiutil.GVKForObject(obj, scheme)
66-
if err != nil {
67-
return false, err
68-
}
52+
func IsAPINamespaced(obj runtime.Object, scheme *runtime.Scheme, restmapper apimeta.RESTMapper) (bool, error) {
53+
gvk, err := apiutil.GVKForObject(obj, scheme)
54+
if err != nil {
55+
return false, err
6956
}
7057

7158
restmapping, err := restmapper.RESTMapping(schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind})

0 commit comments

Comments
 (0)