@@ -26,7 +26,6 @@ import (
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
27
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
28
28
"k8s.io/apimachinery/pkg/types"
29
- "k8s.io/utils/ptr"
30
29
"sigs.k8s.io/controller-runtime/pkg/client"
31
30
32
31
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -52,7 +51,7 @@ func TestPatchHelper(t *testing.T) {
52
51
obj := & unstructured.Unstructured {
53
52
Object : map [string ]interface {}{
54
53
"kind" : "GenericBootstrapConfig" ,
55
- "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta1 " ,
54
+ "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta2 " ,
56
55
"metadata" : map [string ]interface {}{
57
56
"generateName" : "test-bootstrap-" ,
58
57
"namespace" : ns .Name ,
@@ -171,8 +170,8 @@ func TestPatchHelper(t *testing.T) {
171
170
}, timeout ).Should (BeTrue ())
172
171
})
173
172
174
- t .Run ("on a clusterv1.Cluster object" , func (t * testing.T ) {
175
- obj := & clusterv1. Cluster {
173
+ t .Run ("on a Phase1 object" , func (t * testing.T ) {
174
+ obj := & builder. Phase1Obj {
176
175
ObjectMeta : metav1.ObjectMeta {
177
176
GenerateName : "test-" ,
178
177
Namespace : ns .Name ,
@@ -317,10 +316,8 @@ func TestPatchHelper(t *testing.T) {
317
316
g .Expect (err ).ToNot (HaveOccurred ())
318
317
319
318
t .Log ("Changing the object spec, status, and adding Ready=True condition" )
320
- obj .Spec .Paused = true
321
- obj .Spec .ControlPlaneEndpoint .Host = "test://endpoint"
322
- obj .Spec .ControlPlaneEndpoint .Port = 8443
323
- obj .Status .Phase = "Provisioning"
319
+ obj .Spec .Foo = "Foo"
320
+ obj .Status .Bar = "Bar"
324
321
conditions .MarkTrue (obj , clusterv1 .ReadyCondition )
325
322
326
323
t .Log ("Patching the object" )
@@ -353,9 +350,8 @@ func TestPatchHelper(t *testing.T) {
353
350
return false
354
351
}
355
352
356
- return obj .Spec .Paused == objAfter .Spec .Paused &&
357
- obj .Spec .ControlPlaneEndpoint == objAfter .Spec .ControlPlaneEndpoint &&
358
- obj .Status .Phase == objAfter .Status .Phase
353
+ return obj .Spec .Foo == objAfter .Spec .Foo &&
354
+ obj .Status .Bar == objAfter .Status .Bar
359
355
}, timeout ).Should (BeTrue (), cmp .Diff (obj , objAfter ))
360
356
})
361
357
@@ -514,8 +510,8 @@ func TestPatchHelper(t *testing.T) {
514
510
})
515
511
})
516
512
517
- t .Run ("Should patch a clusterv1.Cluster " , func (t * testing.T ) {
518
- obj := & clusterv1. Cluster {
513
+ t .Run ("Should patch a Phase1Obj " , func (t * testing.T ) {
514
+ obj := & builder. Phase1Obj {
519
515
ObjectMeta : metav1.ObjectMeta {
520
516
GenerateName : "test-" ,
521
517
Namespace : ns .Name ,
@@ -624,12 +620,7 @@ func TestPatchHelper(t *testing.T) {
624
620
g .Expect (err ).ToNot (HaveOccurred ())
625
621
626
622
t .Log ("Updating the object spec" )
627
- obj .Spec .Paused = true
628
- obj .Spec .InfrastructureRef = & corev1.ObjectReference {
629
- Kind : "test-kind" ,
630
- Name : "test-ref" ,
631
- Namespace : ns .Name ,
632
- }
623
+ obj .Spec .Foo = "Foo"
633
624
634
625
t .Log ("Patching the object" )
635
626
g .Expect (patcher .Patch (ctx , obj )).To (Succeed ())
@@ -641,8 +632,7 @@ func TestPatchHelper(t *testing.T) {
641
632
return false
642
633
}
643
634
644
- return objAfter .Spec .Paused &&
645
- cmp .Equal (obj .Spec .InfrastructureRef , objAfter .Spec .InfrastructureRef )
635
+ return obj .Spec .Foo == objAfter .Spec .Foo
646
636
}, timeout ).Should (BeTrue ())
647
637
})
648
638
@@ -669,7 +659,7 @@ func TestPatchHelper(t *testing.T) {
669
659
g .Expect (err ).ToNot (HaveOccurred ())
670
660
671
661
t .Log ("Updating the object status" )
672
- obj .Status .InfrastructureReady = true
662
+ obj .Status .Bar = "Bar"
673
663
674
664
t .Log ("Patching the object" )
675
665
g .Expect (patcher .Patch (ctx , obj )).To (Succeed ())
@@ -707,15 +697,10 @@ func TestPatchHelper(t *testing.T) {
707
697
g .Expect (err ).ToNot (HaveOccurred ())
708
698
709
699
t .Log ("Updating the object spec" )
710
- obj .Spec .Paused = true
711
- obj .Spec .InfrastructureRef = & corev1.ObjectReference {
712
- Kind : "test-kind" ,
713
- Name : "test-ref" ,
714
- Namespace : ns .Name ,
715
- }
700
+ obj .Spec .Foo = "Foo"
716
701
717
702
t .Log ("Updating the object status" )
718
- obj .Status .InfrastructureReady = true
703
+ obj .Status .Bar = "Bar"
719
704
720
705
t .Log ("Setting Ready condition" )
721
706
conditions .MarkTrue (obj , clusterv1 .ReadyCondition )
@@ -730,7 +715,7 @@ func TestPatchHelper(t *testing.T) {
730
715
return false
731
716
}
732
717
733
- return obj .Status .InfrastructureReady == objAfter .Status .InfrastructureReady &&
718
+ return cmp . Equal ( obj .Status .Bar , objAfter .Status .Bar ) &&
734
719
conditions .IsTrue (objAfter , clusterv1 .ReadyCondition ) &&
735
720
cmp .Equal (obj .Spec , objAfter .Spec )
736
721
}, timeout ).Should (BeTrue ())
@@ -788,19 +773,11 @@ func TestPatchHelper(t *testing.T) {
788
773
})
789
774
790
775
t .Run ("Should update Status.ObservedGeneration when using WithStatusObservedGeneration option" , func (t * testing.T ) {
791
- obj := & clusterv1. MachineSet {
776
+ obj := & builder. Phase1Obj {
792
777
ObjectMeta : metav1.ObjectMeta {
793
778
GenerateName : "test-ms" ,
794
779
Namespace : ns .Name ,
795
780
},
796
- Spec : clusterv1.MachineSetSpec {
797
- ClusterName : "test1" ,
798
- Template : clusterv1.MachineTemplateSpec {
799
- Spec : clusterv1.MachineSpec {
800
- ClusterName : "test1" ,
801
- },
802
- },
803
- },
804
781
}
805
782
806
783
t .Run ("when updating spec" , func (t * testing.T ) {
@@ -826,7 +803,7 @@ func TestPatchHelper(t *testing.T) {
826
803
g .Expect (err ).ToNot (HaveOccurred ())
827
804
828
805
t .Log ("Updating the object spec" )
829
- obj .Spec .Replicas = ptr. To [ int32 ]( 10 )
806
+ obj .Spec .Foo = "Foo"
830
807
831
808
t .Log ("Patching the object" )
832
809
g .Expect (patcher .Patch (ctx , obj , WithStatusObservedGeneration {})).To (Succeed ())
@@ -866,11 +843,10 @@ func TestPatchHelper(t *testing.T) {
866
843
g .Expect (err ).ToNot (HaveOccurred ())
867
844
868
845
t .Log ("Updating the object spec" )
869
- obj .Spec .Replicas = ptr. To [ int32 ]( 10 )
846
+ obj .Spec .Foo = "Foo"
870
847
871
848
t .Log ("Updating the object status" )
872
- obj .Status .AvailableReplicas = 6
873
- obj .Status .ReadyReplicas = 6
849
+ obj .Status .Bar = "Bar"
874
850
875
851
t .Log ("Updating the object metadata" )
876
852
obj .ObjectMeta .Annotations = map [string ]string {
@@ -936,26 +912,18 @@ func TestPatchHelper(t *testing.T) {
936
912
t .Run ("Should error if the object isn't the same" , func (t * testing.T ) {
937
913
g := NewWithT (t )
938
914
939
- cluster := & clusterv1. Cluster {
915
+ cluster := & builder. Phase0Obj {
940
916
ObjectMeta : metav1.ObjectMeta {
941
917
GenerateName : "test-" ,
942
918
Namespace : ns .Name ,
943
919
},
944
920
}
945
921
946
- machineSet := & clusterv1. MachineSet {
922
+ machineSet := & builder. Phase1Obj {
947
923
ObjectMeta : metav1.ObjectMeta {
948
- GenerateName : "test-ms " ,
924
+ GenerateName : "test-2 " ,
949
925
Namespace : ns .Name ,
950
926
},
951
- Spec : clusterv1.MachineSetSpec {
952
- ClusterName : "test1" ,
953
- Template : clusterv1.MachineTemplateSpec {
954
- Spec : clusterv1.MachineSpec {
955
- ClusterName : "test1" ,
956
- },
957
- },
958
- },
959
927
}
960
928
961
929
g .Expect (env .Create (ctx , cluster )).To (Succeed ())
@@ -975,13 +943,13 @@ func TestPatchHelper(t *testing.T) {
975
943
976
944
t .Run ("Should not error if there are no finalizers and deletion timestamp is not nil" , func (t * testing.T ) {
977
945
g := NewWithT (t )
978
- cluster := & clusterv1. Cluster {
946
+ cluster := & builder. Phase1Obj {
979
947
ObjectMeta : metav1.ObjectMeta {
980
948
Name : "test-cluster" ,
981
949
Namespace : ns .Name ,
982
950
Finalizers : []string {"block-deletion" },
983
951
},
984
- Status : clusterv1. ClusterStatus {},
952
+ Status : builder. Phase1ObjStatus {},
985
953
}
986
954
key := client.ObjectKey {Name : cluster .GetName (), Namespace : cluster .GetNamespace ()}
987
955
g .Expect (env .Create (ctx , cluster )).To (Succeed ())
@@ -998,7 +966,7 @@ func TestPatchHelper(t *testing.T) {
998
966
patcher , err := NewHelper (cluster , env )
999
967
g .Expect (err ).ToNot (HaveOccurred ())
1000
968
cluster .Finalizers = []string {}
1001
- cluster .Status .Phase = "Running "
969
+ cluster .Status .Bar = "Bar "
1002
970
g .Expect (patcher .Patch (ctx , cluster )).To (Succeed ())
1003
971
})
1004
972
}
0 commit comments