@@ -20,73 +20,35 @@ import (
2020 "context"
2121
2222 . "github.com/onsi/gomega"
23- "k8s.io/apimachinery/pkg/types "
23+ "k8s.io/utils/ptr "
2424 clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2525 v1beta1patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
2626 "sigs.k8s.io/controller-runtime/pkg/client"
2727
2828 infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
29- dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta3"
3029)
3130
32- // setClusterReady patches the CAPI and CloudStack cluster with ready status true.
33- func setClusterReady (g * WithT , client client.Client ) {
34- setCAPIClusterReady (g , client )
35- setCloudStackClusterReady (g , client )
36- }
37-
38- // checkClusterReady checks if the CAPI and CloudStack cluster are ready.
39- func checkClusterReady (ctx context.Context , g * WithT , client client.Client ) {
40- checkCAPIClusterReady (ctx , g , client )
41- checkCloudStackClusterReady (ctx , g , client )
42- }
43-
44- // checkCAPIClusterReady checks if the CAPI cluster is ready.
45- func checkCAPIClusterReady (ctx context.Context , g * WithT , client client.Client ) {
46- g .Eventually (func () bool {
47- capiCluster := & clusterv1.Cluster {}
48- if err := client .Get (ctx , types.NamespacedName {Namespace : dummies .CAPICluster .Namespace , Name : dummies .CAPICluster .Name }, capiCluster ); err == nil {
49- if * capiCluster .Status .Initialization .InfrastructureProvisioned {
50- return true
51- }
31+ // markClustersReady patches Cluster & CloudStackCluster status to satisfy controller readiness checks (v1beta2 semantics).
32+ func markClustersReady (ctx context.Context , g * WithT , c client.Client , cluster * clusterv1.Cluster , csCluster * infrav1.CloudStackCluster ) {
33+ g .Eventually (func () error {
34+ ph , err := v1beta1patch .NewHelper (cluster , c )
35+ if err != nil {
36+ return err
5237 }
53-
54- return false
55- }, timeout ).Should (BeTrue ())
56- }
57-
58- // checkCloudStackClusterReady checks if the CloudStack cluster is ready.
59- func checkCloudStackClusterReady (ctx context.Context , g * WithT , client client.Client ) {
60- g .Eventually (func () bool {
61- csCluster := & infrav1.CloudStackCluster {}
62- if err := client .Get (ctx , types.NamespacedName {Namespace : dummies .CSCluster .Namespace , Name : dummies .CSCluster .Name }, csCluster ); err == nil {
63- if csCluster .Status .Ready {
64- return true
65- }
38+ if cluster .Status .Initialization .InfrastructureProvisioned == nil || ! * cluster .Status .Initialization .InfrastructureProvisioned {
39+ cluster .Status .Initialization .InfrastructureProvisioned = ptr .To (true )
6640 }
67-
68- return false
69- }, timeout ).Should (BeTrue ())
70- }
71-
72- // setCAPIClusterReady patches the cluster with ready status true.
73- func setCAPIClusterReady (g * WithT , client client.Client ) {
74- g .Eventually (func () error {
75- ph , err := v1beta1patch .NewHelper (dummies .CAPICluster , client )
76- g .Expect (err ).ToNot (HaveOccurred ())
77- * dummies .CAPICluster .Status .Initialization .InfrastructureProvisioned = true
78-
79- return ph .Patch (ctx , dummies .CAPICluster , v1beta1patch.WithStatusObservedGeneration {})
41+ return ph .Patch (ctx , cluster , v1beta1patch.WithStatusObservedGeneration {})
8042 }, timeout ).Should (Succeed ())
81- }
8243
83- // setCloudStackClusterReady patches the cluster with ready status true.
84- func setCloudStackClusterReady (g * WithT , client client.Client ) {
8544 g .Eventually (func () error {
86- ph , err := v1beta1patch .NewHelper (dummies .CSCluster , client )
87- g .Expect (err ).ToNot (HaveOccurred ())
88- dummies .CSCluster .Status .Ready = true
89-
90- return ph .Patch (ctx , dummies .CSCluster , v1beta1patch.WithStatusObservedGeneration {})
45+ ph , err := v1beta1patch .NewHelper (csCluster , c )
46+ if err != nil {
47+ return err
48+ }
49+ if ! csCluster .Status .Ready {
50+ csCluster .Status .Ready = true
51+ }
52+ return ph .Patch (ctx , csCluster , v1beta1patch.WithStatusObservedGeneration {})
9153 }, timeout ).Should (Succeed ())
9254}
0 commit comments