Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Replace util/pointer with util/ptr #2581

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controllers/serviceaccount_controller_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions controllers/vspherecluster_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
30 changes: 15 additions & 15 deletions controllers/vspherecluster_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{},
}
Expand Down Expand Up @@ -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())

Expand All @@ -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())
})
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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",
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/vspheredeploymentzone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions controllers/vspheredeploymentzone_controller_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestVsphereDeploymentZoneReconciler_Reconcile_VerifyFailureDomain_ComputeCl
},
Topology: infrav1.Topology{
Datacenter: "DC0",
ComputeCluster: pointer.String("DC0_C0"),
ComputeCluster: ptr.To("DC0_C0"),
},
},
}
Expand All @@ -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())

Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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"),
},
},
},
Expand All @@ -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",
Expand Down
Loading