Skip to content

Commit

Permalink
chore: replace deprecated k8s.io/utils/pointer with k8s.io/utils/ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
hrak committed Sep 5, 2024
1 parent 9f4300a commit eccc027
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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"

v1beta1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
Expand Down Expand Up @@ -106,7 +106,7 @@ var _ = Describe("Conversion", func() {
Port: 443,
},
APIServerLoadBalancer: &v1beta3.APIServerLoadBalancer{
Enabled: pointer.Bool(true),
Enabled: ptr.To(true),
AdditionalPorts: []int{},
AllowedCIDRs: []string{},
},
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta2/cloudstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1beta2

import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
Expand Down Expand Up @@ -52,7 +52,7 @@ func Convert_v1beta2_CloudStackClusterSpec_To_v1beta3_CloudStackClusterSpec(in *
}

out.APIServerLoadBalancer = &v1beta3.APIServerLoadBalancer{
Enabled: pointer.Bool(true),
Enabled: ptr.To(true),
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta2/cloudstackmachine_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1beta2_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

capcv1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
)
Expand All @@ -43,7 +43,7 @@ var _ = Describe("CloudStackMachineConfig_CompressUserdata", func() {
Name: "is false when uncompressed user data is true",
Machine: capcv1.CloudStackMachine{
Spec: capcv1.CloudStackMachineSpec{
UncompressedUserData: pointer.Bool(true),
UncompressedUserData: ptr.To(true),
},
},
Expect: false,
Expand All @@ -52,7 +52,7 @@ var _ = Describe("CloudStackMachineConfig_CompressUserdata", func() {
Name: "Is false when uncompressed user data is false",
Machine: capcv1.CloudStackMachine{
Spec: capcv1.CloudStackMachineSpec{
UncompressedUserData: pointer.Bool(false),
UncompressedUserData: ptr.To(false),
},
},
Expect: true,
Expand Down
18 changes: 9 additions & 9 deletions controllers/cloudstackfailuredomain_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -121,17 +121,17 @@ var _ = Describe("CloudStackFailureDomainReconciler", func() {
}
},
// should delete - simulate owner is kubeadmcontrolplane
Entry("Should delete machine if spec.replicas > 1", true, pointer.Int32(2), pointer.Int32(2), pointer.Int32(2), pointer.Bool(true), true),
Entry("Should delete machine if spec.replicas > 1", true, ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(true), true),
// should delete - simulate owner is etcdadmcluster
Entry("Should delete machine if status.readyReplica does not exist", true, pointer.Int32(2), pointer.Int32(2), nil, pointer.Bool(true), true),
Entry("Should delete machine if status.readyReplica does not exist", true, ptr.To(int32(2)), ptr.To(int32(2)), nil, ptr.To(true), true),
// should delete - simulate owner is machineset
Entry("Should delete machine if status.ready does not exist", true, pointer.Int32(2), pointer.Int32(2), pointer.Int32(2), nil, true),
Entry("Should delete machine if status.ready does not exist", true, ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(int32(2)), nil, true),
// should not delete if condition not met
Entry("Should not delete machine if cluster control plane not ready", false, pointer.Int32(2), pointer.Int32(2), pointer.Int32(2), pointer.Bool(true), false),
Entry("Should not delete machine if status.replicas < spec.replicas", false, pointer.Int32(2), pointer.Int32(1), pointer.Int32(1), pointer.Bool(true), true),
Entry("Should not delete machine if spec.replicas < 2", false, pointer.Int32(1), pointer.Int32(1), pointer.Int32(1), pointer.Bool(true), true),
Entry("Should not delete machine if status.ready is false", false, pointer.Int32(2), pointer.Int32(2), pointer.Int32(2), pointer.Bool(false), true),
Entry("Should not delete machine if status.readyReplicas <> status.replicas", false, pointer.Int32(2), pointer.Int32(2), pointer.Int32(1), pointer.Bool(true), true),
Entry("Should not delete machine if cluster control plane not ready", false, ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(true), false),
Entry("Should not delete machine if status.replicas < spec.replicas", false, ptr.To(int32(2)), ptr.To(int32(1)), ptr.To(int32(1)), ptr.To(true), true),
Entry("Should not delete machine if spec.replicas < 2", false, ptr.To(int32(1)), ptr.To(int32(1)), ptr.To(int32(1)), ptr.To(true), true),
Entry("Should not delete machine if status.ready is false", false, ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(false), true),
Entry("Should not delete machine if status.readyReplicas <> status.replicas", false, ptr.To(int32(2)), ptr.To(int32(2)), ptr.To(int32(1)), ptr.To(true), true),
)
})
})
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloudstackisolatednetwork_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -67,7 +67,7 @@ var _ = Describe("CloudStackIsolatedNetworkReconciler", func() {
})

