Skip to content

Commit 61c4f08

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

File tree

2 files changed

+64
-29
lines changed

2 files changed

+64
-29
lines changed

test/extended/machine_config/helpers.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,34 @@ 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+
// `GetUpdatingNode` returns the updating node, determined by the node targetting a new desired
678+
// config, when the corresponding MCP starts updating
679+
func GetUpdatingNode(oc *exutil.CLI, mcpName, originalConfigVersion string) corev1.Node {
679680
// Wait for the MCP to start updating
680681
o.Expect(WaitForMCPConditionStatus(oc, mcpName, mcfgv1.MachineConfigPoolUpdating, corev1.ConditionTrue, 3*time.Minute, 2*time.Second)).NotTo(o.HaveOccurred(), "Waiting for 'Updating' status change failed.")
681682

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)
683+
// Get first updating node & return it
684+
var updatingNode corev1.Node
685+
o.Eventually(func() bool {
686+
framework.Logf("Trying to get updating node in '%v' MCP.", mcpName)
687+
688+
// Get nodes in MCP
689+
nodes, nodeErr := GetNodesByRole(oc, mcpName)
690+
o.Expect(nodeErr).NotTo(o.HaveOccurred(), "Error getting nodes from %v MCP.", mcpName)
691+
o.Expect(nodes).ShouldNot(o.BeEmpty(), "No nodes found for %v MCP.", mcpName)
692+
693+
// Loop through nodes to see which is targetting a new desired config version
694+
for _, node := range nodes {
695+
if node.Annotations[desiredConfigAnnotationKey] != originalConfigVersion {
696+
updatingNode = node
697+
return true
698+
}
699+
}
700+
701+
return false
702+
}, 30*time.Second, 1*time.Second).Should(o.BeTrue())
686703

687-
return node[0]
704+
return updatingNode
688705
}
689706

690707
// `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: 40 additions & 22 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,15 +219,22 @@ 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.")
233+
// Get the starting config version & machine count
234+
mcp, mcpErr := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), poolName, metav1.GetOptions{})
235+
o.Expect(mcpErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not get MCP '%v'; %v", poolName, mcpErr))
236+
startingConfigVersion := mcp.Spec.Configuration.Name
237+
machineCount := mcp.Status.MachineCount
221238

222239
// Remove node disruption policy on test completion or failure
223240
defer func() {
@@ -238,16 +255,17 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc *exutil.CLI, nodeDi
238255

239256
// Wait for master MCP to be ready
240257
time.Sleep(15 * time.Second) //wait to not catch the updated state before the deleted mc triggers an update
241-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", poolName, 1)
242-
WaitForMCPToBeReady(oc, clientSet, poolName, 1)
258+
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", poolName, machineCount)
259+
WaitForMCPToBeReady(oc, clientSet, poolName, machineCount)
243260
}()
244261

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

249266
// Get the updating node
250-
updatingNode := GetUpdatingNodeSNO(oc, poolName)
267+
updatingNode := GetUpdatingNode(oc, poolName, startingConfigVersion)
268+
o.Expect(updatingNode).NotTo(o.BeNil(), "Could not get updating node.")
251269
framework.Logf("Node '%v' is updating.", updatingNode.Name)
252270

253271
// Validate transition through conditions for MCN

0 commit comments

Comments
 (0)