Skip to content

Commit a9bad0e

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

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

test/extended/machine_config/helpers.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,34 @@ func WaitForNodeCurrentConfig(oc *exutil.CLI, nodeName string, config string) {
703703
}, 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)
704704
}
705705

706-
// `GetUpdatingNodeSNO` returns the SNO node when the `master` MCP of the cluster starts updating
707-
func GetUpdatingNodeSNO(oc *exutil.CLI, mcpName string) corev1.Node {
706+
// `GetUpdatingNode` returns the updating node, determined by the node targetting a new desired
707+
// config, when the corresponding MCP starts updating
708+
func GetUpdatingNode(oc *exutil.CLI, mcpName, originalConfigVersion string) corev1.Node {
708709
// Wait for the MCP to start updating
709710
o.Expect(WaitForMCPConditionStatus(oc, mcpName, mcfgv1.MachineConfigPoolUpdating, corev1.ConditionTrue, 3*time.Minute, 2*time.Second)).NotTo(o.HaveOccurred(), "Waiting for 'Updating' status change failed.")
710711

711-
// SNO only has one node, so when the MCP is updating, the node is also updating
712-
node, nodeErr := GetNodesByRole(oc, mcpName)
713-
o.Expect(nodeErr).NotTo(o.HaveOccurred(), "Error getting nodes from %v MCP.", mcpName)
714-
o.Expect(node).ShouldNot(o.BeEmpty(), "No nodes found for %v MCP.", mcpName)
712+
// Get first updating node & return it
713+
var updatingNode corev1.Node
714+
o.Eventually(func() bool {
715+
framework.Logf("Trying to get updating node in '%v' MCP.", mcpName)
716+
717+
// Get nodes in MCP
718+
nodes, nodeErr := GetNodesByRole(oc, mcpName)
719+
o.Expect(nodeErr).NotTo(o.HaveOccurred(), "Error getting nodes from %v MCP.", mcpName)
720+
o.Expect(nodes).ShouldNot(o.BeEmpty(), "No nodes found for %v MCP.", mcpName)
721+
722+
// Loop through nodes to see which is targetting a new desired config version
723+
for _, node := range nodes {
724+
if node.Annotations[desiredConfigAnnotationKey] != originalConfigVersion {
725+
updatingNode = node
726+
return true
727+
}
728+
}
729+
730+
return false
731+
}, 30*time.Second, 1*time.Second).Should(o.BeTrue())
715732

716-
return node[0]
733+
return updatingNode
717734
}
718735

719736
// `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: 39 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"
@@ -77,10 +78,19 @@ var _ = g.Describe("[sig-mco][OCPFeatureGate:MachineConfigNodes]", func() {
7778
// regression tests handle the different conditions list.
7879
SkipWhenFeatureGateEnabled(oc.AdminConfigClient(), "ImageModeStatusReporting")
7980

80-
if IsSingleNode(oc) {
81-
ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc, nodeDisruptionFixture, nodeDisruptionEmptyFixture, masterMCFixture)
82-
} else {
83-
ValidateMCNConditionTransitionsOnRebootlessUpdate(oc, nodeDisruptionFixture, nodeDisruptionEmptyFixture, customMCFixture, infraMCPFixture)
81+
// Create client set for test
82+
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
83+
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
84+
85+
// Get MCPs to test for cluster
86+
poolNames := GetRolesToTest(oc, clientSet)
87+
framework.Logf("Validating MCN properties for node(s) in pool(s) '%v'.", poolNames)
88+
89+
// When the cluster has machines in the "worker" MCP, use a custom MCP to test the update
90+
if slices.Contains(poolNames, worker) {
91+
ValidateMCNConditionTransitionsOnRebootlessUpdate(oc, clientSet, nodeDisruptionFixture, nodeDisruptionEmptyFixture, customMCFixture, infraMCPFixture)
92+
} else { // When there are no machines in the "worker" MCP, test the update by applying a MC targeting the "master" MCP
93+
ValidateMCNConditionTransitionsOnRebootlessUpdateMaster(oc, clientSet, nodeDisruptionFixture, nodeDisruptionEmptyFixture, masterMCFixture)
8494
}
8595
})
8696

@@ -168,17 +178,17 @@ func ValidateMCNPropertiesCustomMCP(oc *exutil.CLI, fixture string) {
168178
o.Expect(mcnErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Error validating MCN properties node in custom pool '%v'.", custom))
169179
}
170180

171-
// `ValidateMCNConditionTransitions` checks that Conditions properly update on a node update
172-
// Note that a custom MCP is created for this test to limit the number of upgrading nodes &
173-
// decrease cleanup time.
174-
func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string, mcpFixture string) {
181+
// `ValidateMCNConditionTransitionsOnRebootlessUpdate` checks that the `Conditions` in an MCN
182+
// properly update on a node update in a custom MCP. The steps of this function are:
183+
// 1. Apply a node disruption policy
184+
// 2. Create a custom MCP with one node
185+
// 3. Apply a MC
186+
// 4. Validate the MCN conditions transition as expected throughout the update
187+
// 5. Clean up the test resources
188+
func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, clientSet *machineconfigclient.Clientset, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string, mcpFixture string) {
175189
poolName := custom
176190
mcName := fmt.Sprintf("90-%v-testfile", poolName)
177191

178-
// Create client set for test
179-
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
180-
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
181-
182192
// Grab a random worker node
183193
workerNode := GetRandomNode(oc, worker)
184194
o.Expect(workerNode.Name).NotTo(o.Equal(""), "Could not get a worker node.")
@@ -218,15 +228,22 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdate(oc *exutil.CLI, nodeDisru
218228
o.Expect(ConfirmUpdatedMCNStatus(clientSet, updatingNodeName)).Should(o.BeTrue(), "Error, all conditions must be 'False' when Updated=True.")
219229
}
220230

221-
// `ValidateMCNConditionTransitionsSNO` checks that Conditions properly update on a node update
222-
// in Single Node Openshift
223-
func ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc *exutil.CLI, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string) {
231+
// `ValidateMCNConditionTransitionsOnRebootlessUpdateMaster` checks that the `Conditions` in an MCN
232+
// properly update on a node update in the master MCP. The steps of this function are:
233+
// 1. Apply a node disruption policy
234+
// 2. Apply a MC
235+
// 3. Get the updating node
236+
// 4. Validate the MCN conditions transition as expected throughout the update
237+
// 5. Clean up the test resources
238+
func ValidateMCNConditionTransitionsOnRebootlessUpdateMaster(oc *exutil.CLI, clientSet *machineconfigclient.Clientset, nodeDisruptionFixture string, nodeDisruptionEmptyFixture string, mcFixture string) {
224239
poolName := master
225240
mcName := fmt.Sprintf("90-%v-testfile", poolName)
226241

227-
// Create client set for test
228-
clientSet, clientErr := machineconfigclient.NewForConfig(oc.KubeFramework().ClientConfig())
229-
o.Expect(clientErr).NotTo(o.HaveOccurred(), "Error creating client set for test.")
242+
// Get the starting config version & machine count
243+
mcp, mcpErr := clientSet.MachineconfigurationV1().MachineConfigPools().Get(context.TODO(), poolName, metav1.GetOptions{})
244+
o.Expect(mcpErr).NotTo(o.HaveOccurred(), fmt.Sprintf("Could not get MCP '%v'; %v", poolName, mcpErr))
245+
startingConfigVersion := mcp.Spec.Configuration.Name
246+
machineCount := mcp.Status.MachineCount
230247

231248
// Remove node disruption policy on test completion or failure
232249
defer func() {
@@ -247,16 +264,17 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc *exutil.CLI, nodeDi
247264

248265
// Wait for master MCP to be ready
249266
time.Sleep(15 * time.Second) //wait to not catch the updated state before the deleted mc triggers an update
250-
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", poolName, 1)
267+
framework.Logf("Waiting for %v MCP to be updated with %v ready machines.", poolName, machineCount)
251268
WaitForMCPToBeReady(oc, clientSet, poolName, 1)
252269
}()
253270

254-
// Apply MC targeting worker node
271+
// Apply MC targeting master MCP
255272
mcErr := oc.Run("apply").Args("-f", mcFixture).Execute()
256273
o.Expect(mcErr).NotTo(o.HaveOccurred(), "Could not apply MachineConfig.")
257274

258275
// Get the updating node
259-
updatingNode := GetUpdatingNodeSNO(oc, poolName)
276+
updatingNode := GetUpdatingNode(oc, poolName, startingConfigVersion)
277+
o.Expect(updatingNode).NotTo(o.BeNil(), "Could not get updating node.")
260278
framework.Logf("Node '%v' is updating.", updatingNode.Name)
261279

262280
// Validate transition through conditions for MCN

0 commit comments

Comments
 (0)