@@ -26,6 +26,7 @@ import (
26
26
. "github.com/onsi/ginkgo"
27
27
. "github.com/onsi/gomega"
28
28
corev1 "k8s.io/api/core/v1"
29
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
29
30
"k8s.io/utils/pointer"
30
31
"sigs.k8s.io/controller-runtime/pkg/client"
31
32
@@ -81,6 +82,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
81
82
It ("Should pivot the bootstrap cluster to a self-hosted cluster" , func () {
82
83
By ("Creating a workload cluster" )
83
84
85
+ workloadClusterName := fmt .Sprintf ("%s-%s" , specName , util .RandomString (6 ))
84
86
clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
85
87
ClusterProxy : input .BootstrapClusterProxy ,
86
88
ConfigCluster : clusterctl.ConfigClusterInput {
@@ -90,7 +92,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
90
92
InfrastructureProvider : clusterctl .DefaultInfrastructureProvider ,
91
93
Flavor : input .Flavor ,
92
94
Namespace : namespace .Name ,
93
- ClusterName : fmt . Sprintf ( "%s-%s" , specName , util . RandomString ( 6 )) ,
95
+ ClusterName : workloadClusterName ,
94
96
KubernetesVersion : input .E2EConfig .GetVariable (KubernetesVersion ),
95
97
ControlPlaneMachineCount : pointer .Int64Ptr (1 ),
96
98
WorkerMachineCount : pointer .Int64Ptr (1 ),
@@ -163,6 +165,18 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
163
165
return selfHostedClusterProxy .GetClient ().Get (ctx , client.ObjectKey {Name : "kube-system" }, kubeSystem )
164
166
}, "5s" , "100ms" ).Should (BeNil (), "Failed to assert self-hosted API server stability" )
165
167
168
+ // Get the machines of the workloadCluster before it is moved to become self-hosted to make sure that the move did not trigger
169
+ // any unexpected rollouts.
170
+ preMoveMachineList := & unstructured.UnstructuredList {}
171
+ preMoveMachineList .SetGroupVersionKind (clusterv1 .GroupVersion .WithKind ("MachineList" ))
172
+ err := input .BootstrapClusterProxy .GetClient ().List (
173
+ ctx ,
174
+ preMoveMachineList ,
175
+ client .InNamespace (namespace .Name ),
176
+ client.MatchingLabels {clusterv1 .ClusterLabelName : workloadClusterName },
177
+ )
178
+ Expect (err ).NotTo (HaveOccurred (), "Failed to list machines before move" )
179
+
166
180
By ("Moving the cluster to self hosted" )
167
181
clusterctl .Move (ctx , clusterctl.MoveInput {
168
182
LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , "bootstrap" ),
@@ -186,6 +200,20 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
186
200
})
187
201
Expect (controlPlane ).ToNot (BeNil ())
188
202
203
+ // After the move check that there were no unexpected rollouts.
204
+ Consistently (func () bool {
205
+ postMoveMachineList := & unstructured.UnstructuredList {}
206
+ postMoveMachineList .SetGroupVersionKind (clusterv1 .GroupVersion .WithKind ("MachineList" ))
207
+ err = selfHostedClusterProxy .GetClient ().List (
208
+ ctx ,
209
+ postMoveMachineList ,
210
+ client .InNamespace (namespace .Name ),
211
+ client.MatchingLabels {clusterv1 .ClusterLabelName : workloadClusterName },
212
+ )
213
+ Expect (err ).NotTo (HaveOccurred (), "Failed to list machines after move" )
214
+ return matchUnstructuredLists (preMoveMachineList , postMoveMachineList )
215
+ }, "3m" , "30s" ).Should (BeTrue (), "Machines should not roll out after move to self-hosted cluster" )
216
+
189
217
By ("PASSED!" )
190
218
})
191
219
0 commit comments