Skip to content

Commit aa22c86

Browse files
MCO: update MCN condition transition test for clusters with no worker MCP nodes
1 parent dc5b8e7 commit aa22c86

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

test/extended/machine_config/helpers.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,33 @@ func WaitForNodeCurrentConfig(oc *exutil.CLI, nodeName string, config string) {
674674
}, 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)
675675
}
676676

677-
// `GetUpdatingNodeSNO` returns the SNO node when the `master` MCP of the cluster starts updating
678-
func GetUpdatingNodeSNO(oc *exutil.CLI, mcpName string) corev1.Node {
677+
// `GetCordonedNode` returns the cordoned node when the corresponding MCP starts updating
678+
func GetCordonedNode(oc *exutil.CLI, mcpName string) corev1.Node {
679679
// Wait for the MCP to start updating
680680
o.Expect(WaitForMCPConditionStatus(oc, mcpName, mcfgv1.MachineConfigPoolUpdating, corev1.ConditionTrue, 3*time.Minute, 2*time.Second)).NotTo(o.HaveOccurred(), "Waiting for 'Updating' status change failed.")
681681

682-
// SNO only has one node, so when the MCP is updating, the node is also updating
683-
node, nodeErr := GetNodesByRole(oc, mcpName)
684-
o.Expect(nodeErr).NotTo(o.HaveOccurred(), "Error getting nodes from %v MCP.", mcpName)
685-
o.Expect(node).ShouldNot(o.BeEmpty(), "No nodes found for %v MCP.", mcpName)
682+
// Get first cordoned node & return it
683+
var cordonedNode corev1.Node
684+
o.Eventually(func() bool {
685+
framework.Logf("Trying to get cordoned node in '%v' MCP.", mcpName)
686+
687+
// Get nodes in MCP
688+
nodes, nodeErr := GetNodesByRole(oc, mcpName)
689+
o.Expect(nodeErr).NotTo(o.HaveOccurred(), "Error getting nodes from %v MCP.", mcpName)
690+
o.Expect(nodes).ShouldNot(o.BeEmpty(), "No nodes found for %v MCP.", mcpName)
691+
692+
// Loop through nodes to see which is cordoned
693+
for _, node := range nodes {
694+
if node.Spec.Unschedulable {
695+
cordonedNode = node
696+
return true
697+
}
698+
}
699+
700+
return false
701+
}, 1*time.Minute, 5*time.Second).Should(o.BeTrue())
686702

687-
return node[0]
703+
return cordonedNode
688704
}
689705

690706
// `WaitForMCPConditionStatus` waits up to the desired timeout for the desired MCP condition to match the desired status (ex. wait until "Updating" is "True")

test/extended/machine_config/machine_config_node.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os/exec"
88
"path/filepath"
9+
"slices"
910
"time"
1011

1112
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
@@ -63,10 +64,19 @@ var _ = g.Describe("[Suite:openshift/machine-config-operator/disruptive][sig-mco
6364
})
6465

6566
g.It("[Suite:openshift/conformance/serial][Serial]Should properly transition through MCN conditions on rebootless node update [apigroup:machineconfiguration.openshift.io]", func() {
66-
if IsSingleNode(oc) {
67-
ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc, nodeDisruptionFixture, nodeDisruptionEmptyFixture, masterMCFixture)
68-
} else {
69-
ValidateMCNConditionTransitionsOnRebootlessUpdate(oc, nodeDisruptionFixture, nodeDisruptionEmptyFixture, customMCFixture, infraMCPFixture)
67+
// Create client set for test
68+
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
69+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
70+
71+
// Get MCPs to test for cluster
72+
poolNames := GetRolesToTest(oc, clientSet)
73+
framework.Logf("Validating MCN properties for node(s) in pool(s) '%v'.", poolNames)
74+
75+
// When the cluster has machines in the "worker" MCP, use a custom MCP to test the update
76+
if slices.Contains(poolNames, worker) {
77+
ValidateMCNConditionTransitionsOnRebootlessUpdate(oc, clientSet, nodeDisruptionFixture, nodeDisruptionEmptyFixture, customMCFixture, infraMCPFixture)
78+
} else { // When there are no machines in the "worker" MCP, test the update by applying a MC targeting the "master" MCP
79+
ValidateMCNConditionTransitionsOnRebootlessUpdateMaster(oc, clientSet, nodeDisruptionFixture, nodeDisruptionEmptyFixture, masterMCFixture)
7080
}
7181
})
7282

