Skip to content

Commit 2e43993

Browse files
Merge pull request #29775 from yuqi-zhang/fix-mcn-race-condition
TRT-2106: Fix race in MCN test cleanup
2 parents 21ad7e1 + 000b1d8 commit 2e43993

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

test/extended/machine_config/machine_config_node.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ func ValidateMCNPropertiesCustomMCP(oc *exutil.CLI, fixture string) {
139139
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
140140
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
141141

142+
// Get starting state of default worker MCP, so we know what the correct number of nodes is during cleanup
143+
workerMcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
144+
o.Expect(err).NotTo(o.HaveOccurred(), "Could not get worker MCP.")
145+
workerMcpMachines := workerMcp.Status.MachineCount
146+
142147
// Grab a random node from each default pool
143148
workerNode := GetRandomNode(oc, worker)
144149
o.Expect(workerNode.Name).NotTo(o.Equal(""), "Could not get a worker node.")
145150

146151
// Cleanup custom MCP on test completion or failure
147152
defer func() {
148-
// Get starting state of default worker MCP
149-
workerMcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
150-
o.Expect(err).NotTo(o.HaveOccurred(), "Could not get worker MCP.")
151-
workerMcpReadyMachines := workerMcp.Status.ReadyMachineCount
152-
153153
// Unlabel node
154154
framework.Logf("Removing label node-role.kubernetes.io/%v from node %v", custom, workerNode.Name)
155155
unlabelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", workerNode.Name), fmt.Sprintf("node-role.kubernetes.io/%s-", custom)).Execute()
@@ -158,8 +158,8 @@ func ValidateMCNPropertiesCustomMCP(oc *exutil.CLI, fixture string) {
158158
// Wait for infra pool to report no nodes & for worker MCP to be ready
159159
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", custom, 0)
160160
WaitForMCPToBeReady(oc, clientSet, custom, 0)
161-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", worker, workerMcpReadyMachines+1)
162-
WaitForMCPToBeReady(oc, clientSet, worker, workerMcpReadyMachines+1)
161+
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", worker, workerMcpMachines)
162+
WaitForMCPToBeReady(oc, clientSet, worker, workerMcpMachines)
163163

164164
// Delete custom MCP
165165
framework.Logf("Deleting MCP %v", custom)
@@ -199,6 +199,11 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
199199
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
200200
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
201201

202+
// Get starting state of default worker MCP, so we know what the correct number of nodes is during cleanup
203+
workerMcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
204+
o.Expect(err).NotTo(o.HaveOccurred(), "Could not get worker MCP.")
205+
workerMcpMachines := workerMcp.Status.MachineCount
206+
202207
// Grab a random worker node
203208
workerNode := GetRandomNode(oc, worker)
204209
o.Expect(workerNode.Name).NotTo(o.Equal(""), "Could not get a worker node.")
@@ -215,11 +220,6 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
215220

216221
// Cleanup custom MCP, and delete MC on test completion or failure
217222
defer func() {
218-
// Get starting state of default worker MCP
219-
workerMcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
220-
o.Expect(err).NotTo(o.HaveOccurred(), "Could not get worker MCP.")
221-
workerMcpReadyMachines := workerMcp.Status.ReadyMachineCount
222-
223223
// Unlabel node
224224
framework.Logf("Removing label node-role.kubernetes.io/%v from node %v", custom, workerNode.Name)
225225
unlabelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", workerNode.Name), fmt.Sprintf("node-role.kubernetes.io/%s-", custom)).Execute()
@@ -234,8 +234,8 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
234234
o.Expect(deleteMCErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not delete MachineConfig '%v'.", mcName))
235235

236236
// Wait for worker MCP to be ready
237-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", worker, workerMcpReadyMachines+1)
238-
WaitForMCPToBeReady(oc, clientSet, worker, workerMcpReadyMachines+1)
237+
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", worker, workerMcpMachines)
238+
WaitForMCPToBeReady(oc, clientSet, worker, workerMcpMachines)
239239

240240
// Delete custom MCP
241241
framework.Logf("Deleting MCP %v", custom)

0 commit comments

Comments
 (0)