@@ -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/klog/v2"
30
31
"k8s.io/utils/pointer"
31
32
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -82,6 +83,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
82
83
It ("Should pivot the bootstrap cluster to a self-hosted cluster" , func () {
83
84
By ("Creating a workload cluster" )
84
85
86
+ workloadClusterName := fmt .Sprintf ("%s-%s" , specName , util .RandomString (6 ))
85
87
clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
86
88
ClusterProxy : input .BootstrapClusterProxy ,
87
89
ConfigCluster : clusterctl.ConfigClusterInput {
@@ -91,7 +93,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
91
93
InfrastructureProvider : clusterctl .DefaultInfrastructureProvider ,
92
94
Flavor : input .Flavor ,
93
95
Namespace : namespace .Name ,
94
- ClusterName : fmt . Sprintf ( "%s-%s" , specName , util . RandomString ( 6 )) ,
96
+ ClusterName : workloadClusterName ,
95
97
KubernetesVersion : input .E2EConfig .GetVariable (KubernetesVersion ),
96
98
ControlPlaneMachineCount : pointer .Int64Ptr (1 ),
97
99
WorkerMachineCount : pointer .Int64Ptr (1 ),
@@ -164,6 +166,18 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
164
166
return selfHostedClusterProxy .GetClient ().Get (ctx , client.ObjectKey {Name : "kube-system" }, kubeSystem )
165
167
}, "5s" , "100ms" ).Should (BeNil (), "Failed to assert self-hosted API server stability" )
166
168
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
+
167
181
By ("Moving the cluster to self hosted" )
168
182
clusterctl .Move (ctx , clusterctl.MoveInput {
169
183
LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , "bootstrap" ),
@@ -187,6 +201,20 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
187
201
})
188
202
Expect (controlPlane ).ToNot (BeNil ())
189
203
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
+
190
218
By ("PASSED!" )
191
219
})
192
220
0 commit comments