Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2c3a5c2

Browse files
committedApr 1, 2025·
update error catching
1 parent da4e47b commit 2c3a5c2

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed
 

‎test/extended/machine_config/machine_config_node.go

+43-42
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var _ = g.Describe("[sig-mco][OCPFeatureGate:MachineConfigNodes]", func() {
7070
func ValidateMCNProperties(oc *exutil.CLI, fixture string) {
7171
// Create client set for test
7272
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
73-
o.Expect(clientErr).NotTo(o.HaveOccurred())
73+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
7474

7575
// Grab a random node from each default pool
7676
workerNode := GetRandomNode(oc, worker)
@@ -92,13 +92,13 @@ func ValidateMCNProperties(oc *exutil.CLI, fixture string) {
9292
defer func() {
9393
// Get starting state of default worker MCP
9494
workerMcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), worker, metav1.GetOptions{})
95-
o.Expect(err).NotTo(o.HaveOccurred())
95+
o.Expect(err).NotTo(o.HaveOccurred(), "Could not get worker MCP.")
9696
workerMcpReadyMachines := workerMcp.Status.ReadyMachineCount
9797

9898
// Unlabel node
9999
framework.Logf("Removing label node-role.kubernetes.io/%v from node %v", custom, workerNode.Name)
100100
unlabelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", workerNode.Name), fmt.Sprintf("node-role.kubernetes.io/%s-", custom)).Execute()
101-
o.Expect(unlabelErr).NotTo(o.HaveOccurred())
101+
o.Expect(unlabelErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not remove label 'node-role.kubernetes.io/%s' from node '%v'.", custom, workerNode.Name))
102102

103103
// Wait for infra pool to report no nodes & for worker MCP to be ready
104104
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", custom, 0)
@@ -109,22 +109,22 @@ func ValidateMCNProperties(oc *exutil.CLI, fixture string) {
109109
// Delete custom MCP
110110
framework.Logf("Deleting MCP %v", custom)
111111
deleteMCPErr := oc.Run("delete").Args("mcp", custom).Execute()
112-
o.Expect(deleteMCPErr).NotTo(o.HaveOccurred())
112+
o.Expect(deleteMCPErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error deleting MCP '%v': %v", custom, deleteMCPErr))
113113
}()
114114

115115
// Apply the fixture to create a custom MCP called "infra" & label the worker node accordingly
116116
mcpErr := oc.Run("apply").Args("-f", fixture).Execute()
117-
o.Expect(mcpErr).NotTo(o.HaveOccurred())
117+
o.Expect(mcpErr).NotTo(o.HaveOccurred(), "Could not create custom MCP.")
118118
labelErr := oc.Run("label").Args(fmt.Sprintf("node/%s", workerNode.Name), fmt.Sprintf("node-role.kubernetes.io/%s=", custom)).Execute()
119-
o.Expect(labelErr).NotTo(o.HaveOccurred())
119+
o.Expect(labelErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not add label 'node-role.kubernetes.io/%s' to node '%v'.", custom, workerNode.Name))
120120

121121
// Wait for the custom pool to be updated with the node ready
122122
framework.Logf("Waiting for '%v' MCP to be updated with %v ready machines.", custom, 1)
123123
WaitForMCPToBeReady(oc, clientSet, custom, 1)
124124

125-
// Get node desired and current config versions
125+
// Get node in custom pool
126126
customNodes, customNodeErr := GetNodesByRole(oc, custom)
127-
o.Expect(customNodeErr).NotTo(o.HaveOccurred())
127+
o.Expect(customNodeErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not get node in MCP '%v'.", custom))
128128
customNode := customNodes[0]
129129

130130
// Validate MCN for node in custom pool
@@ -139,7 +139,7 @@ func ValidateMCNProperties(oc *exutil.CLI, fixture string) {
139139
func ValidateMCNPropertiesSNO(oc *exutil.CLI, fixture string) {
140140
// Create client set for test
141141
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
142-
o.Expect(clientErr).NotTo(o.HaveOccurred())
142+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
143143

144144
// Grab the cluster's node
145145
node := GetRandomNode(oc, master)
@@ -155,21 +155,21 @@ func ValidateMCNPropertiesSNO(oc *exutil.CLI, fixture string) {
155155
func ValidateMCNConditionTransitions(oc *exutil.CLI, fixture string) {
156156
// Create client set for test
157157
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
158-
o.Expect(clientErr).NotTo(o.HaveOccurred())
158+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
159159

160160
// Delete MC on failure or test completion
161161
defer func() {
162162
deleteMCErr := oc.Run("delete").Args("machineconfig", "90-master-testfile").Execute()
163-
o.Expect(deleteMCErr).NotTo(o.HaveOccurred())
163+
o.Expect(deleteMCErr).NotTo(o.HaveOccurred(), "Could not delete MachineConfig '90-master-testfile'.")
164164
}()
165165

166166
// Apply MC targeting master pool
167167
mcErr := oc.Run("apply").Args("-f", fixture).Execute()
168-
o.Expect(mcErr).NotTo(o.HaveOccurred())
168+
o.Expect(mcErr).NotTo(o.HaveOccurred(), "Could not apply MachineConfig.")
169169

170170
// Get an updating master node
171171
updatingNodes := GetCordonedNodes(oc, master)
172-
o.Expect(len(updatingNodes) > 0, "No ready nodes found for MCP '%v'.", master)
172+
o.Expect(len(updatingNodes) > 0, fmt.Sprintf("No ready nodes found for MCP '%v'.", master))
173173
masterNode := updatingNodes[0]
174174

175175
// Validate transition through conditions for MCN
@@ -178,37 +178,37 @@ func ValidateMCNConditionTransitions(oc *exutil.CLI, fixture string) {
178178
// a warning will be logged instead of erroring out the test.
179179
framework.Logf("Waiting for Updated=False")
180180
err := WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdated, metav1.ConditionFalse, 1*time.Minute, 1*time.Second)
181-
o.Expect(err).NotTo(o.HaveOccurred())
181+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect Updated=False.")
182182
framework.Logf("Waiting for UpdatePrepared=True")
183183
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdatePrepared, metav1.ConditionTrue, 1*time.Minute, 1*time.Second)
184-
o.Expect(err).NotTo(o.HaveOccurred())
184+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect UpdatePrepared=True.")
185185
framework.Logf("Waiting for UpdateExecuted=Unknown")
186186
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateExecuted, metav1.ConditionUnknown, 30*time.Second, 1*time.Second)
187187
if err != nil {
188188
framework.Logf("Warning, could not detect UpdateExecuted=Unknown.")
189189
}
190190
framework.Logf("Waiting for Cordoned=True")
191191
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateCordoned, metav1.ConditionTrue, 30*time.Second, 1*time.Second)
192-
o.Expect(err).NotTo(o.HaveOccurred())
192+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect Cordoned=True.")
193193
framework.Logf("Waiting for Drained=Unknown")
194194
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateDrained, metav1.ConditionUnknown, 15*time.Second, 1*time.Second)
195195
if err != nil {
196196
framework.Logf("Warning, could not detect Drained=Unknown.")
197197
}
198198
framework.Logf("Waiting for Drained=True")
199199
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateDrained, metav1.ConditionTrue, 4*time.Minute, 1*time.Second)
200-
o.Expect(err).NotTo(o.HaveOccurred())
200+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect Drained=True.")
201201
framework.Logf("Waiting for AppliedFilesAndOS=Unknown")
202202
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateFilesAndOS, metav1.ConditionUnknown, 30*time.Second, 1*time.Second)
203203
if err != nil {
204204
framework.Logf("Warning, could not detect AppliedFilesAndOS=Unknown.")
205205
}
206206
framework.Logf("Waiting for AppliedFilesAndOS=True")
207207
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateFilesAndOS, metav1.ConditionTrue, 3*time.Minute, 1*time.Second)
208-
o.Expect(err).NotTo(o.HaveOccurred())
208+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect AppliedFilesAndOS=True.")
209209
framework.Logf("Waiting for UpdateExecuted=True")
210210
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateExecuted, metav1.ConditionTrue, 20*time.Second, 1*time.Second)
211-
o.Expect(err).NotTo(o.HaveOccurred())
211+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect UpdateExecuted=True.")
212212
framework.Logf("Waiting for UpdatePostActionComplete=Unknown")
213213
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdatePostActionComplete, metav1.ConditionUnknown, 30*time.Second, 1*time.Second)
214214
if err != nil {
@@ -221,30 +221,30 @@ func ValidateMCNConditionTransitions(oc *exutil.CLI, fixture string) {
221221
}
222222
framework.Logf("Waiting for RebootedNode=True")
223223
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateRebooted, metav1.ConditionTrue, 5*time.Minute, 1*time.Second)
224-
o.Expect(err).NotTo(o.HaveOccurred())
224+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect RebootedNode=True.")
225225
framework.Logf("Waiting for Resumed=True")
226226
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeResumed, metav1.ConditionTrue, 15*time.Second, 1*time.Second)
227-
o.Expect(err).NotTo(o.HaveOccurred())
227+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect Resumed=True.")
228228
framework.Logf("Waiting for UpdateComplete=True")
229229
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateComplete, metav1.ConditionTrue, 10*time.Second, 1*time.Second)
230-
o.Expect(err).NotTo(o.HaveOccurred())
230+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect UpdateComplete=True.")
231231
framework.Logf("Waiting for Uncordoned=True")
232232
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdateUncordoned, metav1.ConditionTrue, 10*time.Second, 1*time.Second)
233-
o.Expect(err).NotTo(o.HaveOccurred())
233+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect Uncordoned=True.")
234234
framework.Logf("Waiting for Updated=True")
235235
err = WaitForMCNConditionStatus(clientSet, masterNode.Name, mcfgv1alpha1.MachineConfigNodeUpdated, metav1.ConditionTrue, 1*time.Minute, 1*time.Second)
236-
o.Expect(err).NotTo(o.HaveOccurred())
236+
o.Expect(err).NotTo(o.HaveOccurred(), "Error, could not detect Updated=True.")
237237

