|
| 1 | +package extended |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + g "github.com/onsi/ginkgo/v2" |
| 7 | + o "github.com/onsi/gomega" |
| 8 | + constants "github.com/openshift/machine-config-operator/pkg/controller/common" |
| 9 | + exutil "github.com/openshift/machine-config-operator/test/extended-priv/util" |
| 10 | + logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" |
| 11 | +) |
| 12 | + |
| 13 | +const ( |
| 14 | + // Test RHCOS & OCP versions for skew enforcement tests |
| 15 | + rhcosVersionExceedsSkew = "48.84.202208021106-0" |
| 16 | + ocpVersionExceedsSkew = "4.12.0" |
| 17 | +) |
| 18 | + |
| 19 | +var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive][Serial][Disruptive][OCPFeatureGate:BootImageSkewEnforcement]", func() { |
| 20 | + defer g.GinkgoRecover() |
| 21 | + |
| 22 | + var ( |
| 23 | + oc = exutil.NewCLI("mco-bootimage", exutil.KubeConfigPath()).AsAdmin() |
| 24 | + machineConfiguration *MachineConfiguration |
| 25 | + originalSpec string |
| 26 | + mcoCO *ClusterOperator |
| 27 | + ) |
| 28 | + |
| 29 | + g.BeforeEach(func() { |
| 30 | + // Skip on single-node topologies |
| 31 | + exutil.SkipOnSingleNodeTopology(oc) |
| 32 | + machineConfiguration = GetMachineConfiguration(oc) |
| 33 | + // Save initial state to restore after each test |
| 34 | + originalSpec = machineConfiguration.GetSpecOrFail() |
| 35 | + mcoCO = NewClusterOperator(oc, "machine-config") |
| 36 | + }) |
| 37 | + |
| 38 | + g.AfterEach(func() { |
| 39 | + exutil.By("Restoring MachineConfiguration to original state") |
| 40 | + o.Expect(machineConfiguration.SetSpec(originalSpec)).To(o.Succeed()) |
| 41 | + }) |
| 42 | + |
| 43 | + g.It("Verify Manual mode with RHCOSVersion and Upgradeable (Happy case) [apigroup:machineconfiguration.openshift.io]", func() { |
| 44 | + // Get the current RHCOS version from the coreos-bootimages configmap (guaranteed to be within skew) |
| 45 | + rhcosVersionWithinSkew := GetRHCOSVersionFromConfigMap(oc) |
| 46 | + logger.Infof("Using RHCOS version from configmap: %s", rhcosVersionWithinSkew) |
| 47 | + |
| 48 | + // Set manual mode with a boot image version that is within skew limits |
| 49 | + o.Expect(machineConfiguration.SetManualSkew(RHCOSVersionMode, rhcosVersionWithinSkew)).To(o.Succeed()) |
| 50 | + |
| 51 | + // Wait for the controller to reflect Manual mode in skew enforcement status |
| 52 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementManualMode) |
| 53 | + |
| 54 | + // Check machine-config CO upgradeable status, should be set to true |
| 55 | + o.Eventually(mcoCO, "1m", "10s").Should(BeUpgradeable(), "co/machine-config should be upgradeable when manual skew version is within limits") |
| 56 | + }) |
| 57 | + |
| 58 | + g.It("Verify Manual mode with RHCOSVersion and Upgradeable (Sad case) [apigroup:machineconfiguration.openshift.io]", func() { |
| 59 | + // Set manual mode with a boot image version that is NOT within skew limits |
| 60 | + o.Expect(machineConfiguration.SetManualSkew(RHCOSVersionMode, rhcosVersionExceedsSkew)).To(o.Succeed()) |
| 61 | + |
| 62 | + // Wait for the controller to reflect Manual mode in skew enforcement status |
| 63 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementManualMode) |
| 64 | + |
| 65 | + // Check machine-config CO upgradeable status, should be set to false |
| 66 | + o.Eventually(mcoCO, "1m", "10s").ShouldNot(BeUpgradeable(), "co/machine-config should not be upgradeable when manual skew version exceeds limits") |
| 67 | + }) |
| 68 | + |
| 69 | + g.It("Verify Manual mode with OCPVersion and Upgradeable (Happy case) [apigroup:machineconfiguration.openshift.io]", func() { |
| 70 | + // Set manual mode with a boot image version that is within skew limits |
| 71 | + o.Expect(machineConfiguration.SetManualSkew(OCPVersionMode, constants.OCPVersionBootImageSkewLimit)).To(o.Succeed()) |
| 72 | + |
| 73 | + // Wait for the controller to reflect Manual mode in skew enforcement status |
| 74 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementManualMode) |
| 75 | + |
| 76 | + // Check machine-config CO upgradeable status, should be set to true |
| 77 | + o.Eventually(mcoCO, "1m", "10s").Should(BeUpgradeable(), "co/machine-config should be upgradeable when manual skew version is within limits") |
| 78 | + }) |
| 79 | + |
| 80 | + g.It("Verify Manual mode with OCPVersion and Upgradeable (Sad case) [apigroup:machineconfiguration.openshift.io]", func() { |
| 81 | + // Set manual mode with a boot image version that is NOT within skew limits |
| 82 | + o.Expect(machineConfiguration.SetManualSkew(OCPVersionMode, ocpVersionExceedsSkew)).To(o.Succeed()) |
| 83 | + |
| 84 | + // Wait for the controller to reflect Manual mode in skew enforcement status |
| 85 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementManualMode) |
| 86 | + |
| 87 | + // Check machine-config CO upgradeable status, should be set to false |
| 88 | + o.Eventually(mcoCO, "1m", "10s").ShouldNot(BeUpgradeable(), "co/machine-config should not be upgradeable when manual skew version exceeds limits") |
| 89 | + }) |
| 90 | + |
| 91 | + g.It("Verify Automatic mode and Upgradeable (Happy Case) [apigroup:machineconfiguration.openshift.io]", func() { |
| 92 | + // only applicable on GCP, AWS clusters |
| 93 | + skipTestIfSupportedPlatformNotMatched(oc, GCPPlatform, AWSPlatform) |
| 94 | + |
| 95 | + // No opinion on skew enforcement for these platforms will result in Automatic mode |
| 96 | + o.Expect(machineConfiguration.RemoveSkew()).To(o.Succeed()) |
| 97 | + |
| 98 | + // Wait for the controller to reflect Automatic mode in skew enforcement status |
| 99 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementAutomaticMode) |
| 100 | + |
| 101 | + // Pick a random machineset to test |
| 102 | + machineSetUnderTest := NewMachineSetList(oc.AsAdmin(), MachineAPINamespace).GetAllOrFail()[0] |
| 103 | + logger.Infof("MachineSet under test: %s", machineSetUnderTest.name) |
| 104 | + |
| 105 | + // Save and restore full spec to ensure cleanup regardless of what we modify |
| 106 | + originalMachineSetSpec := machineSetUnderTest.GetSpecOrFail() |
| 107 | + defer func() { |
| 108 | + o.Expect(machineSetUnderTest.SetSpec(originalMachineSetSpec)).To(o.Succeed()) |
| 109 | + }() |
| 110 | + |
| 111 | + // Patch the boot image to an older version to trigger an update loop |
| 112 | + backdatedBootImage := getBackdatedBootImage(oc) |
| 113 | + o.Expect(machineSetUnderTest.SetCoreOsBootImage(backdatedBootImage)).To(o.Succeed()) |
| 114 | + logger.Infof("Set backdated boot image '%s' in MachineSet %s to trigger update loop", backdatedBootImage, machineSetUnderTest.name) |
| 115 | + |
| 116 | + // Verify that the boot image controller has finished processing |
| 117 | + machineConfiguration.WaitForBootImageControllerComplete() |
| 118 | + |
| 119 | + // Verify that the boot image controller is not degraded |
| 120 | + machineConfiguration.WaitForBootImageControllerDegradedState(false) |
| 121 | + |
| 122 | + // Check machine-config CO upgradeable status, should be set to True |
| 123 | + o.Eventually(mcoCO, "1m", "10s").Should(BeUpgradeable(), "co/machine-config should be upgradeable with restored machineset") |
| 124 | + }) |
| 125 | + |
| 126 | + g.It("Verify Automatic mode and Upgradeable (Sad Case) [apigroup:machineconfiguration.openshift.io]", func(_ context.Context) { |
| 127 | + // only applicable on GCP, AWS clusters |
| 128 | + skipTestIfSupportedPlatformNotMatched(oc, GCPPlatform, AWSPlatform) |
| 129 | + |
| 130 | + // No opinion on skew enforcement for these platforms will result in Automatic mode |
| 131 | + o.Expect(machineConfiguration.RemoveSkew()).To(o.Succeed()) |
| 132 | + |
| 133 | + // Wait for the controller to reflect Automatic mode in skew enforcement status |
| 134 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementAutomaticMode) |
| 135 | + |
| 136 | + // Pick a random machineset to test |
| 137 | + machineSetUnderTest := NewMachineSetList(oc.AsAdmin(), MachineAPINamespace).GetAllOrFail()[0] |
| 138 | + logger.Infof("MachineSet under test: %s", machineSetUnderTest.name) |
| 139 | + |
| 140 | + // Save and restore full spec to ensure cleanup regardless of what we modify |
| 141 | + originalMachineSetSpec := machineSetUnderTest.GetSpecOrFail() |
| 142 | + defer func() { |
| 143 | + o.Expect(machineSetUnderTest.SetSpec(originalMachineSetSpec)).To(o.Succeed()) |
| 144 | + }() |
| 145 | + |
| 146 | + // Set a non-existent user data secret in the machineset's providerSpec; this will cause a boot image controller degrade |
| 147 | + nonExistentSecret := "non-existent-user-data" |
| 148 | + o.Expect(machineSetUnderTest.SetUserDataSecret(nonExistentSecret)).To(o.Succeed()) |
| 149 | + logger.Infof("Set non-existent user data secret '%s' in MachineSet %s", nonExistentSecret, machineSetUnderTest.name) |
| 150 | + |
| 151 | + // Patch the boot image to an older version to trigger an update loop |
| 152 | + backdatedBootImage := getBackdatedBootImage(oc) |
| 153 | + o.Expect(machineSetUnderTest.SetCoreOsBootImage(backdatedBootImage)).To(o.Succeed()) |
| 154 | + logger.Infof("Set backdated boot image '%s' in MachineSet %s to trigger update loop", backdatedBootImage, machineSetUnderTest.name) |
| 155 | + |
| 156 | + // Verify that the boot image controller has finished processing |
| 157 | + machineConfiguration.WaitForBootImageControllerComplete() |
| 158 | + |
| 159 | + // Verify that the boot image controller is degraded |
| 160 | + machineConfiguration.WaitForBootImageControllerDegradedState(true) |
| 161 | + |
| 162 | + // Check machine-config CO upgradeable status, should be set to false due to the degrade |
| 163 | + o.Eventually(mcoCO, "1m", "10s").ShouldNot(BeUpgradeable(), "co/machine-config should not be upgradeable with broken machineset and update loop") |
| 164 | + |
| 165 | + // Restore machineset to original spec |
| 166 | + o.Expect(machineSetUnderTest.SetSpec(originalMachineSetSpec)).To(o.Succeed()) |
| 167 | + |
| 168 | + // Verify that the boot image controller has finished processing |
| 169 | + machineConfiguration.WaitForBootImageControllerComplete() |
| 170 | + |
| 171 | + // Verify that the boot image controller is not degraded |
| 172 | + machineConfiguration.WaitForBootImageControllerDegradedState(false) |
| 173 | + |
| 174 | + // Check machine-config CO upgradeable status, should be set back to true |
| 175 | + o.Eventually(mcoCO, "1m", "10s").Should(BeUpgradeable(), "co/machine-config should be upgradeable with restored machineset") |
| 176 | + }) |
| 177 | + |
| 178 | + g.It("Verify None mode [apigroup:machineconfiguration.openshift.io]", func() { |
| 179 | + // Set None mode, effectively disabling skew enforcement |
| 180 | + o.Expect(machineConfiguration.SetNoneSkew()).To(o.Succeed()) |
| 181 | + |
| 182 | + // Wait for the controller to reflect None mode in skew enforcement status |
| 183 | + machineConfiguration.WaitForBootImageSkewEnforcementStatusMode(SkewEnforcementNoneMode) |
| 184 | + |
| 185 | + // Check machine-config CO upgradeable status, should be set to true |
| 186 | + o.Eventually(mcoCO, "1m", "10s").Should(BeUpgradeable(), "co/machine-config should be upgradeable when skew enforcement is disabled (None mode)") |
| 187 | + }) |
| 188 | +}) |
0 commit comments