Skip to content

Commit 761b053

Browse files
Merge pull request #29874 from isabella-janssen/ocpbugs-56037
OCPBUGS-56037: Stabilize custom MCP cleanup on MCN tests
2 parents c1d4962 + e567d21 commit 761b053

File tree

2 files changed

+77
-47
lines changed

2 files changed

+77
-47
lines changed

test/extended/machine_config/helpers.go

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,85 @@ func WaitForMCPToBeReady(oc *exutil.CLI, machineConfigClient *machineconfigclien
550550
}
551551
// Check if the pool is in an updated state with the correct number of ready machines
552552
if IsMachineConfigPoolConditionTrue(mcp.Status.Conditions, mcfgv1.MachineConfigPoolUpdated) && mcp.Status.UpdatedMachineCount == readyMachineCount {
553+
framework.Logf("MCP '%v' has the desired %v ready machines.", poolName, mcp.Status.UpdatedMachineCount)
553554
return true
554555
}
555-
framework.Logf("MCP '%v' has %v ready machines. Waiting for the desired ready machine count of %v.", poolName, mcp.Status.UpdatedMachineCount, readyMachineCount)
556+
// Log details of what is outstanding for the pool to be considered ready
557+
if mcp.Status.UpdatedMachineCount == readyMachineCount {
558+
framework.Logf("MCP '%v' has the desired %v ready machines, but is not in an 'Updated' state.", poolName, mcp.Status.UpdatedMachineCount)
559+
} else {
560+
framework.Logf("MCP '%v' has %v ready machines. Waiting for the desired ready machine count of %v.", poolName, mcp.Status.UpdatedMachineCount, readyMachineCount)
561+
}
556562
return false
557563
}, 5*time.Minute, 10*time.Second).Should(o.BeTrue(), "Timed out waiting for MCP '%v' to be in 'Updated' state with %v ready machines.", poolName, readyMachineCount)
558564
}
559565

