@@ -10,8 +10,8 @@ import (
1010 g "github.com/onsi/ginkgo/v2"
1111 o "github.com/onsi/gomega"
1212 v1 "github.com/openshift/api/config/v1"
13+ mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
1314 mcv1client "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
14- kapierrs "k8s.io/apimachinery/pkg/api/errors"
1515 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616 e2e "k8s.io/kubernetes/test/e2e/framework"
1717 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
@@ -173,97 +173,129 @@ var _ = g.Describe("[sig-ci] [Early] prow job name", func() {
173173 })
174174
175175 g .It ("should match os version" , func () {
176- // TODO: @pablintino https://redhat.atlassian.net/browse/MCO-2371
177- e2eskipper .Skipf ("Temporarily disabled until RHEL-10 switchover, see MCO-2371" )
178176 if jobName == "" {
179177 e2eskipper .Skipf ("JOB_NAME env var not set, skipping" )
180178 }
181-
182- jobIsRHCOS10 := strings .Contains (jobName , "rhcos10" )
183- jobIsMixedRHCOSVer := strings .Contains (jobName , "rhcos9-10" )
179+ nodeOSJobType := getNodeOSJobType (jobName )
184180
185181 isMicroShift , err := exutil .IsMicroShiftCluster (oc .AdminKubeClient ())
186182 o .Expect (err ).NotTo (o .HaveOccurred ())
187- if isMicroShift {
188- if jobIsRHCOS10 {
189- // TODO(muller): Assume we do not have RHCOS10 microshift jobs now. If someone adds a RHCOS10 job, this failure
190- // should force them to figure out how to detect RHCOS10 in microshift and update this test.
191- e2e .Failf ("TODO: job name %q indicates RHCOS10 which cannot be checked for MicroShift clusters now" , jobName )
192- return
193- }
194-
195- e2eskipper .Skip ("Cannot check RHCOS for MicroShift clusters" )
196- }
197-
198183 isHyperShift , err := exutil .IsHypershift (context .TODO (), oc .AdminConfigClient ())
199184 o .Expect (err ).NotTo (o .HaveOccurred ())
200- if isHyperShift {
201- if jobIsRHCOS10 {
202- // TODO(muller): Assume we do not have RHCOS10 hypershift jobs now. If someone adds a RHCOS10 job, this failure
203- // should force them to figure out how to detect RHCOS10 in hypershift and update this test.
204- e2e .Failf ("TODO: job name %q indicates RHCOS10 which cannot be checked for HyperShift clusters now" , jobName )
205- return
206- }
207185
208- e2eskipper .Skip ("Cannot check RHCOS for HyperShift clusters" )
186+ if isMicroShift {
187+ validateMicroshiftNodeOS (nodeOSJobType , jobName )
188+ } else if isHyperShift {
189+ validateHypershiftNodeOS (nodeOSJobType , jobName )
190+ } else {
191+ validateStandaloneNodeOS (oc , nodeOSJobType )
209192 }
193+ })
194+ })
210195
211- clusterIsRHCOS10 := isRHCOS10 (oc .MachineConfigurationClient ())
196+ func fetchMCPStreams (machineConfigClient mcv1client.Interface ) map [string ]string {
197+ mcps , err := machineConfigClient .MachineconfigurationV1 ().MachineConfigPools ().List (context .TODO (), metav1.ListOptions {})
198+ o .Expect (err ).NotTo (o .HaveOccurred (), "Error fetching MCPs" )
212199
213- // Mixed RHCOS version clusters (e.g. rhcos9-10) have nodes running both
214- // RHCOS 9 and RHCOS 10. Validate that we see both versions across nodes.
215- if jobIsMixedRHCOSVer {
216- hasRHCOS9 , hasRHCOS10 := hasMixedRHCOSNodes (oc )
217- if ! hasRHCOS9 || ! hasRHCOS10 {
218- e2e .Failf ("job name %q is a mixed RHCOS version cluster but nodes do not have both versions (hasRHCOS9=%v, hasRHCOS10=%v)" , jobName , hasRHCOS9 , hasRHCOS10 )
219- }
220- e2e .Logf ("job name %q is a mixed RHCOS version cluster with both RHCOS 9 and RHCOS 10 nodes" , jobName )
221- return
222- }
200+ // Fetch the OSImageStream CR to get the cluster default
201+ osImageStream , err := machineConfigClient .MachineconfigurationV1 ().OSImageStreams ().Get (context .TODO (), "cluster" , metav1.GetOptions {})
202+ o .Expect (err ).NotTo (o .HaveOccurred (), "Error getting OSImageStream singleton" )
223203
224- if clusterIsRHCOS10 && ! jobIsRHCOS10 {
225- e2e .Failf ("cluster runs RHCOS10 so job name %q must contain 'rhcos10'" , jobName )
204+ var workerMCP * mcfgv1.MachineConfigPool
205+ for _ , mcp := range mcps .Items {
206+ if mcp .Name == "worker" {
207+ workerMCP = & mcp
208+ break
226209 }
227- if ! clusterIsRHCOS10 && jobIsRHCOS10 {
228- e2e .Failf ("cluster does not run RHCOS10 so job name %q must not contain 'rhcos10')" , jobName )
210+ }
211+ o .Expect (workerMCP ).NotTo (o .BeNil (), "Cluster worker MCP does not exist" )
212+
213+ mcpsStreams := make (map [string ]string )
214+ for _ , mcp := range mcps .Items {
215+ stream := mcp .Spec .OSImageStream .Name
216+ if stream == "" {
217+ // It can be a custom MCP using the stream of the parent
218+ if mcp .Name == "master" || mcp .Name == "worker" || mcp .Name == "arbiter" {
219+ // Not a custom pool: It's using the cluster-wide stream
220+ stream = osImageStream .Status .DefaultStream
221+ } else if workerMCP .Spec .OSImageStream .Name != "" {
222+ stream = workerMCP .Spec .OSImageStream .Name
223+ } else {
224+ stream = osImageStream .Status .DefaultStream
225+ }
229226 }
230- })
231- })
227+ mcpsStreams [ mcp . Name ] = stream
228+ }
232229
233- // isRHCOS10 checks whether the cluster is running RHEL 10 by examining the worker
234- // MCP's OSImageStream setting, falling back to the cluster-wide default stream
235- // from the OSImageStream singleton if the MCP does not specify one.
236- func isRHCOS10 (machineConfigClient mcv1client.Interface ) bool {
237- mcp , err := machineConfigClient .MachineconfigurationV1 ().MachineConfigPools ().Get (context .TODO (), "worker" , metav1.GetOptions {})
238- o .Expect (err ).NotTo (o .HaveOccurred (), "Error getting worker MCP" )
230+ return mcpsStreams
231+ }
239232
240- if mcp .Spec .OSImageStream .Name != "" {
241- return mcp .Spec .OSImageStream .Name == "rhel-10"
233+ func validateMicroshiftNodeOS (nodeOSJobType NodeOSJobType , jobName string ) {
234+ if nodeOSJobType != RHEL9 {
235+ // TODO(muller): Assume we do not have RHCOS10 microshift jobs now. If someone adds a RHCOS10 job, this failure
236+ // should force them to figure out how to detect RHCOS10 in microshift and update this test.
237+ e2e .Failf ("TODO: job name %q indicates RHCOS10 which cannot be checked for MicroShift clusters now" , jobName )
238+ return
242239 }
243240
244- osImageStream , err := machineConfigClient .MachineconfigurationV1 ().OSImageStreams ().Get (context .TODO (), "cluster" , metav1.GetOptions {})
245- if kapierrs .IsNotFound (err ) {
246- return false
241+ e2eskipper .Skip ("Cannot check RHCOS for MicroShift clusters" )
242+
243+ }
244+
245+ func validateHypershiftNodeOS (nodeOSJobType NodeOSJobType , jobName string ) {
246+ if nodeOSJobType != RHEL9 {
247+ // TODO(muller): Assume we do not have RHCOS10 hypershift jobs now. If someone adds a RHCOS10 job, this failure
248+ // should force them to figure out how to detect RHCOS10 in hypershift and update this test.
249+ e2e .Failf ("TODO: job name %q indicates RHCOS10 which cannot be checked for HyperShift clusters now" , jobName )
250+ return
247251 }
248- o .Expect (err ).NotTo (o .HaveOccurred (), "Error getting OSImageStream singleton" )
249252
250- return osImageStream . Status . DefaultStream == "rhel-10"
253+ e2eskipper . Skip ( "Cannot check RHCOS for HyperShift clusters" )
251254}
252255
253- // hasMixedRHCOSNodes scans all nodes and returns whether both RHCOS 9 and
254- // RHCOS 10 nodes are present, based on node OSImage.
255- func hasMixedRHCOSNodes (oc * exutil.CLI ) (hasRHCOS9 , hasRHCOS10 bool ) {
256- nodes , err := oc .AdminKubeClient ().CoreV1 ().Nodes ().List (context .TODO (), metav1.ListOptions {})
257- o .Expect (err ).NotTo (o .HaveOccurred (), "Error listing nodes" )
258-
259- for _ , node := range nodes .Items {
260- osImage := node .Status .NodeInfo .OSImage
261- e2e .Logf ("node %s has OSImage %q" , node .Name , osImage )
262- if strings .Contains (osImage , "CoreOS 10." ) {
263- hasRHCOS10 = true
264- } else if strings .Contains (osImage , "CoreOS 9." ) {
265- hasRHCOS9 = true
256+ func validateStandaloneNodeOS (oc * exutil.CLI , nodeOSJobType NodeOSJobType ) {
257+ mcpsStreams := fetchMCPStreams (oc .MachineConfigurationClient ())
258+
259+ if nodeOSJobType == RHEL9 {
260+ for mcp , stream := range mcpsStreams {
261+ o .Expect (stream ).To (o .Equal ("rhel-9" ), "MCP %s uses %s as stream but was expecting rhel-9" , mcp , stream )
262+ }
263+ } else if nodeOSJobType == RHEL10 {
264+ for mcp , stream := range mcpsStreams {
265+ o .Expect (stream ).To (o .Equal ("rhel-10" ), "MCP %s uses %s as stream but was expecting rhel-10" , mcp , stream )
266266 }
267+ } else if nodeOSJobType == RHELMixed910 {
268+ var hasRHCOS9 bool
269+ var hasRHCOS10 bool
270+ for _ , stream := range mcpsStreams {
271+ if stream == "rhel-9" {
272+ hasRHCOS9 = true
273+ } else if stream == "rhel-10" {
274+ hasRHCOS10 = true
275+ }
276+ }
277+ o .Expect (hasRHCOS9 ).To (o .BeTrue (), "The cluster is a RHEL 9 and RHEL 10 mixed cluster but it doesn't use RHEL 9" )
278+ o .Expect (hasRHCOS10 ).To (o .BeTrue (), "The cluster is a RHEL 9 and RHEL 10 mixed cluster but it doesn't use RHEL 10" )
267279 }
268- return
280+ }
281+
282+ type NodeOSJobType int
283+
284+ const (
285+ RHEL10 NodeOSJobType = iota
286+ RHEL9
287+ RHELMixed910
288+ )
289+
290+ func getNodeOSJobType (jobName string ) NodeOSJobType {
291+ if strings .Contains (jobName , "rhcos9-10" ) {
292+ return RHELMixed910
293+ } else if strings .Contains (jobName , "rhcos10" ) {
294+ return RHEL10
295+ } else if strings .Contains (jobName , "rhcos9" ) {
296+ return RHEL9
297+ }
298+
299+ // If not explicit OS in the name assume RHEL 10
300+ return RHEL10
269301}
0 commit comments