Skip to content

Commit 030b2cf

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

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

test/extended/machine_config/helpers.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,38 @@ 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+
// `GetCordonedNode` returns the cordoned node when the corresponding MCP starts updating
707+
func GetCordonedNode(oc *exutil.CLI, mcpName string) corev1.Node {
708708
// Wait for the MCP to start updating
709709
o.Expect(WaitForMCPConditionStatus(oc, mcpName, mcfgv1.MachineConfigPoolUpdating, corev1.ConditionTrue, 3*time.Minute, 2*time.Second)).NotTo(o.HaveOccurred(), "Waiting for 'Updating' status change failed.")
710710

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)
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)
715715

716-
return node[0]
716+
// Get first cordoned node & return it
717+
var cordonedNode corev1.Node
718+
o.Eventually(func() bool {
719+
framework.Logf("Trying to get cordoned node in '%v' MCP.", mcpName)
720+
721+
// Get nodes in MCP
722+
nodes, nodeErr := GetNodesByRole(oc, mcpName)
723+
o.Expect(nodeErr).NotTo(o.HaveOccurred(), "Error getting nodes from %v MCP.", mcpName)
724+
o.Expect(nodes).ShouldNot(o.BeEmpty(), "No nodes found for %v MCP.", mcpName)
725+
726+
// Loop through nodes to see which is cordoned
727+
for _, node := range nodes {
728+
if node.Spec.Unschedulable {
729+
cordonedNode = node
730+
return true
731+
}
732+
}
733+
734+
return false
735+
}, 1*time.Minute, 5*time.Second).Should(o.BeTrue())
736+
737+
return cordonedNode
717738
}
718739

719740
// `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"
@@ -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,16 +228,17 @@ 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.")
230-
231242
// Remove node disruption policy on test completion or failure
232243
defer func() {
233244
// Apply empty MachineConfiguration fixture to remove previously set NodeDisruptionPolicy
@@ -251,12 +262,13 @@ func ValidateMCNConditionTransitionsOnRebootlessUpdateSNO(oc *exutil.CLI, nodeDi
251262
WaitForMCPToBeReady(oc, clientSet, poolName, 1)
252263
}()
253264

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

258269
// Get the updating node
259-
updatingNode := GetUpdatingNodeSNO(oc, poolName)
270+
updatingNode := GetCordonedNode(oc, poolName)
271+
o.Expect(updatingNode).NotTo(o.BeNil(), "Could not get updating node.")
260272
framework.Logf("Node '%v' is updating.", updatingNode.Name)
261273

262274
// Validate transition through conditions for MCN

0 commit comments

Comments
 (0)