238238
// When an update is complete, all conditions other than `Updated` must be false
239239
framework.Logf("Checking all conditions other than 'Updated' are False.")
240-
o.Expect(ConfirmUpdatedMCNStatus(clientSet, masterNode.Name)).Should(o.BeTrue())
240+
o.Expect(ConfirmUpdatedMCNStatus(clientSet, masterNode.Name)).Should(o.BeTrue(), "Error, all conditions must be 'False' when Updated=True.")
241241
}
242242

243243
// `ValidateMCNConditionOnNodeDegrade` checks that Conditions properly update on a node failure (MCP degrade)
244244
func ValidateMCNConditionOnNodeDegrade(oc *exutil.CLI, fixture string, isSno bool) {
245245
// Create client set for test
246246
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
247-
o.Expect(clientErr).NotTo(o.HaveOccurred())
247+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
248248

249249
// In SNO, master pool will degrade
250250
poolName := worker
@@ -258,33 +258,34 @@ func ValidateMCNConditionOnNodeDegrade(oc *exutil.CLI, fixture string, isSno boo
258258
defer func() {
259259
// Delete the applied MC
260260
deleteMCErr := oc.Run("delete").Args("machineconfig", mcName).Execute()
261-
o.Expect(deleteMCErr).NotTo(o.HaveOccurred())
261+
o.Expect(deleteMCErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not delete MachineConfig '%v'.", mcName))
262262

263263
// Recover the degraded MCP
264264
recoverErr := RecoverFromDegraded(oc, poolName)
265-
o.Expect(recoverErr).NotTo(o.HaveOccurred())
265+
o.Expect(recoverErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not recover MCP '%v' from degraded state.", poolName))
266266
}()
267267

268268
// Apply invalid MC
269269
mcErr := oc.Run("apply").Args("-f", fixture).Execute()
270-
o.Expect(mcErr).NotTo(o.HaveOccurred())
270+
o.Expect(mcErr).NotTo(o.HaveOccurred(), "Could not apply MachineConfig.")
271271

272272
// Wait for MCP to be in a degraded state with one degraded machine
273-
o.Expect(WaitForMCPConditionStatus(oc, poolName, "Degraded", corev1.ConditionTrue, 8*time.Minute, 3*time.Second)).NotTo(o.HaveOccurred(), fmt.Sprintf("Error waiting for '%v' MCP to be in a degraded state.", poolName))
273+
degradedErr := WaitForMCPConditionStatus(oc, poolName, "Degraded", corev1.ConditionTrue, 8*time.Minute, 3*time.Second)
274+
o.Expect(degradedErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error waiting for '%v' MCP to be in a degraded state.", poolName))
274275
mcp, err := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), poolName, metav1.GetOptions{})
275-
o.Expect(err).NotTo(o.HaveOccurred(), "Error getting '%v' MCP.", poolName)
276+
o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("Error getting '%v' MCP.", poolName))
276277
o.Expect(mcp.Status.DegradedMachineCount).To(o.BeNumerically("==", 1), fmt.Sprintf("Degraded machine count is not 1. It is %v.", mcp.Status.DegradedMachineCount))
277278

278279
// Get degraded node
279280
degradedNode, degradedNodeErr := GetDegradedNode(oc, poolName)
280-
o.Expect(degradedNodeErr).NotTo(o.HaveOccurred())
281+
o.Expect(degradedNodeErr).NotTo(o.HaveOccurred(), "Could not get degraded node.")
281282

282283
// Validate MCN of degraded node
283284
degradedNodeMCN, degradedErr := clientSet.MachineconfigurationV1alpha1().MachineConfigNodes().Get(context.TODO(), degradedNode.Name, metav1.GetOptions{})
284-
o.Expect(degradedErr).NotTo(o.HaveOccurred())
285+
o.Expect(degradedErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error getting MCN of degraded node '%v'.", degradedNode.Name))
285286
framework.Logf("Validating that `AppliedFilesAndOS` and `UpdateExecuted` conditions in '%v' MCN have a status of 'Unknown'.", degradedNodeMCN.Name)
286-
o.Expect(CheckMCNConditionStatus(degradedNodeMCN, mcfgv1alpha1.MachineConfigNodeUpdateFilesAndOS, metav1.ConditionUnknown))
287-
o.Expect(CheckMCNConditionStatus(degradedNodeMCN, mcfgv1alpha1.MachineConfigNodeUpdateExecuted, metav1.ConditionUnknown))
287+
o.Expect(CheckMCNConditionStatus(degradedNodeMCN, mcfgv1alpha1.MachineConfigNodeUpdateFilesAndOS, metav1.ConditionUnknown)).Should(o.BeTrue(), "Condition 'AppliedFilesAndOS' does not have the expected status of 'Unknown'.")
288+
o.Expect(CheckMCNConditionStatus(degradedNodeMCN, mcfgv1alpha1.MachineConfigNodeUpdateExecuted, metav1.ConditionUnknown)).Should(o.BeTrue(), "Condition 'UpdateExecuted' does not have the expected status of 'Unknown'.")
288289
}
289290

290291
// `ValidateMCNProperties` checks that MCNs with correct properties are created on node creation
@@ -296,15 +297,15 @@ func ValidateMCNOnNodeCreationAndDeletion(oc *exutil.CLI) {
296297

297298
// Create machine client for test
298299
machineClient, machineErr := machineclient.NewForConfig(oc.KubeFramework().ClientConfig())
299-
o.Expect(machineErr).NotTo(o.HaveOccurred())
300+
o.Expect(machineErr).NotTo(o.HaveOccurred(), "Error creating machine client for test.")
300301

301302
// Create client set for test
302303
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
303-
o.Expect(clientErr).NotTo(o.HaveOccurred())
304+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
304305

305306
// Skip test if worker nodes cannot be scaled
306307
canBeScaled, canScaleErr := WorkersCanBeScaled(oc, machineClient)
307-
o.Expect(canScaleErr).NotTo(o.HaveOccurred())
308+
o.Expect(canScaleErr).NotTo(o.HaveOccurred(), "Error occured when determining whether worker nodes can be scaled.")
308309
if !canBeScaled {
309310
g.Skip("Worker nodes cannot be scaled using MachineSets. This test cannot be executed if workers cannot be scaled via MachineSets.")
310311
}
@@ -325,7 +326,7 @@ func ValidateMCNOnNodeCreationAndDeletion(oc *exutil.CLI) {
325326
// original value, when needed (in the case where the replica value patch was successful).
326327
defer func() {
327328
cleanupErr := ScaleMachineSetDown(oc, machineSet, originalReplica, cleanupCompleted)
328-
o.Expect(cleanupErr).NotTo(o.HaveOccurred())
329+
o.Expect(cleanupErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error cleaning up cluster by scaling down MachineSet '%v'.", machineSet.Name))
329330
cleanupCompleted = true
330331
}()
331332

@@ -339,7 +340,7 @@ func ValidateMCNOnNodeCreationAndDeletion(oc *exutil.CLI) {
339340
// original value and ensuring that the newly provisioned Machine is deleted.
340341
defer func() {
341342
cleanupErr := CleanupProvisionedMachine(oc, machineClient, machineSet.Name, originalReplica, newMachineName, cleanupCompleted)
342-
o.Expect(cleanupErr).NotTo(o.HaveOccurred())
343+
o.Expect(cleanupErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error removing provisioned Machine '%v' by scaling down MachineSet '%v'.", newMachineName, machineSet.Name))
343344
cleanupCompleted = true
344345
}()
345346

@@ -362,13 +363,13 @@ func ValidateMCNOnNodeCreationAndDeletion(oc *exutil.CLI) {
362363
// original value and ensuring that the newly created Node is deleted.
363364
defer func() {
364365
cleanupErr := CleanupCreatedNode(oc, newMachineName, originalReplica, newNode.Name, cleanupCompleted)
365-
o.Expect(cleanupErr).NotTo(o.HaveOccurred())
366+
o.Expect(cleanupErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error removing created Node '%v' by scaling down MachineSet '%v'.", newNode.Name, machineSet.Name))
366367
cleanupCompleted = true
367368
}()
368369

369370
// Validate new MCN
370371
validMCNErr := WaitForValidMCNProperties(clientSet, newNode)
371-
o.Expect(validMCNErr).NotTo(o.HaveOccurred())
372+
o.Expect(validMCNErr).NotTo(o.HaveOccurred(), fmt.Sprintf("MCN for node '%v' has invalid properties.", newNode))
372373

373374
// Scale down the MachineSet to delete the created node
374375
framework.Logf("Scaling down MachineSet to delete node.")

0 commit comments

Comments
 (0)
Please sign in to comment.