@@ -22,7 +22,7 @@ import (
22
22
23
23
"k8s.io/apimachinery/pkg/api/meta"
24
24
"k8s.io/apimachinery/pkg/runtime"
25
- "sigs. k8s.io/controller-runtime /pkg/internal/objectutil "
25
+ "k8s.io/apimachinery /pkg/runtime/schema "
26
26
)
27
27
28
28
// NewNamespacedClient wraps an existing client enforcing the namespace value.
@@ -52,9 +52,19 @@ func (n *namespacedClient) RESTMapper() meta.RESTMapper {
52
52
return n .client .RESTMapper ()
53
53
}
54
54
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
+
55
65
// Create implements client.Client.
56
66
func (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 )
58
68
if err != nil {
59
69
return fmt .Errorf ("error finding the scope of the object: %w" , err )
60
70
}
@@ -72,7 +82,7 @@ func (n *namespacedClient) Create(ctx context.Context, obj Object, opts ...Creat
72
82
73
83
// Update implements client.Client.
74
84
func (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 )
76
86
if err != nil {
77
87
return fmt .Errorf ("error finding the scope of the object: %w" , err )
78
88
}
@@ -90,7 +100,7 @@ func (n *namespacedClient) Update(ctx context.Context, obj Object, opts ...Updat
90
100
91
101
// Delete implements client.Client.
92
102
func (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 )
94
104
if err != nil {
95
105
return fmt .Errorf ("error finding the scope of the object: %w" , err )
96
106
}
@@ -108,7 +118,7 @@ func (n *namespacedClient) Delete(ctx context.Context, obj Object, opts ...Delet
108
118
109
119
// DeleteAllOf implements client.Client.
110
120
func (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 )
112
122
if err != nil {
113
123
return fmt .Errorf ("error finding the scope of the object: %w" , err )
114
124
}
@@ -121,7 +131,7 @@ func (n *namespacedClient) DeleteAllOf(ctx context.Context, obj Object, opts ...
121
131
122
132
// Patch implements client.Client.
123
133
func (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 )
125
135
if err != nil {
126
136
return fmt .Errorf ("error finding the scope of the object: %w" , err )
127
137
}
@@ -139,7 +149,7 @@ func (n *namespacedClient) Patch(ctx context.Context, obj Object, patch Patch, o
139
149
140
150
// Get implements client.Client.
141
151
func (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 )
143
153
if err != nil {
144
154
return fmt .Errorf ("error finding the scope of the object: %w" , err )
145
155
}
@@ -180,7 +190,7 @@ type namespacedClientSubResourceClient struct {
180
190
}
181
191
182
192
func (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 )
184
194
if err != nil {
185
195
return fmt .Errorf ("error finding the scope of the object: %w" , err )
186
196
}
@@ -198,7 +208,7 @@ func (nsw *namespacedClientSubResourceClient) Get(ctx context.Context, obj, subR
198
208
}
199
209
200
210
func (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 )
202
212
if err != nil {
203
213
return fmt .Errorf ("error finding the scope of the object: %w" , err )
204
214
}
@@ -217,7 +227,7 @@ func (nsw *namespacedClientSubResourceClient) Create(ctx context.Context, obj, s
217
227
218
228
// Update implements client.SubResourceWriter.
219
229
func (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 )
221
231
if err != nil {
222
232
return fmt .Errorf ("error finding the scope of the object: %w" , err )
223
233
}
@@ -235,8 +245,7 @@ func (nsw *namespacedClientSubResourceClient) Update(ctx context.Context, obj Ob
235
245
236
246
// Patch implements client.SubResourceWriter.
237
247
func (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 )
240
249
if err != nil {
241
250
return fmt .Errorf ("error finding the scope of the object: %w" , err )
242
251
}
0 commit comments