566+
// `CleanupCustomMCP` cleans up a custom MCP through the following steps:
567+
// 1. Remove the custom MCP role label from the node
568+
// 2. Wait for the custom MCP to be updated with no ready machines
569+
// 3. Optionally, if a MC has been provided, delete it; if none has been provided, skip to step 4
570+
// 4. Wait for the node to have a current config version equal to the config version of the worker MCP
571+
// 5. Remove the custom MCP
572+
func CleanupCustomMCP(oc *exutil.CLI, clientSet *machineconfigclient.Clientset, customMCPName string, nodeName string, mcName *string) error {
573+
// Unlabel node
574+
framework.Logf("Removing label node-role.kubernetes.io/%v from node %v", customMCPName, nodeName)
575+
unlabelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", nodeName), fmt.Sprintf("node-role.kubernetes.io/%s-", customMCPName)).Execute()
576+
if unlabelErr != nil {
577+
return fmt.Errorf("could not remove label 'node-role.kubernetes.io/%v' from node '%v'; err: %v", customMCPName, nodeName, unlabelErr)
578+
}
579+
580+
// Wait for custom MCP to report no ready nodes
581+
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", customMCPName, 0)
582+
WaitForMCPToBeReady(oc, clientSet, customMCPName, 0)
583+
584+
// Delete the MC, if one was provided
585+
if mcName != nil {
586+
deleteMCErr := oc.Run("delete").Args("machineconfig", *mcName).Execute()
587+
if deleteMCErr != nil {
588+
return fmt.Errorf("could delete MachineConfig '%v'; err: %v", mcName, deleteMCErr)
589+
590+
}
591+
}
592+
593+
// Wait for node to have a current config version equal to the worker MCP's config version
594+
workerMcp, workerMcpErr := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
595+
if workerMcpErr != nil {
596+
return fmt.Errorf("could not get worker MCP; err: %v", workerMcpErr)
597+
}
598+
workerMcpConfig := workerMcp.Spec.Configuration.Name
599+
framework.Logf("Waiting for %v node to be updated with %v config version.", nodeName, workerMcpConfig)
600+
WaitForNodeCurrentConfig(oc, nodeName, workerMcpConfig)
601+
602+
// Delete custom MCP
603+
framework.Logf("Deleting MCP %v", customMCPName)
604+
deleteMCPErr := oc.Run("delete").Args("mcp", customMCPName).Execute()
605+
if deleteMCPErr != nil {
606+
return fmt.Errorf("error deleting MCP '%v': %v", customMCPName, deleteMCPErr)
607+
}
608+
609+
return nil
610+
}
611+
612+
// `WaitForNodeCurrentConfig` waits up to 5 minutes for a input node to have a current config equal to the `config` parameter
613+
func WaitForNodeCurrentConfig(oc *exutil.CLI, nodeName string, config string) {
614+
o.Eventually(func() bool {
615+
node, nodeErr := oc.AsAdmin().KubeClient().CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{})
616+
if nodeErr != nil {
617+
framework.Logf("Failed to get node '%v', error :%v", nodeName, nodeErr)
618+
return false
619+
}
620+
621+
// Check if the node's current config matches the input config version
622+
nodeCurrentConfig := node.Annotations[currentConfigAnnotationKey]
623+
if nodeCurrentConfig == config {
624+
framework.Logf("Node '%v' has successfully updated and has a current config version of '%v'.", nodeName, nodeCurrentConfig)
625+
return true
626+
}
627+
framework.Logf("Node '%v' has a current config version of '%v'. Waiting for the node's current config version to be '%v'.", nodeName, nodeCurrentConfig, config)
628+
return false
629+
}, 5*time.Minute, 10*time.Second).Should(o.BeTrue(), "Timed out waiting for node '%v' to have a current config version of '%v'.", nodeName, config)
630+
}
631+
560632
// `GetUpdatingNodeSNO` returns the SNO node when the `master` MCP of the cluster starts updating
561633
func GetUpdatingNodeSNO(oc *exutil.CLI, mcpName string) corev1.Node {
562634
// Wait for the MCP to start updating

test/extended/machine_config/machine_config_node.go

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

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

149144
// Cleanup custom MCP on test completion or failure
150145
defer func() {
151-
// Unlabel node
152-
framework.Logf("Removing label node-role.kubernetes.io/%v from node %v", custom, workerNode.Name)
153-
unlabelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", workerNode.Name), fmt.Sprintf("node-role.kubernetes.io/%s-", custom)).Execute()
154-
o.Expect(unlabelErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not remove label 'node-role.kubernetes.io/%s' from node '%v'.", custom, workerNode.Name))
155-
156-
// Wait for infra pool to report no nodes & for worker MCP to be ready
157-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", custom, 0)
158-
WaitForMCPToBeReady(oc, clientSet, custom, 0)
159-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", worker, workerMcpMachines)
160-
WaitForMCPToBeReady(oc, clientSet, worker, workerMcpMachines)
161-
162-
// Delete custom MCP
163-
framework.Logf("Deleting MCP %v", custom)
164-
deleteMCPErr := oc.Run("delete").Args("mcp", custom).Execute()
165-
o.Expect(deleteMCPErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error deleting MCP '%v': %v", custom, deleteMCPErr))
146+
cleanupErr := CleanupCustomMCP(oc, clientSet, custom, workerNode.Name, nil)
147+
o.Expect(cleanupErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Failed cleaning up '%v' MCP: %v.", custom, cleanupErr))
166148
}()
167149

168150
// Apply the fixture to create a custom MCP called "infra" & label the worker node accordingly
@@ -197,11 +179,6 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
197179
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
198180
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
199181

200-
// Get starting state of default worker MCP, so we know what the correct number of nodes is during cleanup
201-
workerMcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
202-
o.Expect(err).NotTo(o.HaveOccurred(), "Could not get worker MCP.")
203-
workerMcpMachines := workerMcp.Status.MachineCount
204-
205182
// Grab a random worker node
206183
workerNode := GetRandomNode(oc, worker)
207184
o.Expect(workerNode.Name).NotTo(o.Equal(""), "Could not get a worker node.")
@@ -218,27 +195,8 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
218195

219196
// Cleanup custom MCP, and delete MC on test completion or failure
220197
defer func() {
221-
// Unlabel node
222-
framework.Logf("Removing label node-role.kubernetes.io/%v from node %v", custom, workerNode.Name)
223-
unlabelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", workerNode.Name), fmt.Sprintf("node-role.kubernetes.io/%s-", custom)).Execute()
224-
o.Expect(unlabelErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not remove label 'node-role.kubernetes.io/%s' from node '%v'.", custom, workerNode.Name))
225-
226-
// Wait for infra MCP to report no ready nodes
227-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", custom, 0)
228-
WaitForMCPToBeReady(oc, clientSet, custom, 0)
229-
230-
// Delete applied MC
231-
deleteMCErr := oc.Run("delete").Args("machineconfig", mcName).Execute()
232-
o.Expect(deleteMCErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not delete MachineConfig '%v'.", mcName))
233-
234-
// Wait for worker MCP to be ready
235-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", worker, workerMcpMachines)
236-
WaitForMCPToBeReady(oc, clientSet, worker, workerMcpMachines)
237-
238-
// Delete custom MCP
239-
framework.Logf("Deleting MCP %v", custom)
240-
deleteMCPErr := oc.Run("delete").Args("mcp", custom).Execute()
241-
o.Expect(deleteMCPErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error deleting MCP '%v': %v", custom, deleteMCPErr))
198+
cleanupErr := CleanupCustomMCP(oc, clientSet, custom, workerNode.Name, &mcName)
199+
o.Expect(cleanupErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Failed cleaning up '%v' MCP: %v.", custom, cleanupErr))
242200
}()
243201

244202
// Apply the fixture to create a custom MCP called "infra" & label the worker node accordingly

0 commit comments

Comments
 (0)