@@ -35,6 +35,7 @@ import (
3535 "k8s.io/klog/v2"
3636 "k8s.io/utils/ptr"
3737 clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
38+ "sigs.k8s.io/cluster-api/util"
3839 "sigs.k8s.io/controller-runtime/pkg/cache"
3940 "sigs.k8s.io/controller-runtime/pkg/client"
4041 "sigs.k8s.io/controller-runtime/pkg/config"
@@ -165,11 +166,12 @@ func deployCluster(namespace string, k8sClient client.Client) (client.ObjectKey,
165166func deployCAPIMachine (namespace string , cluster * clusterv1.Cluster , k8sClient client.Client ) (client.ObjectKey , * clusterv1.Machine ) {
166167 // A finalizer is added to prevent it from being deleted until its
167168 // dependents are removed.
169+ name := "test-" + util .RandomString (5 )
168170 machine := & clusterv1.Machine {
169171 ObjectMeta : metav1.ObjectMeta {
170- GenerateName : "test-" ,
171- Namespace : namespace ,
172- Finalizers : []string {"test" },
172+ Name : name ,
173+ Namespace : namespace ,
174+ Finalizers : []string {"test" },
173175 Labels : map [string ]string {
174176 clusterv1 .ClusterNameLabel : cluster .Name ,
175177 clusterv1 .MachineControlPlaneLabel : "" ,
@@ -185,6 +187,11 @@ func deployCAPIMachine(namespace string, cluster *clusterv1.Cluster, k8sClient c
185187 },
186188 Spec : clusterv1.MachineSpec {
187189 ClusterName : cluster .Name ,
190+ InfrastructureRef : clusterv1.ContractVersionedObjectReference {
191+ Kind : "VSphereMachine" ,
192+ Name : name , // We know that the infra machine is going to be called like the machine.
193+ APIGroup : vmwarev1 .GroupVersion .Group ,
194+ },
188195 },
189196 }
190197 Expect (k8sClient .Create (ctx , machine )).To (Succeed ())
@@ -213,10 +220,10 @@ func deployInfraMachine(namespace string, machine *clusterv1.Machine, finalizers
213220// Updates the InfrastructureRef of a CAPI Cluster to a VSphereCluster. Function
214221// does not block on update success.
215222func updateClusterInfraRef (cluster * clusterv1.Cluster , infraCluster client.Object , k8sClient client.Client ) {
216- cluster .Spec .InfrastructureRef = & corev1. ObjectReference {
217- APIVersion : infraCluster . GetObjectKind (). GroupVersionKind (). GroupVersion (). String () ,
218- Kind : infraCluster . GetObjectKind (). GroupVersionKind (). Kind ,
219- Name : infraCluster .GetName (),
223+ cluster .Spec .InfrastructureRef = & clusterv1. ContractVersionedObjectReference {
224+ APIGroup : vmwarev1 . GroupVersion . Group ,
225+ Kind : "VSphereCluster" ,
226+ Name : infraCluster .GetName (),
220227 }
221228 Expect (k8sClient .Update (ctx , cluster )).To (Succeed ())
222229}
@@ -551,14 +558,20 @@ var _ = Describe("Reconciliation tests", func() {
551558 By ("Create the CAPI Machine and wait for it to exist" )
552559 // A finalizer is added to prevent it from being deleted until its
553560 // dependents are removed.
561+ name := "test-" + util .RandomString (5 )
554562 machine := & clusterv1.Machine {
555563 ObjectMeta : metav1.ObjectMeta {
556- GenerateName : "test-" ,
557- Namespace : ns .Name ,
558- Finalizers : []string {"test" },
564+ Name : name ,
565+ Namespace : ns .Name ,
566+ Finalizers : []string {"test" },
559567 },
560568 Spec : clusterv1.MachineSpec {
561569 ClusterName : "crud" ,
570+ InfrastructureRef : clusterv1.ContractVersionedObjectReference {
571+ Kind : "VSphereMachine" ,
572+ Name : name , // We know that the infra machine is going to be called like the machine.
573+ APIGroup : vmwarev1 .GroupVersion .Group ,
574+ },
562575 },
563576 }
564577 Expect (k8sClient .Create (ctx , machine )).To (Succeed ())
0 commit comments