It("Should succeed if API load balancer is disabled.", func() {
dummies.CSCluster.Spec.APIServerLoadBalancer.Enabled = pointer.Bool(false)
dummies.CSCluster.Spec.APIServerLoadBalancer.Enabled = ptr.To(false)
mockCloudClient.EXPECT().GetOrCreateIsolatedNetwork(g.Any(), g.Any(), g.Any()).AnyTimes()
mockCloudClient.EXPECT().AddClusterTag(g.Any(), g.Any(), g.Any()).AnyTimes()
mockCloudClient.EXPECT().AssociatePublicIPAddress(g.Any(), g.Any(), g.Any()).AnyTimes().Return(&cloudstack.PublicIpAddress{
Expand Down
6 changes: 3 additions & 3 deletions controllers/cloudstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
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"
"sigs.k8s.io/cluster-api/util/annotations"
Expand Down Expand Up @@ -356,8 +356,8 @@ func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (ctrl.Result,
// ResolveVMInstanceDetails can get InstanceID by CS machine name
err := r.CSClient.ResolveVMInstanceDetails(r.ReconciliationSubject)
if err != nil {
r.ReconciliationSubject.Status.Status = pointer.String(metav1.StatusFailure)
r.ReconciliationSubject.Status.Reason = pointer.String(err.Error() +
r.ReconciliationSubject.Status.Status = ptr.To(metav1.StatusFailure)
r.ReconciliationSubject.Status.Reason = ptr.To(err.Error() +
fmt.Sprintf(" If this VM has already been deleted, please remove the finalizer named %s from object %s",
"cloudstackmachine.infrastructure.cluster.x-k8s.io", r.ReconciliationSubject.Name))
// Cloudstack VM may be not found or more than one found by name
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloudstackmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
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/patch"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -125,7 +125,7 @@ var _ = Describe("CloudStackMachineReconciler", func() {
})

It("Should call ResolveVMInstanceDetails when CS machine without instanceID deleted", func() {
instanceID := pointer.String("instance-id-123")
instanceID := ptr.To("instance-id-123")
// Mock a call to GetOrCreateVMInstance and set the machine to running.
mockCloudClient.EXPECT().GetOrCreateVMInstance(
gomock.Any(), gomock.Any(), gomock.Any(),
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloud/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/pkg/errors"
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"

infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
Expand Down Expand Up @@ -57,9 +57,9 @@ type VMIface interface {

// Set infrastructure spec and status from the CloudStack API's virtual machine metrics type.
func setMachineDataFromVMMetrics(vmResponse *cloudstack.VirtualMachinesMetric, csMachine *infrav1.CloudStackMachine) {
csMachine.Spec.ProviderID = pointer.String("cloudstack:///" + vmResponse.Id)
csMachine.Spec.ProviderID = ptr.To("cloudstack:///" + vmResponse.Id)
// InstanceID is later used as required parameter to destroy VM.
csMachine.Spec.InstanceID = pointer.String(vmResponse.Id)
csMachine.Spec.InstanceID = ptr.To(vmResponse.Id)
csMachine.Status.Addresses = []corev1.NodeAddress{{Type: corev1.NodeInternalIP, Address: vmResponse.Ipaddress}}
newInstanceState := vmResponse.State
if newInstanceState != csMachine.Status.InstanceState || (newInstanceState != "" && csMachine.Status.InstanceStateLastUpdated.IsZero()) {
Expand Down Expand Up @@ -390,14 +390,14 @@ func (c *client) deployVM(
}
}

csMachine.Spec.InstanceID = pointer.String(vm.Id)
csMachine.Spec.InstanceID = ptr.To(vm.Id)
csMachine.Status.InstanceState = vm.State

return fmt.Errorf("incomplete vm deployment (vm_id=%v): %w", vm.Id, err)
}

csMachine.Spec.InstanceID = pointer.String(deployVMResp.Id)
csMachine.Status.Status = pointer.String(metav1.StatusSuccess)
csMachine.Spec.InstanceID = ptr.To(deployVMResp.Id)
csMachine.Status.Status = ptr.To(metav1.StatusSuccess)

return nil
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloud/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
Expand Down Expand Up @@ -90,8 +90,8 @@ var _ = Describe("Instance", func() {
vmsResp := &cloudstack.VirtualMachinesMetric{Id: *dummies.CSMachine1.Spec.InstanceID}
vms.EXPECT().GetVirtualMachinesMetricByID(*dummies.CSMachine1.Spec.InstanceID).Return(vmsResp, 1, nil)
Ω(client.ResolveVMInstanceDetails(dummies.CSMachine1)).Should(Succeed())
Ω(dummies.CSMachine1.Spec.ProviderID).Should(Equal(pointer.String("cloudstack:///" + vmsResp.Id)))
Ω(dummies.CSMachine1.Spec.InstanceID).Should(Equal(pointer.String(vmsResp.Id)))
Ω(dummies.CSMachine1.Spec.ProviderID).Should(Equal(ptr.To("cloudstack:///" + vmsResp.Id)))
Ω(dummies.CSMachine1.Spec.InstanceID).Should(Equal(ptr.To(vmsResp.Id)))
})

It("handles an unknown error when fetching by name", func() {
Expand All @@ -116,8 +116,8 @@ var _ = Describe("Instance", func() {

Ω(client.ResolveVMInstanceDetails(dummies.CSMachine1)).Should(Succeed())
Ω(dummies.CSMachine1.Spec.ProviderID).Should(Equal(
pointer.String("cloudstack:///" + *dummies.CSMachine1.Spec.InstanceID)))
Ω(dummies.CSMachine1.Spec.InstanceID).Should(Equal(pointer.String(*dummies.CSMachine1.Spec.InstanceID)))
ptr.To("cloudstack:///" + *dummies.CSMachine1.Spec.InstanceID)))
Ω(dummies.CSMachine1.Spec.InstanceID).Should(Equal(ptr.To(*dummies.CSMachine1.Spec.InstanceID)))
})
})

Expand Down Expand Up @@ -671,7 +671,7 @@ var _ = Describe("Instance", func() {
dummies.CSMachine1.Spec.Template.ID = ""
dummies.CSMachine1.Spec.Offering.Name = offeringName
dummies.CSMachine1.Spec.Template.Name = templateName
dummies.CSMachine1.Spec.UncompressedUserData = pointer.Bool(true)
dummies.CSMachine1.Spec.UncompressedUserData = ptr.To(true)

vms.EXPECT().
GetVirtualMachinesMetricByID(*dummies.CSMachine1.Spec.InstanceID).
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/isolated_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta3"
Expand Down Expand Up @@ -929,7 +929,7 @@ var _ = Describe("Network", func() {
dummies.CSCluster.Spec.APIServerLoadBalancer.AllowedCIDRs = append(dummies.CSCluster.Spec.APIServerLoadBalancer.AllowedCIDRs,
"192.168.1.0/24",
"192.168.2.0/24")
dummies.CSCluster.Spec.APIServerLoadBalancer.Enabled = pointer.Bool(false)
dummies.CSCluster.Spec.APIServerLoadBalancer.Enabled = ptr.To(false)
dummies.CSISONet1.Status.PublicIPID = dummies.PublicIPID
dummies.CSISONet1.Status.APIServerLoadBalancer.IPAddressID = dummies.LoadBalancerIPID

Expand Down

0 comments on commit eccc027

Please sign in to comment.