@@ -2489,6 +2489,102 @@ func TestClusterClassValidationWithClusterAwareChecks(t *testing.T) {
24892489 Build (),
24902490 expectErr : false ,
24912491 },
2492+ {
2493+ name : "pass if ClusterClass does not contain any kubernetes version" ,
2494+ clusters : []client.Object {
2495+ builder .Cluster (metav1 .NamespaceDefault , "cluster1" ).
2496+ WithLabels (map [string ]string {clusterv1 .ClusterTopologyOwnedLabel : "" }).
2497+ WithTopology (
2498+ builder .ClusterTopology ().
2499+ WithClass ("class1" ).
2500+ WithVersion ("v1.33.0" ).
2501+ Build ()).
2502+ Build (),
2503+ },
2504+ oldClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2505+ WithInfrastructureClusterTemplate (
2506+ builder .InfrastructureClusterTemplate (metav1 .NamespaceDefault , "inf" ).Build ()).
2507+ WithControlPlaneTemplate (
2508+ builder .ControlPlaneTemplate (metav1 .NamespaceDefault , "cp1" ).Build ()).
2509+ Build (),
2510+ newClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2511+ WithInfrastructureClusterTemplate (
2512+ builder .InfrastructureClusterTemplate (metav1 .NamespaceDefault , "inf" ).Build ()).
2513+ WithControlPlaneTemplate (
2514+ builder .ControlPlaneTemplate (metav1 .NamespaceDefault , "cp1" ).Build ()).
2515+ Build (),
2516+ expectErr : false ,
2517+ },
2518+ {
2519+ name : "pass if ClusterClass contains cluster's kubernetes version" ,
2520+ clusters : []client.Object {
2521+ builder .Cluster (metav1 .NamespaceDefault , "cluster1" ).
2522+ WithLabels (map [string ]string {clusterv1 .ClusterTopologyOwnedLabel : "" }).
2523+ WithTopology (
2524+ builder .ClusterTopology ().
2525+ WithClass ("class1" ).
2526+ WithVersion ("v1.33.0" ).
2527+ Build ()).
2528+ Build (),
2529+ builder .Cluster (metav1 .NamespaceDefault , "cluster2" ).
2530+ WithLabels (map [string ]string {clusterv1 .ClusterTopologyOwnedLabel : "" }).
2531+ WithTopology (
2532+ builder .ClusterTopology ().
2533+ WithClass ("class1" ).
2534+ WithVersion ("v1.34.0" ).
2535+ Build ()).
2536+ Build (),
2537+ },
2538+ oldClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2539+ WithInfrastructureClusterTemplate (
2540+ builder .InfrastructureClusterTemplate (metav1 .NamespaceDefault , "inf" ).Build ()).
2541+ WithControlPlaneTemplate (
2542+ builder .ControlPlaneTemplate (metav1 .NamespaceDefault , "cp1" ).Build ()).
2543+ Build (),
2544+ newClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2545+ WithInfrastructureClusterTemplate (
2546+ builder .InfrastructureClusterTemplate (metav1 .NamespaceDefault , "inf" ).Build ()).
2547+ WithControlPlaneTemplate (
2548+ builder .ControlPlaneTemplate (metav1 .NamespaceDefault , "cp1" ).Build ()).
2549+ WithVersions ("v1.32.0" , "v1.33.0" , "v1.34.0" ).
2550+ Build (),
2551+ expectErr : false ,
2552+ },
2553+ {
2554+ name : "fail if ClusterClass does not contains all of cluster's kubernetes version" ,
2555+ clusters : []client.Object {
2556+ builder .Cluster (metav1 .NamespaceDefault , "cluster1" ).
2557+ WithLabels (map [string ]string {clusterv1 .ClusterTopologyOwnedLabel : "" }).
2558+ WithTopology (
2559+ builder .ClusterTopology ().
2560+ WithClass ("class1" ).
2561+ WithVersion ("v1.33.0" ).
2562+ Build ()).
2563+ Build (),
2564+ builder .Cluster (metav1 .NamespaceDefault , "cluster2" ).
2565+ WithLabels (map [string ]string {clusterv1 .ClusterTopologyOwnedLabel : "" }).
2566+ WithTopology (
2567+ builder .ClusterTopology ().
2568+ WithClass ("class1" ).
2569+ WithVersion ("v1.34.0" ).
2570+ Build ()).
2571+ Build (),
2572+ },
2573+ oldClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2574+ WithInfrastructureClusterTemplate (
2575+ builder .InfrastructureClusterTemplate (metav1 .NamespaceDefault , "inf" ).Build ()).
2576+ WithControlPlaneTemplate (
2577+ builder .ControlPlaneTemplate (metav1 .NamespaceDefault , "cp1" ).Build ()).
2578+ Build (),
2579+ newClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2580+ WithInfrastructureClusterTemplate (
2581+ builder .InfrastructureClusterTemplate (metav1 .NamespaceDefault , "inf" ).Build ()).
2582+ WithControlPlaneTemplate (
2583+ builder .ControlPlaneTemplate (metav1 .NamespaceDefault , "cp1" ).Build ()).
2584+ WithVersions ("v1.32.0" , "v1.33.0" ).
2585+ Build (),
2586+ expectErr : true ,
2587+ },
24922588 }
24932589
24942590 for _ , tt := range tests {
0 commit comments