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