@@ -2,6 +2,7 @@ package vsphere
22
33import (
44 "context"
5+ "fmt"
56 "time"
67
78 . "github.com/onsi/ginkgo/v2"
@@ -75,6 +76,13 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:VSphereMultiDisk][platf
7576 // skip if operator is not running
7677 util .SkipUnlessMachineAPIOperator (dc , c .CoreV1 ().Namespaces ())
7778
79+ By ("checking initial cluster size" )
80+ nodeList , err := c .CoreV1 ().Nodes ().List (context .Background (), metav1.ListOptions {})
81+ Expect (err ).NotTo (HaveOccurred ())
82+
83+ initialNumberOfNodes := len (nodeList .Items )
84+ By (fmt .Sprintf ("initial cluster size is %v" , initialNumberOfNodes ))
85+
7886 // get provider for simple definition vs generating one from scratch
7987 By ("generating provider for tests" )
8088 provider := getProviderFromMachineSet (cfg )
@@ -108,6 +116,20 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:VSphereMultiDisk][platf
108116 By ("delete the machine" )
109117 err = mc .Machines (util .MachineAPINamespace ).Delete (ctx , machine .Name , metav1.DeleteOptions {})
110118 Expect (err ).NotTo (HaveOccurred ())
119+
120+ // By this point, the node object should be deleted, but seems it may linger momentarily causing issue with other tests that grab current
121+ // nodes to perform tests against.
122+ By (fmt .Sprintf ("waiting for cluster to get back to original size. Final size should be %d worker nodes" , initialNumberOfNodes ))
123+ Eventually (func () bool {
124+ nodeList , err := c .CoreV1 ().Nodes ().List (context .Background (), metav1.ListOptions {})
125+ Expect (err ).NotTo (HaveOccurred ())
126+ By (fmt .Sprintf ("got %v nodes, expecting %v" , len (nodeList .Items ), initialNumberOfNodes ))
127+ if len (nodeList .Items ) != initialNumberOfNodes {
128+ return false
129+ }
130+
131+ return true
132+ }, 10 * time .Minute , 5 * time .Second ).Should (BeTrue (), "number of nodes should be the same as it was before test started" )
111133 })
112134
113135 DescribeTable ("create machinesets" , func (msName string , dataDisks []v1beta1.VSphereDisk ) {
@@ -116,6 +138,13 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:VSphereMultiDisk][platf
116138 // skip if operator is not running
117139 util .SkipUnlessMachineAPIOperator (dc , c .CoreV1 ().Namespaces ())
118140
141+ By ("checking initial cluster size" )
142+ nodeList , err := c .CoreV1 ().Nodes ().List (context .Background (), metav1.ListOptions {})
143+ Expect (err ).NotTo (HaveOccurred ())
144+
145+ initialNumberOfNodes := len (nodeList .Items )
146+ By (fmt .Sprintf ("initial cluster size is %v" , initialNumberOfNodes ))
147+
119148 // get provider for simple definition vs generating one from scratch
120149 By ("generating provider for tests" )
121150 provider := getProviderFromMachineSet (cfg )
@@ -144,7 +173,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:VSphereMultiDisk][platf
144173 return - 1 , err
145174 }
146175 return ms .Status .ReadyReplicas , nil
147- }, machineReadyTimeout ).Should (BeEquivalentTo (1 ))
176+ }, machineReadyTimeout ).Should (BeEquivalentTo (1 ), "machine ReadyReplicas should be 1 when all machines are ready" )
148177
149178 // Scale down machineset
150179 By ("scaling down the machineset" )
@@ -159,12 +188,27 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:VSphereMultiDisk][platf
159188 return - 1 , err
160189 }
161190 return ms .Status .ReadyReplicas , nil
162- }, machineReadyTimeout ).Should (BeEquivalentTo (0 ))
191+ }, machineReadyTimeout ).Should (BeEquivalentTo (0 ), "machine ReadyReplicas should be zero when all machines are destroyed" )
163192
164193 // Delete machineset
165194 By ("deleting the machineset" )
166195 err = mc .MachineSets (util .MachineAPINamespace ).Delete (ctx , ddMachineSet .Name , metav1.DeleteOptions {})
167196 Expect (err ).NotTo (HaveOccurred ())
197+
198+ // By this point, the node object should be deleted, but seems it may linger momentarily causing issue with other tests that grab current
199+ // nodes to perform tests against.
200+ By (fmt .Sprintf ("waiting for cluster to get back to original size. Final size should be %d worker nodes" , initialNumberOfNodes ))
201+ Eventually (func () bool {
202+ nodeList , err := c .CoreV1 ().Nodes ().List (context .Background (), metav1.ListOptions {})
203+ Expect (err ).NotTo (HaveOccurred ())
204+ By (fmt .Sprintf ("got %v nodes, expecting %v" , len (nodeList .Items ), initialNumberOfNodes ))
205+ if len (nodeList .Items ) != initialNumberOfNodes {
206+ return false
207+ }
208+
209+ return true
210+ }, 10 * time .Minute , 5 * time .Second ).Should (BeTrue (), "number of nodes should be the same as it was before test started" )
211+
168212 },
169213 Entry ("with thin data disk [apigroup:machine.openshift.io][Serial][Suite:openshift/conformance/serial]" , "ms-thin-test" , []v1beta1.VSphereDisk {
170214 {
0 commit comments