Skip to content

Commit 7ded0ab

Browse files
committed
Adjust CAPV to CAPI bump
1 parent 342c5b0 commit 7ded0ab

21 files changed

+61
-59
lines changed

controllers/clustermodule_reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func toAffinityInput[T client.Object](c client.Client) handler.TypedMapFunc[T, c
214214
log = log.WithValues("Cluster", klog.KObj(cluster))
215215
ctx = ctrl.LoggerInto(ctx, log)
216216

217-
if cluster.Spec.InfrastructureRef == nil {
217+
if !cluster.Spec.InfrastructureRef.IsDefined() {
218218
log.V(4).Error(err, "Failed to get VSphereCluster: Cluster.spec.infrastructureRef not set")
219219
return nil
220220
}

controllers/vmware/test/controllers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func deployInfraMachine(namespace string, machine *clusterv1.Machine, finalizers
225225
// Updates the InfrastructureRef of a CAPI Cluster to a VSphereCluster. Function
226226
// does not block on update success.
227227
func updateClusterInfraRef(cluster *clusterv1.Cluster, infraCluster client.Object, k8sClient client.Client) {
228-
cluster.Spec.InfrastructureRef = &clusterv1.ContractVersionedObjectReference{
228+
cluster.Spec.InfrastructureRef = clusterv1.ContractVersionedObjectReference{
229229
APIGroup: vmwarev1.GroupVersion.Group,
230230
Kind: "VSphereCluster",
231231
Name: infraCluster.GetName(),

controllers/vspherecluster_reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (r *clusterReconciler) controlPlaneMachineToCluster(ctx context.Context, o
532532
return nil
533533
}
534534
log = log.WithValues("Cluster", klog.KObj(cluster))
535-
if cluster.Spec.InfrastructureRef != nil {
535+
if cluster.Spec.InfrastructureRef.IsDefined() {
536536
log = log.WithValues("VSphereCluster", klog.KRef(cluster.Namespace, cluster.Spec.InfrastructureRef.Name))
537537
}
538538
ctx = ctrl.LoggerInto(ctx, log)
@@ -547,7 +547,7 @@ func (r *clusterReconciler) controlPlaneMachineToCluster(ctx context.Context, o
547547
return nil
548548
}
549549

550-
if cluster.Spec.InfrastructureRef == nil {
550+
if !cluster.Spec.InfrastructureRef.IsDefined() {
551551
log.Error(nil, "Failed to get VSphereCluster: Cluster.spec.infrastructureRef is not yet set")
552552
return nil
553553
}

controllers/vspherecluster_reconciler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() {
104104
Namespace: "default",
105105
},
106106
Spec: clusterv1.ClusterSpec{
107-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
107+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
108108
APIGroup: infrav1.GroupVersion.Group,
109109
Kind: "VsphereCluster",
110110
Name: instance.Name,
@@ -173,7 +173,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() {
173173
Namespace: "default",
174174
},
175175
Spec: clusterv1.ClusterSpec{
176-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
176+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
177177
APIGroup: infrav1.GroupVersion.Group,
178178
Kind: "VsphereCluster",
179179
Name: "vsphere-test1",
@@ -257,7 +257,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() {
257257
Namespace: "default",
258258
},
259259
Spec: clusterv1.ClusterSpec{
260-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
260+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
261261
APIGroup: infrav1.GroupVersion.Group,
262262
Kind: "VsphereCluster",
263263
Name: "vsphere-test1",
@@ -365,7 +365,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() {
365365
Namespace: namespace.Name,
366366
},
367367
Spec: clusterv1.ClusterSpec{
368-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
368+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
369369
APIGroup: infrav1.GroupVersion.Group,
370370
Kind: "VSphereCluster",
371371
Name: "vsphere-test2",

controllers/vspheredeploymentzone_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func createMachine(machineName, clusterName, namespace string, isControlPlane bo
547547
Spec: clusterv1.MachineSpec{
548548
Version: "v1.22.0",
549549
Bootstrap: clusterv1.Bootstrap{
550-
ConfigRef: &clusterv1.ContractVersionedObjectReference{
550+
ConfigRef: clusterv1.ContractVersionedObjectReference{
551551
APIGroup: bootstrapv1.GroupVersion.Group,
552552
Kind: "KubeadmConfig",
553553
Name: machineName,

controllers/vspheremachine_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (r *machineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
230230

231231
if cluster != nil {
232232
log = log.WithValues("Cluster", klog.KObj(cluster))
233-
if cluster.Spec.InfrastructureRef != nil {
233+
if cluster.Spec.InfrastructureRef.IsDefined() {
234234
log = log.WithValues("VSphereCluster", klog.KRef(cluster.Namespace, cluster.Spec.InfrastructureRef.Name))
235235
}
236236
ctx = ctrl.LoggerInto(ctx, log)
@@ -315,7 +315,7 @@ func (r *machineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
315315
return reconcile.Result{}, nil
316316
}
317317

318-
if cluster.Spec.InfrastructureRef == nil {
318+
if !cluster.Spec.InfrastructureRef.IsDefined() {
319319
log.Info("Cluster.spec.infrastructureRef is not yet set")
320320
return reconcile.Result{}, nil
321321
}

controllers/vspheremachine_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var _ = Describe("VsphereMachineReconciler", func() {
6868
Namespace: testNs.Name,
6969
},
7070
Spec: clusterv1.ClusterSpec{
71-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
71+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
7272
APIGroup: "infrastructure.cluster.x-k8s.io",
7373
Kind: "VSphereCluster",
7474
Name: "vsphere-test1",
@@ -106,7 +106,7 @@ var _ = Describe("VsphereMachineReconciler", func() {
106106
Spec: clusterv1.MachineSpec{
107107
ClusterName: capiCluster.Name,
108108
Bootstrap: clusterv1.Bootstrap{
109-
ConfigRef: &clusterv1.ContractVersionedObjectReference{
109+
ConfigRef: clusterv1.ContractVersionedObjectReference{
110110
APIGroup: "bootstrap.cluster.x-k8s.io",
111111
Kind: "BootstrapConfig",
112112
Name: "does-no-ext", // Does not have to exist for these tests.
@@ -238,7 +238,7 @@ func Test_machineReconciler_Metadata(t *testing.T) {
238238
Namespace: ns.Name,
239239
},
240240
Spec: clusterv1.ClusterSpec{
241-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
241+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
242242
APIGroup: "infrastructure.cluster.x-k8s.io",
243243
Kind: "VSphereCluster",
244244
Name: "vsphere-test1",

controllers/vspherevm_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func (r vmReconciler) retrieveVcenterSession(ctx context.Context, vsphereVM *inf
670670
return session.GetOrCreate(ctx, params)
671671
}
672672

673-
if cluster.Spec.InfrastructureRef == nil {
673+
if !cluster.Spec.InfrastructureRef.IsDefined() {
674674
return nil, errors.Errorf("cannot retrieve vCenter session for cluster %s: Cluster.spec.infrastructureRef is nil", klog.KObj(cluster))
675675
}
676676
key := ctrlclient.ObjectKey{

controllers/vspherevm_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestReconcileNormal_WaitingForIPAddrAllocation(t *testing.T) {
8888
Namespace: "test",
8989
},
9090
Spec: clusterv1.ClusterSpec{
91-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
91+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
9292
Name: vsphereCluster.Name,
9393
},
9494
},
@@ -476,7 +476,7 @@ func TestRetrievingVCenterCredentialsFromCluster(t *testing.T) {
476476
Namespace: "test",
477477
},
478478
Spec: clusterv1.ClusterSpec{
479-
InfrastructureRef: &clusterv1.ContractVersionedObjectReference{
479+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
480480
Name: vsphereCluster.Name,
481481
},
482482
},
@@ -514,9 +514,9 @@ func TestRetrievingVCenterCredentialsFromCluster(t *testing.T) {
514514
Namespace: "test",
515515
},
516516

517-
// InfrastructureRef is nil so we should get an error.
517+
// InfrastructureRef is not set so we should get an error.
518518
Spec: clusterv1.ClusterSpec{
519-
InfrastructureRef: nil,
519+
// InfrastructureRef not set.
520520
},
521521
}
522522
initObjs := createMachineOwnerHierarchy(machine)

internal/clusterclass/variables.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package clusterclass
1919

2020
import (
21+
"k8s.io/utils/ptr"
2122
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2223
)
2324

@@ -27,7 +28,7 @@ func GetClusterClassVariables(govmomiMode bool) []clusterv1.ClusterClassVariable
2728
variables := []clusterv1.ClusterClassVariable{
2829
{
2930
Name: "sshKey",
30-
Required: false,
31+
Required: ptr.To(false),
3132
Schema: clusterv1.VariableSchema{
3233
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
3334
Description: "Public key to SSH onto the cluster nodes.",
@@ -37,7 +38,7 @@ func GetClusterClassVariables(govmomiMode bool) []clusterv1.ClusterClassVariable
3738
},
3839
{
3940
Name: "controlPlaneIpAddr",
40-
Required: true,
41+
Required: ptr.To(true),
4142
Schema: clusterv1.VariableSchema{
4243
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
4344
Type: "string",
@@ -47,7 +48,7 @@ func GetClusterClassVariables(govmomiMode bool) []clusterv1.ClusterClassVariable
4748
},
4849
{
4950
Name: "controlPlanePort",
50-
Required: true,
51+
Required: ptr.To(true),
5152
Schema: clusterv1.VariableSchema{
5253
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
5354
Type: "integer",
@@ -57,7 +58,7 @@ func GetClusterClassVariables(govmomiMode bool) []clusterv1.ClusterClassVariable
5758
},
5859
{
5960
Name: "kubeVipPodManifest",
60-
Required: true,
61+
Required: ptr.To(true),
6162
Schema: clusterv1.VariableSchema{
6263
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
6364
Type: "string",
@@ -71,7 +72,7 @@ func GetClusterClassVariables(govmomiMode bool) []clusterv1.ClusterClassVariable
7172
varForNoneSupervisorMode := []clusterv1.ClusterClassVariable{
7273
{
7374
Name: "infraServer",
74-
Required: true,
75+
Required: ptr.To(true),
7576
Schema: clusterv1.VariableSchema{
7677
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
7778
Type: "object",
@@ -84,7 +85,7 @@ func GetClusterClassVariables(govmomiMode bool) []clusterv1.ClusterClassVariable
8485
},
8586
{
8687
Name: "credsSecretName",
87-
Required: true,
88+
Required: ptr.To(true),
8889
Schema: clusterv1.VariableSchema{
8990
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
9091
Type: "string",

0 commit comments

Comments
 (0)