@@ -2542,6 +2542,74 @@ var _ = Describe("Fake client", func() {
2542
2542
wg .Wait ()
2543
2543
})
2544
2544
2545
+ DescribeTable ("mutating operations return the updated object" ,
2546
+ func (ctx SpecContext , mutate func (ctx SpecContext ) (* corev1.ConfigMap , error )) {
2547
+ mutated , err := mutate (ctx )
2548
+ Expect (err ).NotTo (HaveOccurred ())
2549
+
2550
+ var retrieved corev1.ConfigMap
2551
+ Expect (cl .Get (ctx , client .ObjectKeyFromObject (mutated ), & retrieved )).To (Succeed ())
2552
+
2553
+ Expect (& retrieved ).To (BeComparableTo (mutated ))
2554
+ },
2555
+
2556
+ Entry ("create" , func (ctx SpecContext ) (* corev1.ConfigMap , error ) {
2557
+ cl = NewClientBuilder ().Build ()
2558
+ cm .ResourceVersion = ""
2559
+ return cm , cl .Create (ctx , cm )
2560
+ }),
2561
+ Entry ("update" , func (ctx SpecContext ) (* corev1.ConfigMap , error ) {
2562
+ cl = NewClientBuilder ().WithObjects (cm ).Build ()
2563
+ cm .Labels = map [string ]string {"updated-label" : "update-test" }
2564
+ cm .Data ["new-key" ] = "new-value"
2565
+ return cm , cl .Update (ctx , cm )
2566
+ }),
2567
+ Entry ("patch" , func (ctx SpecContext ) (* corev1.ConfigMap , error ) {
2568
+ cl = NewClientBuilder ().WithObjects (cm ).Build ()
2569
+ original := cm .DeepCopy ()
2570
+
2571
+ cm .Labels = map [string ]string {"updated-label" : "update-test" }
2572
+ cm .Data ["new-key" ] = "new-value"
2573
+ return cm , cl .Patch (ctx , cm , client .MergeFrom (original ))
2574
+ }),
2575
+ Entry ("Create through Apply" , func (ctx SpecContext ) (* corev1.ConfigMap , error ) {
2576
+ ac := corev1applyconfigurations .ConfigMap (cm .Name , cm .Namespace ).WithData (cm .Data )
2577
+
2578
+ cl = NewClientBuilder ().Build ()
2579
+ Expect (cl .Apply (ctx , ac , client .FieldOwner ("foo" ))).To (Succeed ())
2580
+
2581
+ serialized , err := json .Marshal (ac )
2582
+ Expect (err ).NotTo (HaveOccurred ())
2583
+
2584
+ var cm corev1.ConfigMap
2585
+ Expect (json .Unmarshal (serialized , & cm )).To (Succeed ())
2586
+
2587
+ // ApplyConfigurations always have TypeMeta set as they do not support using the scheme
2588
+ // to retrieve gvk.
2589
+ cm .TypeMeta = metav1.TypeMeta {}
2590
+ return & cm , nil
2591
+ }),
2592
+ Entry ("Update through Apply" , func (ctx SpecContext ) (* corev1.ConfigMap , error ) {
2593
+ ac := corev1applyconfigurations .ConfigMap (cm .Name , cm .Namespace ).
2594
+ WithLabels (map [string ]string {"updated-label" : "update-test" }).
2595
+ WithData (map [string ]string {"new-key" : "new-value" })
2596
+
2597
+ cl = NewClientBuilder ().WithObjects (cm ).Build ()
2598
+ Expect (cl .Apply (ctx , ac , client .FieldOwner ("foo" ))).To (Succeed ())
2599
+
2600
+ serialized , err := json .Marshal (ac )
2601
+ Expect (err ).NotTo (HaveOccurred ())
2602
+
2603
+ var cm corev1.ConfigMap
2604
+ Expect (json .Unmarshal (serialized , & cm )).To (Succeed ())
2605
+
2606
+ // ApplyConfigurations always have TypeMeta set as they do not support using the scheme
2607
+ // to retrieve gvk.
2608
+ cm .TypeMeta = metav1.TypeMeta {}
2609
+ return & cm , nil
2610
+ }),
2611
+ )
2612
+
2545
2613
It ("supports server-side apply of a client-go resource" , func (ctx SpecContext ) {
2546
2614
cl := NewClientBuilder ().Build ()
2547
2615
obj := & unstructured.Unstructured {}
@@ -2810,7 +2878,7 @@ var _ = Describe("Fake client", func() {
2810
2878
})
2811
2879
2812
2880
It ("allows to set deletionTimestamp on an object during SSA create" , func (ctx SpecContext ) {
2813
- now := metav1 .Now ()
2881
+ now := metav1.Time { Time : time . Now (). Round ( time . Second )}
2814
2882
obj := corev1applyconfigurations .
2815
2883
ConfigMap ("foo" , "default" ).
2816
2884
WithDeletionTimestamp (now ).
@@ -2823,8 +2891,7 @@ var _ = Describe("Fake client", func() {
2823
2891
})
2824
2892
2825
2893
It ("will silently ignore a deletionTimestamp update through SSA" , func (ctx SpecContext ) {
2826
- Skip ("the apply logic in the managedFieldObjectTracker seems to override this" )
2827
- now := metav1 .Now ()
2894
+ now := metav1.Time {Time : time .Now ().Round (time .Second )}
2828
2895
obj := corev1applyconfigurations .
2829
2896
ConfigMap ("foo" , "default" ).
2830
2897
WithDeletionTimestamp (now ).
0 commit comments