@@ -26,6 +26,7 @@ import (
2626 . "github.com/onsi/ginkgo"
2727 . "github.com/onsi/gomega"
2828 corev1 "k8s.io/api/core/v1"
29+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2930 "k8s.io/klog/v2"
3031 "k8s.io/utils/pointer"
3132 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -82,6 +83,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
8283 It ("Should pivot the bootstrap cluster to a self-hosted cluster" , func () {
8384 By ("Creating a workload cluster" )
8485
86+ workloadClusterName := fmt .Sprintf ("%s-%s" , specName , util .RandomString (6 ))
8587 clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
8688 ClusterProxy : input .BootstrapClusterProxy ,
8789 ConfigCluster : clusterctl.ConfigClusterInput {
@@ -91,7 +93,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
9193 InfrastructureProvider : clusterctl .DefaultInfrastructureProvider ,
9294 Flavor : input .Flavor ,
9395 Namespace : namespace .Name ,
94- ClusterName : fmt . Sprintf ( "%s-%s" , specName , util . RandomString ( 6 )) ,
96+ ClusterName : workloadClusterName ,
9597 KubernetesVersion : input .E2EConfig .GetVariable (KubernetesVersion ),
9698 ControlPlaneMachineCount : pointer .Int64Ptr (1 ),
9799 WorkerMachineCount : pointer .Int64Ptr (1 ),
@@ -164,6 +166,18 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
164166 return selfHostedClusterProxy .GetClient ().Get (ctx , client.ObjectKey {Name : "kube-system" }, kubeSystem )
165167 }, "5s" , "100ms" ).Should (BeNil (), "Failed to assert self-hosted API server stability" )
166168
169+ // Get the machines of the workloadCluster before it is moved to become self-hosted to make sure that the move did not trigger
170+ // any unexpected rollouts.
171+ preMoveMachineList := & unstructured.UnstructuredList {}
172+ preMoveMachineList .SetGroupVersionKind (clusterv1 .GroupVersion .WithKind ("MachineList" ))
173+ err := input .BootstrapClusterProxy .GetClient ().List (
174+ ctx ,
175+ preMoveMachineList ,
176+ client .InNamespace (namespace .Name ),
177+ client.MatchingLabels {clusterv1 .ClusterLabelName : workloadClusterName },
178+ )
179+ Expect (err ).NotTo (HaveOccurred (), "Failed to list machines before move" )
180+
167181 By ("Moving the cluster to self hosted" )
168182 clusterctl .Move (ctx , clusterctl.MoveInput {
169183 LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , "bootstrap" ),
@@ -187,6 +201,20 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
187201 })
188202 Expect (controlPlane ).ToNot (BeNil ())
189203
204+ // After the move check that there were no unexpected rollouts.
205+ Consistently (func () bool {
206+ postMoveMachineList := & unstructured.UnstructuredList {}
207+ postMoveMachineList .SetGroupVersionKind (clusterv1 .GroupVersion .WithKind ("MachineList" ))
208+ err = selfHostedClusterProxy .GetClient ().List (
209+ ctx ,
210+ postMoveMachineList ,
211+ client .InNamespace (namespace .Name ),
212+ client.MatchingLabels {clusterv1 .ClusterLabelName : workloadClusterName },
213+ )
214+ Expect (err ).NotTo (HaveOccurred (), "Failed to list machines after move" )
215+ return matchUnstructuredLists (preMoveMachineList , postMoveMachineList )
216+ }, "3m" , "30s" ).Should (BeTrue (), "Machines should not roll out after move to self-hosted cluster" )
217+
190218 By ("PASSED!" )
191219 })
192220
0 commit comments