@@ -2409,6 +2409,93 @@ var _ = Describe("Fake client", func() {
2409
2409
Expect (cl .SubResource (subResourceScale ).Update (context .Background (), obj , client .WithSubResourceBody (scale )).Error ()).To (Equal (expectedErr ))
2410
2410
})
2411
2411
2412
+ It ("is threadsafe" , func () {
2413
+ cl := NewClientBuilder ().Build ()
2414
+
2415
+ u := func () * unstructured.Unstructured {
2416
+ u := & unstructured.Unstructured {}
2417
+ u .SetAPIVersion ("custom/v1" )
2418
+ u .SetKind ("Version" )
2419
+ u .SetName ("foo" )
2420
+ return u
2421
+ }
2422
+
2423
+ uList := func () * unstructured.UnstructuredList {
2424
+ u := & unstructured.UnstructuredList {}
2425
+ u .SetAPIVersion ("custom/v1" )
2426
+ u .SetKind ("Version" )
2427
+
2428
+ return u
2429
+ }
2430
+
2431
+ meta := func () * metav1.PartialObjectMetadata {
2432
+ return & metav1.PartialObjectMetadata {
2433
+ ObjectMeta : metav1.ObjectMeta {
2434
+ Name : "foo" ,
2435
+ Namespace : "default" ,
2436
+ },
2437
+ TypeMeta : metav1.TypeMeta {
2438
+ APIVersion : "custom/v1" ,
2439
+ Kind : "Version" ,
2440
+ },
2441
+ }
2442
+ }
2443
+ metaList := func () * metav1.PartialObjectMetadataList {
2444
+ return & metav1.PartialObjectMetadataList {
2445
+ TypeMeta : metav1.TypeMeta {
2446
+
2447
+ APIVersion : "custom/v1" ,
2448
+ Kind : "Version" ,
2449
+ },
2450
+ }
2451
+ }
2452
+
2453
+ pod := func () * corev1.Pod {
2454
+ return & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
2455
+ Name : "foo" ,
2456
+ Namespace : "default" ,
2457
+ }}
2458
+ }
2459
+
2460
+ ctx := context .Background ()
2461
+ ops := []func (){
2462
+ func () { _ = cl .Create (ctx , u ()) },
2463
+ func () { _ = cl .Get (ctx , client .ObjectKeyFromObject (u ()), u ()) },
2464
+ func () { _ = cl .Update (ctx , u ()) },
2465
+ func () { _ = cl .Patch (ctx , u (), client .RawPatch (types .StrategicMergePatchType , []byte ("foo" ))) },
2466
+ func () { _ = cl .Delete (ctx , u ()) },
2467
+ func () { _ = cl .DeleteAllOf (ctx , u (), client.HasLabels {"foo" }) },
2468
+ func () { _ = cl .List (ctx , uList ()) },
2469
+
2470
+ func () { _ = cl .Create (ctx , meta ()) },
2471
+ func () { _ = cl .Get (ctx , client .ObjectKeyFromObject (meta ()), meta ()) },
2472
+ func () { _ = cl .Update (ctx , meta ()) },
2473
+ func () { _ = cl .Patch (ctx , meta (), client .RawPatch (types .StrategicMergePatchType , []byte ("foo" ))) },
2474
+ func () { _ = cl .Delete (ctx , meta ()) },
2475
+ func () { _ = cl .DeleteAllOf (ctx , meta (), client.HasLabels {"foo" }) },
2476
+ func () { _ = cl .List (ctx , metaList ()) },
2477
+
2478
+ func () { _ = cl .Create (ctx , pod ()) },
2479
+ func () { _ = cl .Get (ctx , client .ObjectKeyFromObject (pod ()), pod ()) },
2480
+ func () { _ = cl .Update (ctx , pod ()) },
2481
+ func () { _ = cl .Patch (ctx , pod (), client .RawPatch (types .StrategicMergePatchType , []byte ("foo" ))) },
2482
+ func () { _ = cl .Delete (ctx , pod ()) },
2483
+ func () { _ = cl .DeleteAllOf (ctx , pod (), client.HasLabels {"foo" }) },
2484
+ func () { _ = cl .List (ctx , & corev1.PodList {}) },
2485
+ }
2486
+
2487
+ wg := sync.WaitGroup {}
2488
+ wg .Add (len (ops ))
2489
+ for _ , op := range ops {
2490
+ go func () {
2491
+ defer wg .Done ()
2492
+ op ()
2493
+ }()
2494
+ }
2495
+
2496
+ wg .Wait ()
2497
+ })
2498
+
2412
2499
scalableObjs := []client.Object {
2413
2500
& appsv1.Deployment {
2414
2501
ObjectMeta : metav1.ObjectMeta {
@@ -2497,6 +2584,7 @@ var _ = Describe("Fake client", func() {
2497
2584
scaleExpected .ResourceVersion = scaleActual .ResourceVersion
2498
2585
Expect (cmp .Diff (scaleExpected , scaleActual )).To (BeEmpty ())
2499
2586
})
2587
+
2500
2588
}
2501
2589
})
2502
2590
0 commit comments