File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,12 @@ type ResourceSet[T client.Object] interface {
49
49
Difference (set ResourceSet [T ]) ResourceSet [T ]
50
50
// Return the intersection with the provided set
51
51
Intersection (set ResourceSet [T ]) ResourceSet [T ]
52
- // Find the resource with the given ID
52
+ // Find the resource with the given ID.
53
+ // Returns a NotFoundErr error if the resource is not found.
53
54
Find (resource ezkube.ResourceId ) (T , error )
55
+ // Find the resource with the given ID.
56
+ // Returns nil if the resource is not found.
57
+ Get (resource ezkube.ResourceId ) T
54
58
// Get the length of the set
55
59
Len () int
56
60
Length () int
@@ -274,6 +278,22 @@ func (s *resourceSet[T]) Intersection(set ResourceSet[T]) ResourceSet[T] {
274
278
return result
275
279
}
276
280
281
+ func (s * resourceSet [T ]) Get (resource ezkube.ResourceId ) T {
282
+ s .lock .RLock ()
283
+ defer s .lock .RUnlock ()
284
+
285
+ insertIndex , found := slices .BinarySearchFunc (
286
+ s .set ,
287
+ resource ,
288
+ func (a T , b ezkube.ResourceId ) int { return s .compareFunc (a , b ) },
289
+ )
290
+ if found {
291
+ return s .set [insertIndex ]
292
+ }
293
+ var r T
294
+ return r
295
+ }
296
+
277
297
func (s * resourceSet [T ]) Find (resource ezkube.ResourceId ) (T , error ) {
278
298
s .lock .RLock ()
279
299
defer s .lock .RUnlock ()
You can’t perform that action at this time.
0 commit comments