diff --git a/controllers/serviceaccount_controller_intg_test.go b/controllers/serviceaccount_controller_intg_test.go index 591ac68db8..65c902ed53 100644 --- a/controllers/serviceaccount_controller_intg_test.go +++ b/controllers/serviceaccount_controller_intg_test.go @@ -29,7 +29,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" @@ -206,7 +206,7 @@ var _ = Describe("ProviderServiceAccount controller integration tests", func() { Kind: "ProviderServiceAccount", Name: pSvcAccount.GetName(), UID: types.UID(oldOwnerUID), - Controller: pointer.Bool(true), + Controller: ptr.To(true), }, }, }, @@ -227,7 +227,7 @@ var _ = Describe("ProviderServiceAccount controller integration tests", func() { APIVersion: "incorrect.api.com/v1beta1", Kind: "ProviderServiceAccount", Name: pSvcAccount.GetName(), - Controller: pointer.Bool(true), + Controller: ptr.To(true), UID: types.UID(oldOwnerUID), }, }, @@ -267,7 +267,7 @@ var _ = Describe("ProviderServiceAccount controller integration tests", func() { Kind: pSvcAccount.Kind, Name: pSvcAccount.GetName(), UID: pSvcAccount.UID, - Controller: pointer.Bool(true), + Controller: ptr.To(true), } By("Taking ownership of the role and reconciling the rules", func() { Eventually(func() error { diff --git a/controllers/vspherecluster_reconciler.go b/controllers/vspherecluster_reconciler.go index 9cf6331caa..3e0900f247 100644 --- a/controllers/vspherecluster_reconciler.go +++ b/controllers/vspherecluster_reconciler.go @@ -30,7 +30,7 @@ import ( "k8s.io/apimachinery/pkg/types" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/klog/v2" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" clusterutilv1 "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" @@ -331,14 +331,14 @@ func (r *clusterReconciler) reconcileDeploymentZones(ctx context.Context, cluste if zone.Status.Ready == nil { readyNotReported++ failureDomains[zone.Name] = clusterv1.FailureDomainSpec{ - ControlPlane: pointer.BoolDeref(zone.Spec.ControlPlane, true), + ControlPlane: ptr.Deref(zone.Spec.ControlPlane, true), } continue } if *zone.Status.Ready { failureDomains[zone.Name] = clusterv1.FailureDomainSpec{ - ControlPlane: pointer.BoolDeref(zone.Spec.ControlPlane, true), + ControlPlane: ptr.Deref(zone.Spec.ControlPlane, true), } continue } diff --git a/controllers/vspherecluster_reconciler_test.go b/controllers/vspherecluster_reconciler_test.go index 241a0c01aa..797c2a1fc1 100644 --- a/controllers/vspherecluster_reconciler_test.go +++ b/controllers/vspherecluster_reconciler_test.go @@ -28,7 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" @@ -331,7 +331,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: testEnv.Simulator.ServerURL().Host, FailureDomain: "fd-one", - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), }, Status: infrav1.VSphereDeploymentZoneStatus{}, } @@ -376,7 +376,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() { Eventually(func() error { ph, err := patch.NewHelper(zoneOne, testEnv) Expect(err).ShouldNot(HaveOccurred()) - zoneOne.Status.Ready = pointer.Bool(true) + zoneOne.Status.Ready = ptr.To(true) return ph.Patch(ctx, zoneOne, patch.WithStatusObservedGeneration{}) }, timeout).Should(BeNil()) @@ -395,7 +395,7 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() { Eventually(func() error { ph, err := patch.NewHelper(zoneOne, testEnv) Expect(err).ShouldNot(HaveOccurred()) - zoneOne.Status.Ready = pointer.Bool(true) + zoneOne.Status.Ready = ptr.To(true) return ph.Patch(ctx, zoneOne, patch.WithStatusObservedGeneration{}) }, timeout).Should(BeNil()) }) @@ -447,8 +447,8 @@ func TestClusterReconciler_ReconcileDeploymentZones(t *testing.T) { name: "with all deployment zone statuses as ready", reconciled: true, initObjs: []client.Object{ - deploymentZone(server, "zone-1", pointer.Bool(false), pointer.Bool(true)), - deploymentZone(server, "zone-2", pointer.Bool(true), pointer.Bool(true)), + deploymentZone(server, "zone-1", ptr.To(false), ptr.To(true)), + deploymentZone(server, "zone-2", ptr.To(true), ptr.To(true)), }, assert: func(vsphereCluster *infrav1.VSphereCluster) { g.Expect(conditions.Has(vsphereCluster, infrav1.FailureDomainsAvailableCondition)).To(BeFalse()) @@ -495,8 +495,8 @@ func TestClusterReconciler_ReconcileDeploymentZones(t *testing.T) { { name: "with deployment zone status not reported", initObjs: []client.Object{ - deploymentZone(server, "zone-1", pointer.Bool(false), nil), - deploymentZone(server, "zone-2", pointer.Bool(true), pointer.Bool(false)), + deploymentZone(server, "zone-1", ptr.To(false), nil), + deploymentZone(server, "zone-2", ptr.To(true), ptr.To(false)), }, assert: func(vsphereCluster *infrav1.VSphereCluster) { g.Expect(conditions.IsFalse(vsphereCluster, infrav1.FailureDomainsAvailableCondition)).To(BeTrue()) @@ -507,8 +507,8 @@ func TestClusterReconciler_ReconcileDeploymentZones(t *testing.T) { name: "with some deployment zones statuses as not ready", reconciled: true, initObjs: []client.Object{ - deploymentZone(server, "zone-1", pointer.Bool(false), pointer.Bool(false)), - deploymentZone(server, "zone-2", pointer.Bool(true), pointer.Bool(true)), + deploymentZone(server, "zone-1", ptr.To(false), ptr.To(false)), + deploymentZone(server, "zone-2", ptr.To(true), ptr.To(true)), }, assert: func(vsphereCluster *infrav1.VSphereCluster) { g.Expect(conditions.IsFalse(vsphereCluster, infrav1.FailureDomainsAvailableCondition)).To(BeTrue()) @@ -519,8 +519,8 @@ func TestClusterReconciler_ReconcileDeploymentZones(t *testing.T) { name: "with all deployment zone statuses as ready", reconciled: true, initObjs: []client.Object{ - deploymentZone(server, "zone-1", pointer.Bool(false), pointer.Bool(true)), - deploymentZone(server, "zone-2", pointer.Bool(true), pointer.Bool(true)), + deploymentZone(server, "zone-1", ptr.To(false), ptr.To(true)), + deploymentZone(server, "zone-2", ptr.To(true), ptr.To(true)), }, assert: func(vsphereCluster *infrav1.VSphereCluster) { g.Expect(conditions.IsTrue(vsphereCluster, infrav1.FailureDomainsAvailableCondition)).To(BeTrue()) @@ -553,17 +553,17 @@ func TestClusterReconciler_ReconcileDeploymentZones(t *testing.T) { t.Run("with zone selectors", func(t *testing.T) { g := NewWithT(t) - zoneOne := deploymentZone(server, "zone-1", pointer.Bool(false), pointer.Bool(true)) + zoneOne := deploymentZone(server, "zone-1", ptr.To(false), ptr.To(true)) zoneOne.Labels = map[string]string{ "zone": "rack-one", "datacenter": "ohio", } - zoneTwo := deploymentZone(server, "zone-2", pointer.Bool(false), pointer.Bool(true)) + zoneTwo := deploymentZone(server, "zone-2", ptr.To(false), ptr.To(true)) zoneTwo.Labels = map[string]string{ "zone": "rack-two", "datacenter": "ohio", } - zoneThree := deploymentZone(server, "zone-3", pointer.Bool(false), pointer.Bool(true)) + zoneThree := deploymentZone(server, "zone-3", ptr.To(false), ptr.To(true)) zoneThree.Labels = map[string]string{ "datacenter": "oregon", } diff --git a/controllers/vspheredeploymentzone_controller.go b/controllers/vspheredeploymentzone_controller.go index 441322fcf6..5449839c46 100644 --- a/controllers/vspheredeploymentzone_controller.go +++ b/controllers/vspheredeploymentzone_controller.go @@ -26,7 +26,7 @@ import ( "k8s.io/apimachinery/pkg/types" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/klog/v2" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" clusterutilv1 "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" @@ -143,26 +143,26 @@ func (r vsphereDeploymentZoneReconciler) reconcileNormal(ctx context.Context, de authSession, err := r.getVCenterSession(ctx, deploymentZoneCtx, failureDomain.Spec.Topology.Datacenter) if err != nil { conditions.MarkFalse(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VCenterAvailableCondition, infrav1.VCenterUnreachableReason, clusterv1.ConditionSeverityError, err.Error()) - deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = pointer.Bool(false) + deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false) return err } deploymentZoneCtx.AuthSession = authSession conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VCenterAvailableCondition) if err := r.reconcilePlacementConstraint(ctx, deploymentZoneCtx); err != nil { - deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = pointer.Bool(false) + deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false) return err } conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.PlacementConstraintMetCondition) // reconcile the failure domain if err := r.reconcileFailureDomain(ctx, deploymentZoneCtx, failureDomain); err != nil { - deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = pointer.Bool(false) + deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(false) return err } // Mark the deployment zone as ready. - deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = pointer.Bool(true) + deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = ptr.To(true) return nil } diff --git a/controllers/vspheredeploymentzone_controller_domain_test.go b/controllers/vspheredeploymentzone_controller_domain_test.go index fce1f7a565..a001b2fbfe 100644 --- a/controllers/vspheredeploymentzone_controller_domain_test.go +++ b/controllers/vspheredeploymentzone_controller_domain_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/vmware/govmomi/simulator" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" "sigs.k8s.io/cluster-api-provider-vsphere/internal/test/helpers/vcsim" @@ -78,7 +78,7 @@ func TestVsphereDeploymentZoneReconciler_Reconcile_VerifyFailureDomain_ComputeCl }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), }, }, } @@ -100,7 +100,7 @@ func TestVsphereDeploymentZoneReconciler_Reconcile_VerifyFailureDomain_ComputeCl g.Expect(simr.Run("tags.attached.ls k8s-region-west-2", stdout)).To(Succeed()) g.Expect(stdout).Should(gbytes.Say("ClusterComputeResource")) - vsphereFailureDomain.Spec.Topology.ComputeCluster = pointer.String("DC0_C1") + vsphereFailureDomain.Spec.Topology.ComputeCluster = ptr.To("DC0_C1") // Since association is verified, the method errors since the tag is not associated to the object. g.Expect(reconciler.verifyFailureDomain(ctx, deploymentZoneCtx, vsphereFailureDomain, vsphereFailureDomain.Spec.Zone)).To(HaveOccurred()) @@ -155,7 +155,7 @@ func TestVsphereDeploymentZoneReconciler_Reconcile_VerifyFailureDomain_HostGroup }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), Hosts: &infrav1.FailureDomainHosts{ HostGroupName: "test_grp_1", }, @@ -240,7 +240,7 @@ func TestVsphereDeploymentZoneReconciler_Reconcile_CreateAndAttachMetadata(t *te }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), }, }, }, @@ -251,11 +251,11 @@ func TestVsphereDeploymentZoneReconciler_Reconcile_CreateAndAttachMetadata(t *te Name: "bar", Type: infrav1.HostGroupFailureDomain, TagCategory: "foo", - AutoConfigure: pointer.Bool(true), + AutoConfigure: ptr.To(true), }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), Hosts: &infrav1.FailureDomainHosts{ HostGroupName: "group-one", VMGroupName: "vm-group-one", diff --git a/controllers/vspheredeploymentzone_controller_test.go b/controllers/vspheredeploymentzone_controller_test.go index 639d5f863f..b58aa97a1a 100644 --- a/controllers/vspheredeploymentzone_controller_test.go +++ b/controllers/vspheredeploymentzone_controller_test.go @@ -26,7 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" @@ -83,17 +83,17 @@ var _ = Describe("VSphereDeploymentZoneReconciler", func() { Name: "k8s-region-west", Type: infrav1.DatacenterFailureDomain, TagCategory: "k8s-region", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Zone: infrav1.FailureDomain{ Name: "k8s-zone-west-1", Type: infrav1.ComputeClusterFailureDomain, TagCategory: "k8s-zone", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), Datastore: "LocalDS_0", Networks: []string{"VM Network"}, }, @@ -108,7 +108,7 @@ var _ = Describe("VSphereDeploymentZoneReconciler", func() { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: vsphereFailureDomain.Name, - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: "DC0_C0_RP1", Folder: "/", @@ -164,17 +164,17 @@ var _ = Describe("VSphereDeploymentZoneReconciler", func() { Name: "k8s-region-west", Type: infrav1.DatacenterFailureDomain, TagCategory: "k8s-region", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Zone: infrav1.FailureDomain{ Name: "k8s-zone-west-1", Type: infrav1.ComputeClusterFailureDomain, TagCategory: "k8s-zone", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), Datastore: "LocalDS_0", Networks: []string{"VM Network"}, }, @@ -189,7 +189,7 @@ var _ = Describe("VSphereDeploymentZoneReconciler", func() { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: vsphereFailureDomain.Name, - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: "DC0_C1_RP1", Folder: "/", @@ -250,7 +250,7 @@ var _ = Describe("VSphereDeploymentZoneReconciler", func() { Context("when machines are using Deployment Zone", func() { It("should block deletion", func() { machineUsingDeplZone := createMachine("machine-using-zone", "cluster-using-zone", machineNamespace.Name, false) - machineUsingDeplZone.Spec.FailureDomain = pointer.String(vsphereDeploymentZone.Name) + machineUsingDeplZone.Spec.FailureDomain = ptr.To(vsphereDeploymentZone.Name) Expect(testEnv.Create(ctx, machineUsingDeplZone)).To(Succeed()) Expect(testEnv.Delete(ctx, vsphereDeploymentZone)).To(Succeed()) @@ -266,7 +266,7 @@ var _ = Describe("VSphereDeploymentZoneReconciler", func() { It("should not block deletion if machines are being deleted", func() { machineBeingDeleted := createMachine("machine-deleted", "cluster-deleted", machineNamespace.Name, false) - machineBeingDeleted.Spec.FailureDomain = pointer.String(vsphereDeploymentZone.Name) + machineBeingDeleted.Spec.FailureDomain = ptr.To(vsphereDeploymentZone.Name) machineBeingDeleted.Finalizers = []string{clusterv1.MachineFinalizer} Expect(testEnv.Create(ctx, machineBeingDeleted)).To(Succeed()) @@ -333,17 +333,17 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) { Name: "k8s-region-west", Type: infrav1.DatacenterFailureDomain, TagCategory: "k8s-region", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Zone: infrav1.FailureDomain{ Name: "k8s-zone-west-1", Type: infrav1.ComputeClusterFailureDomain, TagCategory: "k8s-zone", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), Datastore: "LocalDS_0", Networks: []string{"VM Network"}, }, @@ -358,7 +358,7 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: vsphereFailureDomain.Name, - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: "DC0_C0_RP1", Folder: "/", @@ -405,17 +405,17 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) { Name: "k8s-region-west", Type: infrav1.DatacenterFailureDomain, TagCategory: "k8s-region", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Zone: infrav1.FailureDomain{ Name: "k8s-zone-west-1", Type: infrav1.ComputeClusterFailureDomain, TagCategory: "k8s-zone", - AutoConfigure: pointer.Bool(false), + AutoConfigure: ptr.To(false), }, Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), Datastore: "LocalDS_0", Networks: []string{"VM Network"}, }, @@ -430,7 +430,7 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: vsphereFailureDomain.Name, - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: "DC0_C0_RP1", Folder: "/", @@ -468,7 +468,7 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: "fd1", - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: "DC0_C0_RP1", Folder: "/", @@ -503,7 +503,7 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: "fd1", - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: "DC0_C0_RP1", Folder: "/", @@ -545,7 +545,7 @@ func createMachine(machineName, clusterName, namespace string, isControlPlane bo }, }, Spec: clusterv1.MachineSpec{ - Version: pointer.String("v1.22.0"), + Version: ptr.To("v1.22.0"), Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: bootstrapv1.GroupVersion.String(), @@ -617,7 +617,7 @@ func TestVsphereDeploymentZone_Failed_ReconcilePlacementConstraint(t *testing.T) Spec: infrav1.VSphereFailureDomainSpec{ Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), }, }, })).To(Succeed()) @@ -627,7 +627,7 @@ func TestVsphereDeploymentZone_Failed_ReconcilePlacementConstraint(t *testing.T) VSphereDeploymentZone: &infrav1.VSphereDeploymentZone{Spec: infrav1.VSphereDeploymentZoneSpec{ Server: simr.ServerURL().Host, FailureDomain: "blah", - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: tt.placementConstraint, }}, } @@ -661,14 +661,14 @@ func TestVSphereDeploymentZoneReconciler_ReconcileDelete(t *testing.T) { Spec: infrav1.VSphereFailureDomainSpec{ Topology: infrav1.Topology{ Datacenter: "DC0", - ComputeCluster: pointer.String("DC0_C0"), + ComputeCluster: ptr.To("DC0_C0"), }, }, } t.Run("when machines are using deployment zone", func(t *testing.T) { machineUsingDeplZone := createMachine("machine-1", "cluster-1", "ns", false) - machineUsingDeplZone.Spec.FailureDomain = pointer.String("blah") + machineUsingDeplZone.Spec.FailureDomain = ptr.To("blah") t.Run("should block deletion", func(t *testing.T) { controllerManagerContext := fake.NewControllerManagerContext(machineUsingDeplZone, vsphereFailureDomain) diff --git a/controllers/vspheremachine_controller_test.go b/controllers/vspheremachine_controller_test.go index b67584fc5e..79ab407b3f 100644 --- a/controllers/vspheremachine_controller_test.go +++ b/controllers/vspheremachine_controller_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" capiutil "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" @@ -196,7 +196,7 @@ var _ = Describe("VsphereMachineReconciler", func() { ph, err := patch.NewHelper(capiMachine, testEnv) Expect(err).ShouldNot(HaveOccurred()) capiMachine.Spec.Bootstrap = clusterv1.Bootstrap{ - DataSecretName: pointer.String("some-secret"), + DataSecretName: ptr.To("some-secret"), } return ph.Patch(ctx, capiMachine, patch.WithStatusObservedGeneration{}) }, timeout).Should(BeNil()) diff --git a/controllers/vspherevm_controller.go b/controllers/vspherevm_controller.go index 5abbd980cc..f78c765729 100644 --- a/controllers/vspherevm_controller.go +++ b/controllers/vspherevm_controller.go @@ -29,7 +29,7 @@ import ( kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/client-go/tools/record" "k8s.io/klog/v2" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/remote" ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1alpha1" @@ -627,7 +627,7 @@ func (r vmReconciler) fetchClusterModuleInfo(ctx context.Context, clusterModInpu for _, mod := range clusterModInput.VSphereCluster.Spec.ClusterModules { if mod.TargetObjectName == owner.GetName() { log.V(4).Info("Cluster module found", "moduleUUID", mod.ModuleUUID) - return pointer.String(mod.ModuleUUID), nil + return ptr.To(mod.ModuleUUID), nil } } log.V(4).Info("No cluster module found") diff --git a/controllers/vspherevm_ipaddress_reconciler_test.go b/controllers/vspherevm_ipaddress_reconciler_test.go index e6b38ef1b7..5f795a82af 100644 --- a/controllers/vspherevm_ipaddress_reconciler_test.go +++ b/controllers/vspherevm_ipaddress_reconciler_test.go @@ -23,7 +23,7 @@ import ( "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1alpha1" "sigs.k8s.io/cluster-api/util/conditions" @@ -244,7 +244,7 @@ func Test_vmReconciler_reconcileIPAddressClaims(t *testing.T) { func poolRef(name string) corev1.TypedLocalObjectReference { return corev1.TypedLocalObjectReference{ - APIGroup: pointer.String("test.ipam.provider.io/v1"), + APIGroup: ptr.To("test.ipam.provider.io/v1"), Name: name, Kind: "my-pool-kind", } diff --git a/go.mod b/go.mod index 8c9a957daa..f68ba72d1b 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( k8s.io/cluster-bootstrap v0.28.5 k8s.io/component-base v0.28.5 k8s.io/klog/v2 v2.100.1 - k8s.io/utils v0.0.0-20230505201702-9f6742963106 + k8s.io/utils v0.0.0-20231127182322-b307cd553661 sigs.k8s.io/cluster-api v0.0.0-00010101000000-000000000000 sigs.k8s.io/controller-runtime v0.16.3 sigs.k8s.io/kustomize/api v0.16.0 diff --git a/go.sum b/go.sum index a7431bcc25..4b32fe6494 100644 --- a/go.sum +++ b/go.sum @@ -984,8 +984,8 @@ k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5Ohx k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210527160623-6fdb442a123b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU= -k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI= +k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/internal/webhooks/vspheredeploymentzone.go b/internal/webhooks/vspheredeploymentzone.go index 3805136834..128b67771c 100644 --- a/internal/webhooks/vspheredeploymentzone.go +++ b/internal/webhooks/vspheredeploymentzone.go @@ -22,7 +22,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/webhook" @@ -50,7 +50,7 @@ func (webhook *VSphereDeploymentZoneWebhook) Default(_ context.Context, obj runt return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereDeploymentZone but got a %T", obj)) } if typedObj.Spec.ControlPlane == nil { - typedObj.Spec.ControlPlane = pointer.Bool(true) + typedObj.Spec.ControlPlane = ptr.To(true) } return nil diff --git a/internal/webhooks/vspheredeploymentzone_test.go b/internal/webhooks/vspheredeploymentzone_test.go index 2980b44c63..cdeb528357 100644 --- a/internal/webhooks/vspheredeploymentzone_test.go +++ b/internal/webhooks/vspheredeploymentzone_test.go @@ -21,7 +21,7 @@ import ( "testing" . "github.com/onsi/gomega" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" ) @@ -41,7 +41,7 @@ func TestVSphereDeploymentZone_Default(t *testing.T) { }, { name: "when control plane is set", - boolPtr: pointer.Bool(false), + boolPtr: ptr.To(false), expectedVal: false, }, } diff --git a/internal/webhooks/vspherefailuredomain.go b/internal/webhooks/vspherefailuredomain.go index 8c0622aa28..3406506c91 100644 --- a/internal/webhooks/vspherefailuredomain.go +++ b/internal/webhooks/vspherefailuredomain.go @@ -24,7 +24,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" @@ -108,11 +108,11 @@ func (webhook *VSphereFailureDomainWebhook) Default(_ context.Context, obj runti return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereFailureDomain but got a %T", obj)) } if typedObj.Spec.Zone.AutoConfigure == nil { - typedObj.Spec.Zone.AutoConfigure = pointer.Bool(false) + typedObj.Spec.Zone.AutoConfigure = ptr.To(false) } if typedObj.Spec.Region.AutoConfigure == nil { - typedObj.Spec.Region.AutoConfigure = pointer.Bool(false) + typedObj.Spec.Region.AutoConfigure = ptr.To(false) } return nil diff --git a/internal/webhooks/vspherefailuredomain_test.go b/internal/webhooks/vspherefailuredomain_test.go index a560c61bb4..e22fb86dcd 100644 --- a/internal/webhooks/vspherefailuredomain_test.go +++ b/internal/webhooks/vspherefailuredomain_test.go @@ -21,7 +21,7 @@ import ( "testing" . "github.com/onsi/gomega" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" ) @@ -53,7 +53,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) { Name: "foo", Type: infrav1.HostGroupFailureDomain, TagCategory: "k8s-bar", - AutoConfigure: pointer.Bool(true), + AutoConfigure: ptr.To(true), }, }}, }, @@ -85,7 +85,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) { }, Topology: infrav1.Topology{ Datacenter: "/blah", - ComputeCluster: pointer.String("blah2"), + ComputeCluster: ptr.To("blah2"), Hosts: nil, }, }}, diff --git a/internal/webhooks/vspheremachinetemplate_test.go b/internal/webhooks/vspheremachinetemplate_test.go index faad6a4e8b..3c6a1397d7 100644 --- a/internal/webhooks/vspheremachinetemplate_test.go +++ b/internal/webhooks/vspheremachinetemplate_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/gomega" admissionv1 "k8s.io/api/admission/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" @@ -96,35 +96,35 @@ func TestVSphereMachineTemplate_ValidateUpdate(t *testing.T) { name: "ProviderID cannot be updated", oldVSphereMachine: createVSphereMachineTemplate("foo.com", "", nil, "", []string{"192.168.0.1/32"}), vsphereMachine: createVSphereMachineTemplate("foo.com", "", &someProviderID, "", []string{"192.168.0.1/32"}), - req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: pointer.Bool(false)}}, + req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(false)}}, wantErr: true, }, { name: "ip addresses cannot be updated", oldVSphereMachine: createVSphereMachineTemplate("foo.com", "", nil, "", []string{"192.168.0.1/32"}), vsphereMachine: createVSphereMachineTemplate("foo.com", "", &someProviderID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}), - req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: pointer.Bool(false)}}, + req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(false)}}, wantErr: true, }, { name: "server cannot be updated", oldVSphereMachine: createVSphereMachineTemplate("foo.com", "", nil, "", []string{"192.168.0.1/32"}), vsphereMachine: createVSphereMachineTemplate("baz.com", "", &someProviderID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}), - req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: pointer.Bool(false)}}, + req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(false)}}, wantErr: true, }, { name: "hardware version cannot be updated", oldVSphereMachine: createVSphereMachineTemplate("foo.com", "vmx-16", nil, "", []string{"192.168.0.1/32"}), vsphereMachine: createVSphereMachineTemplate("baz.com", "vmx-17", nil, "", []string{"192.168.0.1/32"}), - req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: pointer.Bool(false)}}, + req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(false)}}, wantErr: true, }, { name: "with hardware version set and not updated", oldVSphereMachine: createVSphereMachineTemplate("foo.com", "vmx-16", nil, "", []string{"192.168.0.1/32"}), vsphereMachine: createVSphereMachineTemplate("foo.com", "vmx-16", nil, "", []string{"192.168.0.1/32"}), - req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: pointer.Bool(false)}}, + req: &admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(false)}}, wantErr: false, // explicitly calling out that this is a valid scenario. }, } diff --git a/packaging/flavorgen/flavors/clusterclass_generators.go b/packaging/flavorgen/flavors/clusterclass_generators.go index d562272041..c03fe0024a 100644 --- a/packaging/flavorgen/flavors/clusterclass_generators.go +++ b/packaging/flavorgen/flavors/clusterclass_generators.go @@ -21,7 +21,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" @@ -122,7 +122,7 @@ func getCredSecretNameTemplate() *string { "kind": "Secret", } templateStr, _ := yaml.Marshal(template) - return pointer.String(string(templateStr)) + return ptr.To(string(templateStr)) } func getControlPlaneEndpointTemplate() *string { @@ -131,7 +131,7 @@ func getControlPlaneEndpointTemplate() *string { "port": 6443, } templateStr, _ := yaml.Marshal(template) - return pointer.String(string(templateStr)) + return ptr.To(string(templateStr)) } func getEnableSSHIntoNodesTemplate() *string { @@ -145,7 +145,7 @@ func getEnableSSHIntoNodesTemplate() *string { }, } templateStr, _ := yaml.Marshal(template) - return pointer.String(string(templateStr)) + return ptr.To(string(templateStr)) } func getClusterClassVariables() []clusterv1.ClusterClassVariable { diff --git a/packaging/flavorgen/flavors/generators.go b/packaging/flavorgen/flavors/generators.go index bb132f75c7..257e8372f2 100644 --- a/packaging/flavorgen/flavors/generators.go +++ b/packaging/flavorgen/flavors/generators.go @@ -24,7 +24,7 @@ import ( corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" @@ -117,14 +117,14 @@ func newClusterTopologyCluster() (clusterv1.Cluster, error) { Class: env.ClusterClassNameVar, Version: env.KubernetesVersionVar, ControlPlane: clusterv1.ControlPlaneTopology{ - Replicas: pointer.Int32(1), + Replicas: ptr.To[int32](1), }, Workers: &clusterv1.WorkersTopology{ MachineDeployments: []clusterv1.MachineDeploymentTopology{ { Class: fmt.Sprintf("%s-worker", env.ClusterClassNameVar), Name: "md-0", - Replicas: pointer.Int32(3), + Replicas: ptr.To[int32](3), }, }, }, @@ -349,7 +349,7 @@ func nodeIPAMVirtualMachineCloneSpec() infrav1.VirtualMachineCloneSpec { DHCP6: false, AddressesFromPools: []corev1.TypedLocalObjectReference{ { - APIGroup: pointer.String(env.NodeIPAMPoolAPIGroup), + APIGroup: ptr.To(env.NodeIPAMPoolAPIGroup), Kind: env.NodeIPAMPoolKind, Name: env.NodeIPAMPoolName, }, @@ -499,7 +499,7 @@ func defaultUsers() []bootstrapv1.User { return []bootstrapv1.User{ { Name: "capv", - Sudo: pointer.String("ALL=(ALL) NOPASSWD:ALL"), + Sudo: ptr.To("ALL=(ALL) NOPASSWD:ALL"), SSHAuthorizedKeys: []string{ env.VSphereSSHAuthorizedKeysVar, }, @@ -511,7 +511,7 @@ func flatcarUsers() []bootstrapv1.User { return []bootstrapv1.User{ { Name: "core", - Sudo: pointer.String("ALL=(ALL) NOPASSWD:ALL"), + Sudo: ptr.To("ALL=(ALL) NOPASSWD:ALL"), SSHAuthorizedKeys: []string{ env.VSphereSSHAuthorizedKeysVar, }, @@ -600,13 +600,13 @@ func newMachineDeployment(cluster clusterv1.Cluster, machineTemplate infrav1.VSp }, Spec: clusterv1.MachineDeploymentSpec{ ClusterName: env.ClusterNameVar, - Replicas: pointer.Int32(int32(555)), + Replicas: ptr.To[int32](555), Template: clusterv1.MachineTemplateSpec{ ObjectMeta: clusterv1.ObjectMeta{ Labels: clusterLabels(), }, Spec: clusterv1.MachineSpec{ - Version: pointer.String(env.KubernetesVersionVar), + Version: ptr.To(env.KubernetesVersionVar), ClusterName: cluster.Name, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ diff --git a/packaging/flavorgen/flavors/kubevip/topology.go b/packaging/flavorgen/flavors/kubevip/topology.go index d80abc9b44..8fd1f3b3e4 100644 --- a/packaging/flavorgen/flavors/kubevip/topology.go +++ b/packaging/flavorgen/flavors/kubevip/topology.go @@ -24,7 +24,7 @@ import ( "github.com/pkg/errors" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" @@ -79,13 +79,13 @@ func TopologyPatch() clusterv1.ClusterClassPatch { `content: {{ printf "%q" (regexReplaceAll "(name: address\n +value:).*" .kubeVipPodManifest (printf "$1 %s" .controlPlaneIpAddr)) }}`, fmt.Sprintf("permissions: %q", f.Permissions), } - p.ValueFrom.Template = pointer.String(strings.Join(lines, "\n")) + p.ValueFrom.Template = ptr.To(strings.Join(lines, "\n")) patches = append(patches, p) continue } tpl, _ := fileToTemplate(f) - p.ValueFrom.Template = pointer.String(tpl) + p.ValueFrom.Template = ptr.To(tpl) patches = append(patches, p) } @@ -94,12 +94,12 @@ func TopologyPatch() clusterv1.ClusterClassPatch { clusterv1.JSONPatch{ Op: "add", Path: "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-", - ValueFrom: &clusterv1.JSONPatchValue{Template: pointer.String("/etc/kube-vip-prepare.sh")}, + ValueFrom: &clusterv1.JSONPatchValue{Template: ptr.To("/etc/kube-vip-prepare.sh")}, }, clusterv1.JSONPatch{ Op: "add", Path: "/spec/template/spec/kubeadmConfigSpec/postKubeadmCommands/-", - ValueFrom: &clusterv1.JSONPatchValue{Template: pointer.String("/etc/kube-vip-cleanup.sh")}, + ValueFrom: &clusterv1.JSONPatchValue{Template: ptr.To("/etc/kube-vip-cleanup.sh")}, }, ) diff --git a/packaging/flavorgen/flavors/patches.go b/packaging/flavorgen/flavors/patches.go index 5ed249feb6..676a8c441a 100644 --- a/packaging/flavorgen/flavors/patches.go +++ b/packaging/flavorgen/flavors/patches.go @@ -20,7 +20,7 @@ import ( "fmt" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" @@ -93,7 +93,7 @@ func createEmptyArraysPatch() clusterv1.ClusterClassPatch { func enableSSHPatch() clusterv1.ClusterClassPatch { return clusterv1.ClusterClassPatch{ Name: "enableSSHIntoNodes", - EnabledIf: pointer.String("{{ if .sshKey }}true{{end}}"), + EnabledIf: ptr.To("{{ if .sshKey }}true{{end}}"), Definitions: []clusterv1.PatchDefinition{ { Selector: clusterv1.PatchSelector{ @@ -169,14 +169,14 @@ func infraClusterPatch() clusterv1.ClusterClassPatch { Op: "add", Path: "/spec/template/spec/server", ValueFrom: &clusterv1.JSONPatchValue{ - Variable: pointer.String("infraServer.url"), + Variable: ptr.To("infraServer.url"), }, }, { Op: "add", Path: "/spec/template/spec/thumbprint", ValueFrom: &clusterv1.JSONPatchValue{ - Variable: pointer.String("infraServer.thumbprint"), + Variable: ptr.To("infraServer.thumbprint"), }, }, }, diff --git a/pkg/services/govmomi/cluster/rule.go b/pkg/services/govmomi/cluster/rule.go index 2f5e47797a..44e118842e 100644 --- a/pkg/services/govmomi/cluster/rule.go +++ b/pkg/services/govmomi/cluster/rule.go @@ -21,7 +21,7 @@ import ( "github.com/pkg/errors" "github.com/vmware/govmomi/vim25/types" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // Rule is a role for host affinity. @@ -36,7 +36,7 @@ type vmHostAffinityRule struct { } func (v vmHostAffinityRule) IsMandatory() bool { - return pointer.BoolDeref(v.Mandatory, false) + return ptr.Deref(v.Mandatory, false) } func (v vmHostAffinityRule) Disabled() bool { diff --git a/pkg/services/govmomi/find/object_test.go b/pkg/services/govmomi/find/object_test.go index 3d3bf8b78c..bd119e5b35 100644 --- a/pkg/services/govmomi/find/object_test.go +++ b/pkg/services/govmomi/find/object_test.go @@ -26,7 +26,7 @@ import ( . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/vmware/govmomi/simulator" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" "sigs.k8s.io/cluster-api-provider-vsphere/internal/test/helpers/vcsim" @@ -56,7 +56,7 @@ func TestObjectFunc(t *testing.T) { topology := infrav1.Topology{ Datacenter: defaultDatacenter.Name(), - ComputeCluster: pointer.String(defaultDatacenter.Name() + "_C0"), + ComputeCluster: ptr.To(defaultDatacenter.Name() + "_C0"), Hosts: &infrav1.FailureDomainHosts{HostGroupName: TestHostGroup}, } diff --git a/pkg/services/govmomi/pci/device_test.go b/pkg/services/govmomi/pci/device_test.go index bdfb194532..74f57245c8 100644 --- a/pkg/services/govmomi/pci/device_test.go +++ b/pkg/services/govmomi/pci/device_test.go @@ -24,7 +24,7 @@ import ( "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/vim25" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" ) @@ -74,8 +74,8 @@ func Test_CalculateDevicesToBeAdded(t *testing.T) { name: "when adding a single PCI device of each type", expectedLen: 2, pciDeviceSpecs: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(4321), VendorID: pointer.Int32(8765)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](4321), VendorID: ptr.To[int32](8765)}, }, assertFunc: func(g *gomega.WithT, actual []infrav1.PCIDeviceSpec) { g.Expect(*actual[0].DeviceID).To(gomega.Equal(int32(1234))) @@ -88,8 +88,8 @@ func Test_CalculateDevicesToBeAdded(t *testing.T) { name: "when adding multiple PCI devices of a type", expectedLen: 2, pciDeviceSpecs: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, }, assertFunc: func(g *gomega.WithT, actual []infrav1.PCIDeviceSpec) { g.Expect(*actual[0].DeviceID).To(gomega.Equal(int32(1234))) @@ -110,8 +110,8 @@ func Test_CalculateDevicesToBeAdded(t *testing.T) { name: "when adding a single PCI device of each type", expectedLen: 0, pciDeviceSpecs: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(4321), VendorID: pointer.Int32(8765)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](4321), VendorID: ptr.To[int32](8765)}, }, existingDeviceSpecIndexes: []int{0, 1}, }, @@ -119,8 +119,8 @@ func Test_CalculateDevicesToBeAdded(t *testing.T) { name: "when adding multiple PCI devices of a type", expectedLen: 0, pciDeviceSpecs: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, }, existingDeviceSpecIndexes: []int{0, 1}, }, @@ -136,8 +136,8 @@ func Test_CalculateDevicesToBeAdded(t *testing.T) { name: "when adding a single PCI device of each type", expectedLen: 1, pciDeviceSpecs: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(4321), VendorID: pointer.Int32(8765)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](4321), VendorID: ptr.To[int32](8765)}, }, existingDeviceSpecIndexes: []int{0}, assertFunc: func(g *gomega.WithT, actual []infrav1.PCIDeviceSpec) { @@ -149,9 +149,9 @@ func Test_CalculateDevicesToBeAdded(t *testing.T) { name: "when adding multiple PCI devices of a type", expectedLen: 2, pciDeviceSpecs: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(4321), VendorID: pointer.Int32(8765)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](4321), VendorID: ptr.To[int32](8765)}, }, existingDeviceSpecIndexes: []int{0}, assertFunc: func(g *gomega.WithT, actual []infrav1.PCIDeviceSpec) { diff --git a/pkg/services/govmomi/service_test.go b/pkg/services/govmomi/service_test.go index ad7e190511..74e4f38e30 100644 --- a/pkg/services/govmomi/service_test.go +++ b/pkg/services/govmomi/service_test.go @@ -29,7 +29,7 @@ import ( "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/types" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client/fake" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" @@ -81,8 +81,8 @@ func Test_reconcilePCIDevices(t *testing.T) { Spec: infrav1.VSphereVMSpec{ VirtualMachineCloneSpec: infrav1.VirtualMachineCloneSpec{ PciDevices: []infrav1.PCIDeviceSpec{ - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, - {DeviceID: pointer.Int32(1234), VendorID: pointer.Int32(5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, + {DeviceID: ptr.To[int32](1234), VendorID: ptr.To[int32](5678)}, }, }, }, diff --git a/pkg/services/govmomi/vcenter/clone.go b/pkg/services/govmomi/vcenter/clone.go index bd00c87551..e216790081 100644 --- a/pkg/services/govmomi/vcenter/clone.go +++ b/pkg/services/govmomi/vcenter/clone.go @@ -29,7 +29,7 @@ import ( pbmTypes "github.com/vmware/govmomi/pbm/types" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/types" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" ctrl "sigs.k8s.io/controller-runtime" @@ -204,7 +204,7 @@ func Clone(ctx context.Context, vmCtx *capvcontext.VMContext, bootstrapData []by // We can replace this once we have another way of reserving memory option // exposed via the API types. if len(vmCtx.VSphereVM.Spec.PciDevices) > 0 { - spec.Config.MemoryReservationLockedToMax = pointer.Bool(true) + spec.Config.MemoryReservationLockedToMax = ptr.To(true) } var datastoreRef *types.ManagedObjectReference diff --git a/pkg/services/vimmachine_test.go b/pkg/services/vimmachine_test.go index f93df0933a..27dab08545 100644 --- a/pkg/services/vimmachine_test.go +++ b/pkg/services/vimmachine_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" ctrl "sigs.k8s.io/controller-runtime" @@ -43,7 +43,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: fmt.Sprintf("server-%s", suffix), FailureDomain: fmt.Sprintf("fd-%s", suffix), - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: fmt.Sprintf("rp-%s", suffix), Folder: fmt.Sprintf("folder-%s", suffix), @@ -79,7 +79,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { g := NewWithT(t) controllerManagerContext := fake.NewControllerManagerContext(deplZone("one"), deplZone("two"), failureDomain("one"), failureDomain("two")) machineCtx := fake.NewMachineContext(ctx, fake.NewClusterContext(ctx, controllerManagerContext), controllerManagerContext) - machineCtx.Machine.Spec.FailureDomain = pointer.String("zone-one") + machineCtx.Machine.Spec.FailureDomain = ptr.To("zone-one") vimMachineService := &VimMachineService{controllerManagerContext.Client} _, ok := vimMachineService.generateOverrideFunc(ctx, machineCtx) @@ -90,7 +90,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { g := NewWithT(t) controllerManagerContext := fake.NewControllerManagerContext(deplZone("one"), deplZone("two"), failureDomain("one"), failureDomain("two")) machineCtx := fake.NewMachineContext(ctx, fake.NewClusterContext(ctx, controllerManagerContext), controllerManagerContext) - machineCtx.Machine.Spec.FailureDomain = pointer.String("zone-one") + machineCtx.Machine.Spec.FailureDomain = ptr.To("zone-one") vimMachineService := &VimMachineService{controllerManagerContext.Client} overrideFunc, ok := vimMachineService.generateOverrideFunc(ctx, machineCtx) @@ -110,7 +110,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { g := NewWithT(t) controllerManagerContext := fake.NewControllerManagerContext(deplZone("one"), deplZone("two"), failureDomain("one"), failureDomain("two")) machineCtx := fake.NewMachineContext(ctx, fake.NewClusterContext(ctx, controllerManagerContext), controllerManagerContext) - machineCtx.Machine.Spec.FailureDomain = pointer.String("non-existent-zone") + machineCtx.Machine.Spec.FailureDomain = ptr.To("non-existent-zone") vimMachineService := &VimMachineService{controllerManagerContext.Client} overrideFunc, ok := vimMachineService.generateOverrideFunc(ctx, machineCtx) @@ -122,7 +122,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { g := NewWithT(t) controllerManagerContext := fake.NewControllerManagerContext(deplZone("one"), deplZone("two"), failureDomain("one"), failureDomain("two")) machineCtx := fake.NewMachineContext(ctx, fake.NewClusterContext(ctx, controllerManagerContext), controllerManagerContext) - machineCtx.Machine.Spec.FailureDomain = pointer.String("zone-one") + machineCtx.Machine.Spec.FailureDomain = ptr.To("zone-one") vimMachineService := &VimMachineService{controllerManagerContext.Client} vm := &infrav1.VSphereVM{ @@ -149,7 +149,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { g := NewWithT(t) controllerManagerContext := fake.NewControllerManagerContext(deplZone("one"), deplZone("two"), failureDomain("one"), failureDomain("two")) machineCtx := fake.NewMachineContext(ctx, fake.NewClusterContext(ctx, controllerManagerContext), controllerManagerContext) - machineCtx.Machine.Spec.FailureDomain = pointer.String("zone-one") + machineCtx.Machine.Spec.FailureDomain = ptr.To("zone-one") vimMachineService := &VimMachineService{controllerManagerContext.Client} vm := &infrav1.VSphereVM{ @@ -176,7 +176,7 @@ func Test_VimMachineService_GenerateOverrideFunc(t *testing.T) { g := NewWithT(t) controllerManagerContext := fake.NewControllerManagerContext(deplZone("one"), deplZone("two"), failureDomain("one"), failureDomain("two")) machineCtx := fake.NewMachineContext(ctx, fake.NewClusterContext(ctx, controllerManagerContext), controllerManagerContext) - machineCtx.Machine.Spec.FailureDomain = pointer.String("zone-one") + machineCtx.Machine.Spec.FailureDomain = ptr.To("zone-one") vimMachineService := &VimMachineService{controllerManagerContext.Client} vm := &infrav1.VSphereVM{ @@ -276,7 +276,7 @@ func Test_VimMachineService_createOrPatchVSphereVM(t *testing.T) { Spec: infrav1.VSphereDeploymentZoneSpec{ Server: fmt.Sprintf("server-%s", suffix), FailureDomain: fmt.Sprintf("fd-%s", suffix), - ControlPlane: pointer.Bool(true), + ControlPlane: ptr.To(true), PlacementConstraint: infrav1.PlacementConstraint{ ResourcePool: fmt.Sprintf("rp-%s", suffix), Folder: fmt.Sprintf("folder-%s", suffix), diff --git a/pkg/util/supervisor_test.go b/pkg/util/supervisor_test.go index 4f72539c28..85c9446f5d 100644 --- a/pkg/util/supervisor_test.go +++ b/pkg/util/supervisor_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1" @@ -99,7 +99,7 @@ func TestSetControllerReferenceWithOverride(t *testing.T) { { Kind: "ProviderServiceAccount", Name: "non-controller-owner", - Controller: pointer.Bool(true), + Controller: ptr.To(true), }, }, }, @@ -143,7 +143,7 @@ func TestSetControllerReferenceWithOverride(t *testing.T) { { Kind: "ProviderServiceAccount", Name: "owner", - Controller: pointer.Bool(true), + Controller: ptr.To(true), }, }, },