@@ -159,17 +169,17 @@ func ValidateMCNPropertiesCustomMCP(oc *exutil.CLI, fixture string) {
159169
o.Expect(mcnErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error validating MCN properties node in custom pool '%v'.", custom))
160170
}
161171

162-
// `ValidateMCNConditionTransitions` checks that Conditions properly update on a node update
163-
// Note that a custom MCP is created for this test to limit the number of upgrading nodes &
164-
// decrease cleanup time.
165-
func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string, mcpFixture string) {
172+
// `ValidateMCNConditionTransitionsOnRebootlessUpdate` checks that the `Conditions` in an MCN
173+
// properly update on a node update in a custom MCP. The steps of this function are:
174+
// 1. Apply a node disruption policy
175+
// 2. Create a custom MCP with one node
176+
// 3. Apply a MC
177+
// 4. Validate the MCN conditions transition as expected throughout the update
178+
// 5. Clean up the test resources
179+
func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, clientSet *machineconfigclient.Clientset, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string, mcpFixture string) {
166180
poolName := custom
167181
mcName := fmt.Sprintf("90-%v-testfile", poolName)
168182

169-
// Create client set for test
170-
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
171-
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
172-
173183
// Grab a random worker node
174184
workerNode := GetRandomNode(oc, worker)
175185
o.Expect(workerNode.Name).NotTo(o.Equal(""), "Could not get a worker node.")
@@ -209,16 +219,17 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
209219
o.Expect(ConfirmUpdatedMCNStatus(clientSet, updatingNodeName)).Should(o.BeTrue(), "Error, all conditions must be 'False' when Updated=True.")
210220
}
211221

212-
// `ValidateMCNConditionTransitionsSNO` checks that Conditions properly update on a node update
213-
// in Single Node Openshift
214-
func ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc *exutil.CLI, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string) {
222+
// `ValidateMCNConditionTransitionsOnRebootlessUpdateMaster` checks that the `Conditions` in an MCN
223+
// properly update on a node update in the master MCP. The steps of this function are:
224+
// 1. Apply a node disruption policy
225+
// 2. Apply a MC
226+
// 3. Get the updating node
227+
// 4. Validate the MCN conditions transition as expected throughout the update
228+
// 5. Clean up the test resources
229+
func ValidateMCNConditionTransitionsOnRebootlessUpdateMaster(oc *exutil.CLI, clientSet *machineconfigclient.Clientset, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string) {
215230
poolName := master
216231
mcName := fmt.Sprintf("90-%v-testfile", poolName)
217232

218-
// Create client set for test
219-
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
220-
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
221-
222233
// Remove node disruption policy on test completion or failure
223234
defer func() {
224235
// Apply empty MachineConfiguration fixture to remove previously set NodeDisruptionPolicy
@@ -242,12 +253,13 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc *exutil.CLI, nodeDi
242253
WaitForMCPToBeReady(oc, clientSet, poolName, 1)
243254
}()
244255

245-
// Apply MC targeting worker node
256+
// Apply MC targeting master MCP
246257
mcErr := oc.Run("apply").Args("-f", mcFixture).Execute()
247258
o.Expect(mcErr).NotTo(o.HaveOccurred(), "Could not apply MachineConfig.")
248259

249260
// Get the updating node
250-
updatingNode := GetUpdatingNodeSNO(oc, poolName)
261+
updatingNode := GetCordonedNode(oc, poolName)
262+
o.Expect(updatingNode).NotTo(o.BeNil(), "Could not get updating node.")
251263
framework.Logf("Node '%v' is updating.", updatingNode.Name)
252264

253265
// Validate transition through conditions for MCN

0 commit comments

Comments
 (0)