@@ -22,7 +22,7 @@ import (
2222
2323 "k8s.io/apimachinery/pkg/api/meta"
2424 "k8s.io/apimachinery/pkg/runtime"
25- "sigs. k8s.io/controller-runtime /pkg/internal/objectutil "
25+ "k8s.io/apimachinery /pkg/runtime/schema "
2626)
2727
2828// NewNamespacedClient wraps an existing client enforcing the namespace value.
@@ -52,9 +52,19 @@ func (n *namespacedClient) RESTMapper() meta.RESTMapper {
5252 return n .client .RESTMapper ()
5353}
5454
55+ // GroupVersionKindFor returns the GroupVersionKind for the given object.
56+ func (n * namespacedClient ) GroupVersionKindFor (obj Object ) (schema.GroupVersionKind , error ) {
57+ return n .client .GroupVersionKindFor (obj )
58+ }
59+
60+ // IsObjectNamespaced returns true if the GroupVersionKind of the object is namespaced.
61+ func (n * namespacedClient ) IsObjectNamespaced (obj Object ) (bool , error ) {
62+ return n .client .IsObjectNamespaced (obj )
63+ }
64+
5565// Create implements client.Client.
5666func (n * namespacedClient ) Create (ctx context.Context , obj Object , opts ... CreateOption ) error {
57- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , n . Scheme (), n . RESTMapper () )
67+ isNamespaceScoped , err := n . IsObjectNamespaced ( obj )
5868 if err != nil {
5969 return fmt .Errorf ("error finding the scope of the object: %w" , err )
6070 }
@@ -72,7 +82,7 @@ func (n *namespacedClient) Create(ctx context.Context, obj Object, opts ...Creat
7282
7383// Update implements client.Client.
7484func (n * namespacedClient ) Update (ctx context.Context , obj Object , opts ... UpdateOption ) error {
75- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , n . Scheme (), n . RESTMapper () )
85+ isNamespaceScoped , err := n . IsObjectNamespaced ( obj )
7686 if err != nil {
7787 return fmt .Errorf ("error finding the scope of the object: %w" , err )
7888 }
@@ -90,7 +100,7 @@ func (n *namespacedClient) Update(ctx context.Context, obj Object, opts ...Updat
90100
91101// Delete implements client.Client.
92102func (n * namespacedClient ) Delete (ctx context.Context , obj Object , opts ... DeleteOption ) error {
93- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , n . Scheme (), n . RESTMapper () )
103+ isNamespaceScoped , err := n . IsObjectNamespaced ( obj )
94104 if err != nil {
95105 return fmt .Errorf ("error finding the scope of the object: %w" , err )
96106 }
@@ -108,7 +118,7 @@ func (n *namespacedClient) Delete(ctx context.Context, obj Object, opts ...Delet
108118
109119// DeleteAllOf implements client.Client.
110120func (n * namespacedClient ) DeleteAllOf (ctx context.Context , obj Object , opts ... DeleteAllOfOption ) error {
111- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , n . Scheme (), n . RESTMapper () )
121+ isNamespaceScoped , err := n . IsObjectNamespaced ( obj )
112122 if err != nil {
113123 return fmt .Errorf ("error finding the scope of the object: %w" , err )
114124 }
@@ -121,7 +131,7 @@ func (n *namespacedClient) DeleteAllOf(ctx context.Context, obj Object, opts ...
121131
122132// Patch implements client.Client.
123133func (n * namespacedClient ) Patch (ctx context.Context , obj Object , patch Patch , opts ... PatchOption ) error {
124- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , n . Scheme (), n . RESTMapper () )
134+ isNamespaceScoped , err := n . IsObjectNamespaced ( obj )
125135 if err != nil {
126136 return fmt .Errorf ("error finding the scope of the object: %w" , err )
127137 }
@@ -139,7 +149,7 @@ func (n *namespacedClient) Patch(ctx context.Context, obj Object, patch Patch, o
139149
140150// Get implements client.Client.
141151func (n * namespacedClient ) Get (ctx context.Context , key ObjectKey , obj Object , opts ... GetOption ) error {
142- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , n . Scheme (), n . RESTMapper () )
152+ isNamespaceScoped , err := n . IsObjectNamespaced ( obj )
143153 if err != nil {
144154 return fmt .Errorf ("error finding the scope of the object: %w" , err )
145155 }
@@ -180,7 +190,7 @@ type namespacedClientSubResourceClient struct {
180190}
181191
182192func (nsw * namespacedClientSubResourceClient ) Get (ctx context.Context , obj , subResource Object , opts ... SubResourceGetOption ) error {
183- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , nsw .namespacedclient .Scheme (), nsw . namespacedclient . RESTMapper () )
193+ isNamespaceScoped , err := nsw .namespacedclient .IsObjectNamespaced ( obj )
184194 if err != nil {
185195 return fmt .Errorf ("error finding the scope of the object: %w" , err )
186196 }
@@ -198,7 +208,7 @@ func (nsw *namespacedClientSubResourceClient) Get(ctx context.Context, obj, subR
198208}
199209
200210func (nsw * namespacedClientSubResourceClient ) Create (ctx context.Context , obj , subResource Object , opts ... SubResourceCreateOption ) error {
201- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , nsw .namespacedclient .Scheme (), nsw . namespacedclient . RESTMapper () )
211+ isNamespaceScoped , err := nsw .namespacedclient .IsObjectNamespaced ( obj )
202212 if err != nil {
203213 return fmt .Errorf ("error finding the scope of the object: %w" , err )
204214 }
@@ -217,7 +227,7 @@ func (nsw *namespacedClientSubResourceClient) Create(ctx context.Context, obj, s
217227
218228// Update implements client.SubResourceWriter.
219229func (nsw * namespacedClientSubResourceClient ) Update (ctx context.Context , obj Object , opts ... SubResourceUpdateOption ) error {
220- isNamespaceScoped , err := objectutil . IsAPINamespaced ( obj , nsw .namespacedclient .Scheme (), nsw . namespacedclient . RESTMapper () )
230+ isNamespaceScoped , err := nsw .namespacedclient .IsObjectNamespaced ( obj )
221231 if err != nil {
222232 return fmt .Errorf ("error finding the scope of the object: %w" , err )
223233 }
@@ -235,8 +245,7 @@ func (nsw *namespacedClientSubResourceClient) Update(ctx context.Context, obj Ob
235245
236246// Patch implements client.SubResourceWriter.
237247func (nsw * namespacedClientSubResourceClient ) Patch (ctx context.Context , obj Object , patch Patch , opts ... SubResourcePatchOption ) error {
238- isNamespaceScoped , err := objectutil .IsAPINamespaced (obj , nsw .namespacedclient .Scheme (), nsw .namespacedclient .RESTMapper ())
239-
248+ isNamespaceScoped , err := nsw .namespacedclient .IsObjectNamespaced (obj )
240249 if err != nil {
241250 return fmt .Errorf ("error finding the scope of the object: %w" , err )
242251 }
0 commit comments