@@ -68,6 +68,57 @@ func TestClusterDefaultNamespaces(t *testing.T) {
68
68
g .Expect (c .Spec .ControlPlaneRef .Namespace ).To (Equal (c .Namespace ))
69
69
}
70
70
71
+ func TestClusterTopologyDefaultNamespaces (t * testing.T ) {
72
+ // NOTE: ClusterTopology feature flag is disabled by default, thus preventing to set Cluster.Topologies.
73
+ // Enabling the feature flag temporarily for this test.
74
+ defer utilfeature .SetFeatureGateDuringTest (t , feature .Gates , feature .ClusterTopology , true )()
75
+
76
+ g := NewWithT (t )
77
+
78
+ c := builder .Cluster ("fooboo" , "cluster1" ).
79
+ WithTopology (builder .ClusterTopology ().
80
+ WithClass ("foo" ).
81
+ WithVersion ("v1.19.1" ).
82
+ WithControlPlaneMachineHealthCheck (& clusterv1.MachineHealthCheckTopology {
83
+ MachineHealthCheckClass : clusterv1.MachineHealthCheckClass {
84
+ RemediationTemplate : & corev1.ObjectReference {},
85
+ },
86
+ }).
87
+ WithMachineDeployment (
88
+ builder .MachineDeploymentTopology ("md1" ).
89
+ WithClass ("aa" ).
90
+ WithMachineHealthCheck (& clusterv1.MachineHealthCheckTopology {
91
+ MachineHealthCheckClass : clusterv1.MachineHealthCheckClass {
92
+ RemediationTemplate : & corev1.ObjectReference {},
93
+ },
94
+ }).
95
+ Build ()).
96
+ Build ()).
97
+ Build ()
98
+
99
+ clusterClass := builder .ClusterClass ("fooboo" , "foo" ).
100
+ WithControlPlaneInfrastructureMachineTemplate (& unstructured.Unstructured {}).
101
+ WithWorkerMachineDeploymentClasses (* builder .MachineDeploymentClass ("aa" ).Build ()).
102
+ Build ()
103
+ conditions .MarkTrue (clusterClass , clusterv1 .ClusterClassVariablesReconciledCondition )
104
+ // Sets up the fakeClient for the test case. This is required because the test uses a Managed Topology.
105
+ fakeClient := fake .NewClientBuilder ().
106
+ WithObjects (clusterClass ).
107
+ WithScheme (fakeScheme ).
108
+ Build ()
109
+
110
+ // Create the webhook and add the fakeClient as its client.
111
+ webhook := & Cluster {Client : fakeClient }
112
+ t .Run ("for Cluster" , util .CustomDefaultValidateTest (ctx , c , webhook ))
113
+
114
+ g .Expect (webhook .Default (ctx , c )).To (Succeed ())
115
+
116
+ g .Expect (c .Spec .Topology .ControlPlane .MachineHealthCheck .MachineHealthCheckClass .RemediationTemplate .Namespace ).To (Equal (c .Namespace ))
117
+ for i := range c .Spec .Topology .Workers .MachineDeployments {
118
+ g .Expect (c .Spec .Topology .Workers .MachineDeployments [i ].MachineHealthCheck .MachineHealthCheckClass .RemediationTemplate .Namespace ).To (Equal (c .Namespace ))
119
+ }
120
+ }
121
+
71
122
// TestClusterDefaultAndValidateVariables cases where cluster.spec.topology.class is altered.
72
123
func TestClusterDefaultAndValidateVariables (t * testing.T ) {
73
124
defer utilfeature .SetFeatureGateDuringTest (t , feature .Gates , feature .ClusterTopology , true )()
0 commit comments