diff --git a/.golangci.yml b/.golangci.yml index 99f0c5238a..334333a5f2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -81,7 +81,6 @@ linters: disable: - omitzero - fmtappendf - - newexpr revive: rules: # The following rules are recommended https://github.com/mgechev/revive#recommended-configuration diff --git a/designs/warmreplicas.md b/designs/warmreplicas.md index db14247916..de3dd60f2d 100644 --- a/designs/warmreplicas.md +++ b/designs/warmreplicas.md @@ -42,7 +42,7 @@ Warmup runnables are also stopped in parallel with non-leader runnables during s Controllers expose the option via: -- `ctrl.Options{Controller: config.Controller{EnableWarmup: ptr.To(true)}}` +- `ctrl.Options{Controller: config.Controller{EnableWarmup: new(true)}}` If both `EnableWarmup` and `NeedLeaderElection` are true, controller-runtime registers the controller as a warmup runnable. Calling `Warmup` launches the same event sources and cache sync logic as `Start`, but it does **not** start worker goroutines. Once the manager becomes leader, the controller’s normal `Start` simply spins up workers against the already-initialized queue. Enabling warmup on a controller that does not use leader election is a no-op, as the worker threads do not block on leader election being won. @@ -51,7 +51,7 @@ If both `EnableWarmup` and `NeedLeaderElection` are true, controller-runtime reg ```go mgr, err := ctrl.NewManager(cfg, ctrl.Options{ Controller: config.Controller{ - EnableWarmup: ptr.To(true), // make every controller warm up + EnableWarmup: new(true), // make every controller warm up }, }) if err != nil { @@ -61,7 +61,7 @@ if err != nil { builder.ControllerManagedBy(mgr). Named("slow-source"). WithOptions(controller.Options{ - EnableWarmup: ptr.To(true), // optional per-controller override + EnableWarmup: new(true), // optional per-controller override }). For(&examplev1.Example{}). Complete(reconciler) diff --git a/pkg/builder/controller_test.go b/pkg/builder/controller_test.go index 389f53e73c..023428d106 100644 --- a/pkg/builder/controller_test.go +++ b/pkg/builder/controller_test.go @@ -33,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/rest" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -711,7 +710,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager Name: deployName, Kind: "Deployment", APIVersion: "apps/v1", - Controller: ptr.To(true), + Controller: new(true), UID: dep.UID, }, }, diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 875f022a3e..2a3a0670d7 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -42,7 +42,6 @@ import ( kscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" kcache "k8s.io/client-go/tools/cache" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -148,10 +147,10 @@ var _ = Describe("Multi-Namespace Informer Cache", func() { var _ = Describe("Informer Cache without global DeepCopy", func() { CacheTest(cache.New, cache.Options{ - DefaultUnsafeDisableDeepCopy: ptr.To(true), + DefaultUnsafeDisableDeepCopy: new(true), }) NonBlockingGetTest(cache.New, cache.Options{ - DefaultUnsafeDisableDeepCopy: ptr.To(true), + DefaultUnsafeDisableDeepCopy: new(true), }) }) diff --git a/pkg/cache/defaulting_test.go b/pkg/cache/defaulting_test.go index b4b4dd030a..36cbb4eccb 100644 --- a/pkg/cache/defaulting_test.go +++ b/pkg/cache/defaulting_test.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -205,23 +204,23 @@ func TestDefaultOpts(t *testing.T) { name: "ByObject.UnsafeDisableDeepCopy gets defaulted from DefaultUnsafeDisableDeepCopy", in: Options{ ByObject: map[client.Object]ByObject{pod: {}}, - DefaultUnsafeDisableDeepCopy: ptr.To(true), + DefaultUnsafeDisableDeepCopy: new(true), }, verification: func(o Options) string { - expected := ptr.To(true) + expected := new(true) return cmp.Diff(expected, o.ByObject[pod].UnsafeDisableDeepCopy) }, }, { name: "ByObject.UnsafeDisableDeepCopy doesn't get defaulted when set", in: Options{ - ByObject: map[client.Object]ByObject{pod: {UnsafeDisableDeepCopy: ptr.To(false)}}, - DefaultUnsafeDisableDeepCopy: ptr.To(true), + ByObject: map[client.Object]ByObject{pod: {UnsafeDisableDeepCopy: new(false)}}, + DefaultUnsafeDisableDeepCopy: new(true), }, verification: func(o Options) string { - expected := ptr.To(false) + expected := new(false) return cmp.Diff(expected, o.ByObject[pod].UnsafeDisableDeepCopy) }, }, @@ -229,23 +228,23 @@ func TestDefaultOpts(t *testing.T) { name: "ByObject.EnableWatchBookmarks gets defaulted from DefaultEnableWatchBookmarks", in: Options{ ByObject: map[client.Object]ByObject{pod: {}}, - DefaultEnableWatchBookmarks: ptr.To(true), + DefaultEnableWatchBookmarks: new(true), }, verification: func(o Options) string { - expected := ptr.To(true) + expected := new(true) return cmp.Diff(expected, o.ByObject[pod].EnableWatchBookmarks) }, }, { name: "ByObject.EnableWatchBookmarks doesn't get defaulted when set", in: Options{ - ByObject: map[client.Object]ByObject{pod: {EnableWatchBookmarks: ptr.To(false)}}, - DefaultEnableWatchBookmarks: ptr.To(true), + ByObject: map[client.Object]ByObject{pod: {EnableWatchBookmarks: new(false)}}, + DefaultEnableWatchBookmarks: new(true), }, verification: func(o Options) string { - expected := ptr.To(false) + expected := new(false) return cmp.Diff(expected, o.ByObject[pod].EnableWatchBookmarks) }, }, @@ -253,23 +252,23 @@ func TestDefaultOpts(t *testing.T) { name: "ByObject.SyncPeriod gets defaulted from SyncPeriod", in: Options{ ByObject: map[client.Object]ByObject{pod: {}}, - SyncPeriod: ptr.To(5 * time.Minute), + SyncPeriod: new(5 * time.Minute), }, verification: func(o Options) string { - expected := ptr.To(5 * time.Minute) + expected := new(5 * time.Minute) return cmp.Diff(expected, o.ByObject[pod].SyncPeriod) }, }, { name: "ByObject.SyncPeriod doesn't get defaulted when set", in: Options{ - ByObject: map[client.Object]ByObject{pod: {SyncPeriod: ptr.To(1 * time.Minute)}}, - SyncPeriod: ptr.To(5 * time.Minute), + ByObject: map[client.Object]ByObject{pod: {SyncPeriod: new(1 * time.Minute)}}, + SyncPeriod: new(5 * time.Minute), }, verification: func(o Options) string { - expected := ptr.To(1 * time.Minute) + expected := new(1 * time.Minute) return cmp.Diff(expected, o.ByObject[pod].SyncPeriod) }, }, diff --git a/pkg/client/apiutil/restmapper.go b/pkg/client/apiutil/restmapper.go index 7a7a0d1145..ef5d0fee97 100644 --- a/pkg/client/apiutil/restmapper.go +++ b/pkg/client/apiutil/restmapper.go @@ -28,7 +28,6 @@ import ( "k8s.io/client-go/discovery" "k8s.io/client-go/rest" "k8s.io/client-go/restmapper" - "k8s.io/utils/ptr" ) // NewDynamicRESTMapper returns a dynamic RESTMapper for cfg. The dynamic @@ -197,7 +196,7 @@ func (m *mapper) addKnownGroupAndReload(groupName string, versions ...string) er } } if len(failedGroups) > 0 { - return ptr.To(ErrResourceDiscoveryFailed(failedGroups)) + return new(ErrResourceDiscoveryFailed(failedGroups)) } return nil } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 878927f467..f0b49fc035 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -516,7 +516,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC Context("with the DryRun option", func() { It("should not create a new object, global option", func(ctx SpecContext) { - cl, err := client.New(cfg, client.Options{DryRun: ptr.To(true)}) + cl, err := client.New(cfg, client.Options{DryRun: new(true)}) Expect(err).NotTo(HaveOccurred()) Expect(cl).NotTo(BeNil()) @@ -1038,7 +1038,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC Expect(cm.Data).To(BeComparableTo(obj.Data)) // Apply with ResourceVersion unset - obj.ResourceVersion = ptr.To("") + obj.ResourceVersion = new("") data = map[string]string{ "a-new-key": "a-new-value", } @@ -1149,7 +1149,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC By("Creating the eviction") eviction := &policyv1.Eviction{ - DeleteOptions: &metav1.DeleteOptions{GracePeriodSeconds: ptr.To(int64(0))}, + DeleteOptions: &metav1.DeleteOptions{GracePeriodSeconds: new(int64(0))}, } err = cl.SubResource("eviction").Create(ctx, pod, eviction, &client.SubResourceCreateOptions{}) Expect((err)).NotTo(HaveOccurred()) @@ -1665,7 +1665,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC deploymentAC, err := appsv1applyconfigurations.ExtractDeployment(dep, "foo") Expect(err).NotTo(HaveOccurred()) deploymentAC.WithStatus(&appsv1applyconfigurations.DeploymentStatusApplyConfiguration{ - Replicas: ptr.To(int32(1)), + Replicas: new(int32(1)), }) Expect(cl.Status().Apply(ctx, deploymentAC, client.FieldOwner("foo"))).To(Succeed()) diff --git a/pkg/client/dryrun_test.go b/pkg/client/dryrun_test.go index 35a9b63869..4ecd141553 100644 --- a/pkg/client/dryrun_test.go +++ b/pkg/client/dryrun_test.go @@ -28,7 +28,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" appsv1applyconfigurations "k8s.io/client-go/applyconfigurations/apps/v1" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -40,7 +39,7 @@ var _ = Describe("DryRunClient", func() { var ns = "default" getClient := func() client.Client { - cl, err := client.New(cfg, client.Options{DryRun: ptr.To(true)}) + cl, err := client.New(cfg, client.Options{DryRun: new(true)}) Expect(err).NotTo(HaveOccurred()) Expect(cl).NotTo(BeNil()) return cl @@ -266,7 +265,7 @@ var _ = Describe("DryRunClient", func() { deploymentAC, err := appsv1applyconfigurations.ExtractDeployment(dep, "test-owner") Expect(err).NotTo(HaveOccurred()) deploymentAC.WithStatus(&appsv1applyconfigurations.DeploymentStatusApplyConfiguration{ - Replicas: ptr.To(int32(99)), + Replicas: new(int32(99)), }) Expect(getClient().Status().Apply(ctx, deploymentAC, client.FieldOwner("test-owner"))).NotTo(HaveOccurred()) @@ -281,7 +280,7 @@ var _ = Describe("DryRunClient", func() { deploymentAC, err := appsv1applyconfigurations.ExtractDeployment(dep, "test-owner") Expect(err).NotTo(HaveOccurred()) deploymentAC.WithStatus(&appsv1applyconfigurations.DeploymentStatusApplyConfiguration{ - Replicas: ptr.To(int32(99)), + Replicas: new(int32(99)), }) opts := &client.SubResourceApplyOptions{ApplyOptions: client.ApplyOptions{DryRun: []string{"Bye", "Pippa"}}} diff --git a/pkg/client/fake/client.go b/pkg/client/fake/client.go index 2a07bd40b2..dd538ebd43 100644 --- a/pkg/client/fake/client.go +++ b/pkg/client/fake/client.go @@ -67,7 +67,6 @@ import ( clientgoapplyconfigurations "k8s.io/client-go/applyconfigurations" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/testing" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" @@ -1621,13 +1620,13 @@ func extractScale(obj client.Object) (*autoscalingv1.Scale, error) { func applyScale(obj client.Object, scale *autoscalingv1.Scale) error { switch obj := obj.(type) { case *appsv1.Deployment: - obj.Spec.Replicas = ptr.To(scale.Spec.Replicas) + obj.Spec.Replicas = new(scale.Spec.Replicas) case *appsv1.ReplicaSet: - obj.Spec.Replicas = ptr.To(scale.Spec.Replicas) + obj.Spec.Replicas = new(scale.Spec.Replicas) case *corev1.ReplicationController: - obj.Spec.Replicas = ptr.To(scale.Spec.Replicas) + obj.Spec.Replicas = new(scale.Spec.Replicas) case *appsv1.StatefulSet: - obj.Spec.Replicas = ptr.To(scale.Spec.Replicas) + obj.Spec.Replicas = new(scale.Spec.Replicas) default: // TODO: CRDs https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#scale-subresource return fmt.Errorf("unimplemented scale subresource for resource %T", obj) diff --git a/pkg/client/fake/client_test.go b/pkg/client/fake/client_test.go index db7d1c6279..d15efd03b5 100644 --- a/pkg/client/fake/client_test.go +++ b/pkg/client/fake/client_test.go @@ -50,7 +50,6 @@ import ( "k8s.io/client-go/kubernetes/fake" clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/testing" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/interceptor" @@ -1727,7 +1726,7 @@ var _ = Describe("Fake client", func() { objOriginal.APIVersion = actual.APIVersion objOriginal.Kind = actual.Kind objOriginal.ResourceVersion = actual.ResourceVersion - objOriginal.Spec.Replicas = ptr.To(int32(2)) + objOriginal.Spec.Replicas = new(int32(2)) Expect(cmp.Diff(objOriginal, actual)).To(BeEmpty()) }) @@ -2590,7 +2589,7 @@ var _ = Describe("Fake client", func() { Name: "foo", }, Spec: appsv1.DeploymentSpec{ - Replicas: ptr.To[int32](2), + Replicas: new(int32(2)), }, } cl := NewClientBuilder().Build() @@ -3011,7 +3010,7 @@ var _ = Describe("Fake client", func() { Expect(cm.Data).To(BeComparableTo(map[string]string{"other": "data"})) // Apply with ResourceVersion unset - obj.ResourceVersion = ptr.To("") + obj.ResourceVersion = new("") obj.Data = map[string]string{"another": "data"} Expect(cl.Apply(ctx, obj, &client.ApplyOptions{FieldManager: "test-manager"})).To(Succeed()) @@ -3193,7 +3192,7 @@ var _ = Describe("Fake client", func() { Expect(cl.Apply(ctx, obj, client.FieldOwner("foo"))).NotTo(HaveOccurred()) // Ideally we should only test for it to not be empty, realistically we will // break ppl if we ever start setting a different value. - Expect(obj.ResourceVersion).To(BeEquivalentTo(ptr.To("1"))) + Expect(obj.ResourceVersion).To(BeEquivalentTo(new("1"))) }) It("ignores a passed resourceVersion on SSA create", func(ctx SpecContext) { @@ -3204,7 +3203,7 @@ var _ = Describe("Fake client", func() { cl := NewClientBuilder().Build() Expect(cl.Apply(ctx, obj, client.FieldOwner("foo"))).NotTo(HaveOccurred()) - Expect(obj.ResourceVersion).To(BeEquivalentTo(ptr.To("1"))) + Expect(obj.ResourceVersion).To(BeEquivalentTo(new("1"))) }) It("allows to set deletionTimestamp on an object during SSA create", func(ctx SpecContext) { @@ -3331,7 +3330,7 @@ var _ = Describe("Fake client", func() { Name: "foo", }, Spec: appsv1.DeploymentSpec{ - Replicas: ptr.To[int32](2), + Replicas: new(int32(2)), }, }, &appsv1.ReplicaSet{ @@ -3339,7 +3338,7 @@ var _ = Describe("Fake client", func() { Name: "foo", }, Spec: appsv1.ReplicaSetSpec{ - Replicas: ptr.To[int32](2), + Replicas: new(int32(2)), }, }, &corev1.ReplicationController{ @@ -3347,7 +3346,7 @@ var _ = Describe("Fake client", func() { Name: "foo", }, Spec: corev1.ReplicationControllerSpec{ - Replicas: ptr.To[int32](2), + Replicas: new(int32(2)), }, }, &appsv1.StatefulSet{ @@ -3355,7 +3354,7 @@ var _ = Describe("Fake client", func() { Name: "foo", }, Spec: appsv1.StatefulSetSpec{ - Replicas: ptr.To[int32](2), + Replicas: new(int32(2)), }, }, } @@ -3392,16 +3391,16 @@ var _ = Describe("Fake client", func() { switch expected := objExpected.(type) { case *appsv1.Deployment: expected.ResourceVersion = objActual.GetResourceVersion() - expected.Spec.Replicas = ptr.To(int32(3)) + expected.Spec.Replicas = new(int32(3)) case *appsv1.ReplicaSet: expected.ResourceVersion = objActual.GetResourceVersion() - expected.Spec.Replicas = ptr.To(int32(3)) + expected.Spec.Replicas = new(int32(3)) case *corev1.ReplicationController: expected.ResourceVersion = objActual.GetResourceVersion() - expected.Spec.Replicas = ptr.To(int32(3)) + expected.Spec.Replicas = new(int32(3)) case *appsv1.StatefulSet: expected.ResourceVersion = objActual.GetResourceVersion() - expected.Spec.Replicas = ptr.To(int32(3)) + expected.Spec.Replicas = new(int32(3)) } Expect(cmp.Diff(objExpected, objActual)).To(BeEmpty()) diff --git a/pkg/client/namespaced_client_test.go b/pkg/client/namespaced_client_test.go index d7be6eeee6..d3712ca501 100644 --- a/pkg/client/namespaced_client_test.go +++ b/pkg/client/namespaced_client_test.go @@ -37,7 +37,6 @@ import ( corev1applyconfigurations "k8s.io/client-go/applyconfigurations/core/v1" metav1applyconfigurations "k8s.io/client-go/applyconfigurations/meta/v1" rbacv1applyconfigurations "k8s.io/client-go/applyconfigurations/rbac/v1" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -638,7 +637,7 @@ var _ = Describe("NamespacedClient", func() { deploymentAC, err := appsv1applyconfigurations.ExtractDeployment(dep, "test-owner") Expect(err).NotTo(HaveOccurred()) deploymentAC.WithStatus(&appsv1applyconfigurations.DeploymentStatusApplyConfiguration{ - Replicas: ptr.To(int32(99)), + Replicas: new(int32(99)), }) Expect(getClient().SubResource("status").Apply(ctx, deploymentAC, client.FieldOwner("test-owner"))).To(Succeed()) @@ -653,7 +652,7 @@ var _ = Describe("NamespacedClient", func() { It("should set namespace on ApplyConfiguration when applying via SubResource", func(ctx SpecContext) { deploymentAC := appsv1applyconfigurations.Deployment(dep.Name, "") deploymentAC.WithStatus(&appsv1applyconfigurations.DeploymentStatusApplyConfiguration{ - Replicas: ptr.To(int32(50)), + Replicas: new(int32(50)), }) Expect(getClient().SubResource("status").Apply(ctx, deploymentAC, client.FieldOwner("test-owner"))).To(Succeed()) @@ -668,7 +667,7 @@ var _ = Describe("NamespacedClient", func() { It("should fail when applying via SubResource with conflicting namespace", func(ctx SpecContext) { deploymentAC := appsv1applyconfigurations.Deployment(dep.Name, "different-namespace") deploymentAC.WithStatus(&appsv1applyconfigurations.DeploymentStatusApplyConfiguration{ - Replicas: ptr.To(int32(25)), + Replicas: new(int32(25)), }) err := getClient().SubResource("status").Apply(ctx, deploymentAC, client.FieldOwner("test-owner")) diff --git a/pkg/client/options.go b/pkg/client/options.go index a6b921171a..c5bd9f0b8c 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -21,7 +21,6 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" - "k8s.io/utils/ptr" ) // {{{ "Functional" Option Interfaces @@ -741,12 +740,12 @@ type UnsafeDisableDeepCopyOption bool // ApplyToGet applies this configuration to the given an Get options. func (d UnsafeDisableDeepCopyOption) ApplyToGet(opts *GetOptions) { - opts.UnsafeDisableDeepCopy = ptr.To(bool(d)) + opts.UnsafeDisableDeepCopy = new(bool(d)) } // ApplyToList applies this configuration to the given an List options. func (d UnsafeDisableDeepCopyOption) ApplyToList(opts *ListOptions) { - opts.UnsafeDisableDeepCopy = ptr.To(bool(d)) + opts.UnsafeDisableDeepCopy = new(bool(d)) } // UnsafeDisableDeepCopy indicates not to deep copy objects during list objects. @@ -953,19 +952,19 @@ var ForceOwnership = forceOwnership{} type forceOwnership struct{} func (forceOwnership) ApplyToPatch(opts *PatchOptions) { - opts.Force = ptr.To(true) + opts.Force = new(true) } func (forceOwnership) ApplyToSubResourcePatch(opts *SubResourcePatchOptions) { - opts.Force = ptr.To(true) + opts.Force = new(true) } func (forceOwnership) ApplyToApply(opts *ApplyOptions) { - opts.Force = ptr.To(true) + opts.Force = new(true) } func (forceOwnership) ApplyToSubResourceApply(opts *SubResourceApplyOptions) { - opts.Force = ptr.To(true) + opts.Force = new(true) } // }}} diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index 88ef4a1839..3c1fc32666 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -23,7 +23,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -143,7 +142,7 @@ var _ = Describe("ApplyOptions", func() { Expect(newApplyOpts).To(Equal(o)) }) It("Should set Force", func() { - o := &client.ApplyOptions{Force: ptr.To(true)} + o := &client.ApplyOptions{Force: new(true)} newApplyOpts := &client.ApplyOptions{} o.ApplyToApply(newApplyOpts) Expect(newApplyOpts).To(Equal(o)) @@ -185,7 +184,7 @@ var _ = Describe("CreateOptions", func() { var _ = Describe("DeleteOptions", func() { It("Should set GracePeriodSeconds", func() { - o := &client.DeleteOptions{GracePeriodSeconds: ptr.To(int64(42))} + o := &client.DeleteOptions{GracePeriodSeconds: new(int64(42))} newDeleteOpts := &client.DeleteOptions{} o.ApplyToDelete(newDeleteOpts) Expect(newDeleteOpts).To(Equal(o)) @@ -258,7 +257,7 @@ var _ = Describe("PatchOptions", func() { Expect(newPatchOpts).To(Equal(o)) }) It("Should set Force", func() { - o := &client.PatchOptions{Force: ptr.To(true)} + o := &client.PatchOptions{Force: new(true)} newPatchOpts := &client.PatchOptions{} o.ApplyToPatch(newPatchOpts) Expect(newPatchOpts).To(Equal(o)) @@ -291,7 +290,7 @@ var _ = Describe("DeleteAllOfOptions", func() { Expect(newDeleteAllOfOpts).To(Equal(o)) }) It("Should set DeleleteOptions", func() { - o := &client.DeleteAllOfOptions{DeleteOptions: client.DeleteOptions{GracePeriodSeconds: ptr.To(int64(44))}} + o := &client.DeleteAllOfOptions{DeleteOptions: client.DeleteOptions{GracePeriodSeconds: new(int64(44))}} newDeleteAllOfOpts := &client.DeleteAllOfOptions{} o.ApplyToDeleteAllOf(newDeleteAllOfOpts) Expect(newDeleteAllOfOpts).To(Equal(o)) diff --git a/pkg/controller/controller_integration_test.go b/pkg/controller/controller_integration_test.go index e09813eee2..7b3af49463 100644 --- a/pkg/controller/controller_integration_test.go +++ b/pkg/controller/controller_integration_test.go @@ -26,7 +26,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -72,7 +71,7 @@ var _ = Describe("controller", func() { reconciled <- request return reconcile.Result{}, nil }), - EnableWarmup: ptr.To(enableWarmup), + EnableWarmup: new(enableWarmup), }, ) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 0a250bd0a4..faafecc459 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -26,7 +26,6 @@ import ( corev1 "k8s.io/api/core/v1" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/config" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -79,7 +78,7 @@ var _ = Describe("controller.Controller", func() { It("should return an error if two controllers are registered with the same name and SkipNameValidation is set to false on the manager", func() { m, err := manager.New(cfg, manager.Options{ Controller: config.Controller{ - SkipNameValidation: ptr.To(false), + SkipNameValidation: new(false), }, }) Expect(err).NotTo(HaveOccurred()) @@ -97,7 +96,7 @@ var _ = Describe("controller.Controller", func() { It("should not return an error if two controllers are registered with the same name and SkipNameValidation is set on the manager", func() { m, err := manager.New(cfg, manager.Options{ Controller: config.Controller{ - SkipNameValidation: ptr.To(true), + SkipNameValidation: new(true), }, }) Expect(err).NotTo(HaveOccurred()) @@ -119,7 +118,7 @@ var _ = Describe("controller.Controller", func() { Expect(err).NotTo(HaveOccurred()) Expect(c1).ToNot(BeNil()) - c2, err := controller.New("c6", m, controller.Options{Reconciler: rec, SkipNameValidation: ptr.To(true)}) + c2, err := controller.New("c6", m, controller.Options{Reconciler: rec, SkipNameValidation: new(true)}) Expect(err).NotTo(HaveOccurred()) Expect(c2).ToNot(BeNil()) }) @@ -241,7 +240,7 @@ var _ = Describe("controller.Controller", func() { }) It("should default RecoverPanic from the manager", func() { - m, err := manager.New(cfg, manager.Options{Controller: config.Controller{RecoverPanic: ptr.To(true)}}) + m, err := manager.New(cfg, manager.Options{Controller: config.Controller{RecoverPanic: new(true)}}) Expect(err).NotTo(HaveOccurred()) c, err := controller.New("new-controller-4", m, controller.Options{ @@ -257,11 +256,11 @@ var _ = Describe("controller.Controller", func() { }) It("should not override RecoverPanic on the controller", func() { - m, err := manager.New(cfg, manager.Options{Controller: config.Controller{RecoverPanic: ptr.To(true)}}) + m, err := manager.New(cfg, manager.Options{Controller: config.Controller{RecoverPanic: new(true)}}) Expect(err).NotTo(HaveOccurred()) c, err := controller.New("new-controller", m, controller.Options{ - RecoverPanic: ptr.To(false), + RecoverPanic: new(false), Reconciler: reconcile.Func(nil), }) Expect(err).NotTo(HaveOccurred()) @@ -274,7 +273,7 @@ var _ = Describe("controller.Controller", func() { }) It("should default NeedLeaderElection from the manager", func() { - m, err := manager.New(cfg, manager.Options{Controller: config.Controller{NeedLeaderElection: ptr.To(true)}}) + m, err := manager.New(cfg, manager.Options{Controller: config.Controller{NeedLeaderElection: new(true)}}) Expect(err).NotTo(HaveOccurred()) c, err := controller.New("new-controller-5", m, controller.Options{ @@ -289,11 +288,11 @@ var _ = Describe("controller.Controller", func() { }) It("should not override NeedLeaderElection on the controller", func() { - m, err := manager.New(cfg, manager.Options{Controller: config.Controller{NeedLeaderElection: ptr.To(true)}}) + m, err := manager.New(cfg, manager.Options{Controller: config.Controller{NeedLeaderElection: new(true)}}) Expect(err).NotTo(HaveOccurred()) c, err := controller.New("new-controller-6", m, controller.Options{ - NeedLeaderElection: ptr.To(false), + NeedLeaderElection: new(false), Reconciler: reconcile.Func(nil), }) Expect(err).NotTo(HaveOccurred()) @@ -416,7 +415,7 @@ var _ = Describe("controller.Controller", func() { Expect(err).NotTo(HaveOccurred()) c, err := controller.New("new-controller-14", m, controller.Options{ - NeedLeaderElection: ptr.To(false), + NeedLeaderElection: new(false), Reconciler: rec, }) Expect(err).NotTo(HaveOccurred()) @@ -465,7 +464,7 @@ var _ = Describe("controller.Controller", func() { c, err := controller.New("new-controller-17", m, controller.Options{ Reconciler: rec, - UsePriorityQueue: ptr.To(false), + UsePriorityQueue: new(false), }) Expect(err).NotTo(HaveOccurred()) @@ -484,7 +483,7 @@ var _ = Describe("controller.Controller", func() { // Test with EnableWarmup set to true ctrlWithWarmup, err := controller.New("warmup-enabled-ctrl", m, controller.Options{ Reconciler: reconcile.Func(nil), - EnableWarmup: ptr.To(true), + EnableWarmup: new(true), }) Expect(err).NotTo(HaveOccurred()) @@ -495,7 +494,7 @@ var _ = Describe("controller.Controller", func() { // Test with EnableWarmup set to false ctrlWithoutWarmup, err := controller.New("warmup-disabled-ctrl", m, controller.Options{ Reconciler: reconcile.Func(nil), - EnableWarmup: ptr.To(false), + EnableWarmup: new(false), }) Expect(err).NotTo(HaveOccurred()) @@ -518,7 +517,7 @@ var _ = Describe("controller.Controller", func() { // Test with manager default setting EnableWarmup to true managerWithWarmup, err := manager.New(cfg, manager.Options{ Controller: config.Controller{ - EnableWarmup: ptr.To(true), + EnableWarmup: new(true), }, }) Expect(err).NotTo(HaveOccurred()) @@ -534,7 +533,7 @@ var _ = Describe("controller.Controller", func() { // Test that explicit controller setting overrides manager setting ctrlOverridingWarmup, err := controller.New("override-warmup-disabled", managerWithWarmup, controller.Options{ Reconciler: reconcile.Func(nil), - EnableWarmup: ptr.To(false), + EnableWarmup: new(false), }) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/controller/controllerutil/controllerutil.go b/pkg/controller/controllerutil/controllerutil.go index 0f12b934ee..a9a2a95a06 100644 --- a/pkg/controller/controllerutil/controllerutil.go +++ b/pkg/controller/controllerutil/controllerutil.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" @@ -88,8 +87,8 @@ func SetControllerReference(owner, controlled metav1.Object, scheme *runtime.Sch Kind: gvk.Kind, Name: owner.GetName(), UID: owner.GetUID(), - BlockOwnerDeletion: ptr.To(true), - Controller: ptr.To(true), + BlockOwnerDeletion: new(true), + Controller: new(true), } for _, opt := range opts { opt(&ref) diff --git a/pkg/controller/controllerutil/controllerutil_test.go b/pkg/controller/controllerutil/controllerutil_test.go index a716667f6a..28fc86a01b 100644 --- a/pkg/controller/controllerutil/controllerutil_test.go +++ b/pkg/controller/controllerutil/controllerutil_test.go @@ -30,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) @@ -786,7 +785,7 @@ var _ = Describe("Controllerutil", func() { assertLocalDeployWasUpdated(ctx, nil) op, err = controllerutil.CreateOrPatch(ctx, c, deploy, func() error { - deploy.Spec.Replicas = ptr.To(int32(5)) + deploy.Spec.Replicas = new(int32(5)) deploy.Status.Conditions = []appsv1.DeploymentCondition{{ Type: appsv1.DeploymentProgressing, Status: corev1.ConditionTrue, diff --git a/pkg/controller/priorityqueue/priorityqueue.go b/pkg/controller/priorityqueue/priorityqueue.go index c534a0b1c5..69ac25083b 100644 --- a/pkg/controller/priorityqueue/priorityqueue.go +++ b/pkg/controller/priorityqueue/priorityqueue.go @@ -213,7 +213,7 @@ func (w *priorityqueue[T]) lockedAddWithOpts(o AddOpts, items ...T) { var readyAt *time.Time if after > 0 { - readyAt = ptr.To(w.now().Add(after)) + readyAt = new(w.now().Add(after)) w.metrics.retry() } if _, ok := w.items[key]; !ok { diff --git a/pkg/controller/priorityqueue/priorityqueue_test.go b/pkg/controller/priorityqueue/priorityqueue_test.go index 89c3216fbf..b46a715c62 100644 --- a/pkg/controller/priorityqueue/priorityqueue_test.go +++ b/pkg/controller/priorityqueue/priorityqueue_test.go @@ -132,8 +132,8 @@ var _ = Describe("Controllerworkqueue", func() { q, metrics := newQueue() defer q.ShutDown() - q.AddWithOpts(AddOpts{Priority: ptr.To(1)}, "foo") - q.AddWithOpts(AddOpts{Priority: ptr.To(2)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(1)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(2)}, "foo") item, priority, _ := q.GetWithPriority() Expect(item).To(Equal("foo")) @@ -149,8 +149,8 @@ var _ = Describe("Controllerworkqueue", func() { q, metrics := newQueue() defer q.ShutDown() - q.AddWithOpts(AddOpts{Priority: ptr.To(2)}, "foo") - q.AddWithOpts(AddOpts{Priority: ptr.To(1)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(2)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(1)}, "foo") item, priority, _ := q.GetWithPriority() Expect(item).To(Equal("foo")) @@ -169,7 +169,7 @@ var _ = Describe("Controllerworkqueue", func() { q.AddWithOpts(AddOpts{}, "foo") q.AddWithOpts(AddOpts{}, "bar") q.AddWithOpts(AddOpts{}, "baz") - q.AddWithOpts(AddOpts{Priority: ptr.To(1)}, "baz") + q.AddWithOpts(AddOpts{Priority: new(1)}, "baz") item, priority, _ := q.GetWithPriority() Expect(item).To(Equal("baz")) @@ -296,13 +296,13 @@ var _ = Describe("Controllerworkqueue", func() { q, metrics := newQueue() defer q.ShutDown() - q.AddWithOpts(AddOpts{After: time.Hour, Priority: ptr.To(0)}, "foo") + q.AddWithOpts(AddOpts{After: time.Hour, Priority: new(0)}, "foo") Expect(q.Len()).To(Equal(0)) metrics.mu.Lock() Expect(metrics.depth["test"]).To(Equal(map[int]int{})) metrics.mu.Unlock() - q.AddWithOpts(AddOpts{Priority: ptr.To(1)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(1)}, "foo") Expect(q.Len()).To(Equal(1)) metrics.mu.Lock() @@ -325,9 +325,9 @@ var _ = Describe("Controllerworkqueue", func() { q, _ := newQueue() defer q.ShutDown() - q.AddWithOpts(AddOpts{Priority: ptr.To(0)}, "foo") - q.AddWithOpts(AddOpts{Priority: ptr.To(1)}, "bar") - q.AddWithOpts(AddOpts{Priority: ptr.To(1)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(0)}, "foo") + q.AddWithOpts(AddOpts{Priority: new(1)}, "bar") + q.AddWithOpts(AddOpts{Priority: new(1)}, "foo") Expect(q.Len()).To(Equal(2)) item, priority, _ := q.GetWithPriority() diff --git a/pkg/envtest/crd.go b/pkg/envtest/crd.go index 8ed2224cfe..da9b4fb67d 100644 --- a/pkg/envtest/crd.go +++ b/pkg/envtest/crd.go @@ -38,7 +38,6 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/util/retry" - "k8s.io/utils/ptr" "sigs.k8s.io/yaml" "sigs.k8s.io/controller-runtime/pkg/client" @@ -362,7 +361,7 @@ func modifyConversionWebhooks(crds []*apiextensionsv1.CustomResourceDefinition, if err != nil { return err } - url := ptr.To(fmt.Sprintf("https://%s/convert", hostPort)) + url := new(fmt.Sprintf("https://%s/convert", hostPort)) for i := range crds { // Continue if we're preserving unknown fields. diff --git a/pkg/envtest/komega/default.go b/pkg/envtest/komega/default.go index dad1f551ae..b4b5ef9cae 100644 --- a/pkg/envtest/komega/default.go +++ b/pkg/envtest/komega/default.go @@ -81,7 +81,7 @@ func UpdateStatus(obj client.Object, f func(), opts ...client.SubResourceUpdateO // It can be used with gomega.Eventually() like this: // // deployment := appsv1.Deployment{ ... } -// gomega.Eventually(k.Object(&deployment)).Should(HaveField("Spec.Replicas", gomega.Equal(ptr.To(3)))) +// gomega.Eventually(k.Object(&deployment)).Should(HaveField("Spec.Replicas", gomega.Equal(new(3)))) // // By calling the returned function directly it can also be used as gomega.Expect(k.Object(...)()).To(...) func Object(obj client.Object) func() (client.Object, error) { diff --git a/pkg/envtest/komega/default_test.go b/pkg/envtest/komega/default_test.go index 1a1de72cf3..1e663b9d38 100644 --- a/pkg/envtest/komega/default_test.go +++ b/pkg/envtest/komega/default_test.go @@ -6,7 +6,6 @@ import ( . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" ) func TestDefaultGet(t *testing.T) { @@ -95,7 +94,7 @@ func TestDefaultObject(t *testing.T) { } g.Eventually(Object(&fetched)).Should(And( Not(BeNil()), - HaveField("Spec.Replicas", Equal(ptr.To(int32(5)))), + HaveField("Spec.Replicas", Equal(new(int32(5)))), )) } @@ -110,7 +109,7 @@ func TestDefaultObjectList(t *testing.T) { Not(BeNil()), HaveField("Items", And( HaveLen(1), - ContainElement(HaveField("Spec.Replicas", Equal(ptr.To(int32(5))))), + ContainElement(HaveField("Spec.Replicas", Equal(new(int32(5))))), )), )) } diff --git a/pkg/envtest/komega/interfaces.go b/pkg/envtest/komega/interfaces.go index b412e5c1bf..94d9c5a853 100644 --- a/pkg/envtest/komega/interfaces.go +++ b/pkg/envtest/komega/interfaces.go @@ -60,7 +60,7 @@ type Komega interface { // Object returns a function that fetches a resource and returns the object. // It can be used with gomega.Eventually() like this: // deployment := appsv1.Deployment{ ... } - // gomega.Eventually(k.Object(&deployment)).To(HaveField("Spec.Replicas", gomega.Equal(ptr.To(int32(3))))) + // gomega.Eventually(k.Object(&deployment)).To(HaveField("Spec.Replicas", gomega.Equal(new(int32(3))))) // By calling the returned function directly it can also be used as gomega.Expect(k.Object(...)()).To(...) Object(client.Object) func() (client.Object, error) diff --git a/pkg/envtest/komega/komega_test.go b/pkg/envtest/komega/komega_test.go index 8867ac239a..9adf0158b6 100644 --- a/pkg/envtest/komega/komega_test.go +++ b/pkg/envtest/komega/komega_test.go @@ -7,7 +7,6 @@ import ( . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -20,7 +19,7 @@ func exampleDeployment() *appsv1.Deployment { Name: "test", }, Spec: appsv1.DeploymentSpec{ - Replicas: ptr.To(int32(5)), + Replicas: new(int32(5)), }, } } @@ -117,7 +116,7 @@ func TestObject(t *testing.T) { } g.Eventually(k.Object(&fetched)).Should(And( Not(BeNil()), - HaveField("Spec.Replicas", Equal(ptr.To(int32(5)))), + HaveField("Spec.Replicas", Equal(new(int32(5)))), )) } @@ -132,7 +131,7 @@ func TestObjectList(t *testing.T) { Not(BeNil()), HaveField("Items", And( HaveLen(1), - ContainElement(HaveField("Spec.Replicas", Equal(ptr.To(int32(5))))), + ContainElement(HaveField("Spec.Replicas", Equal(new(int32(5))))), )), )) } diff --git a/pkg/handler/enqueue_mapped.go b/pkg/handler/enqueue_mapped.go index 62d6728151..6f8dde7d15 100644 --- a/pkg/handler/enqueue_mapped.go +++ b/pkg/handler/enqueue_mapped.go @@ -20,7 +20,6 @@ import ( "context" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue" "sigs.k8s.io/controller-runtime/pkg/event" @@ -142,7 +141,7 @@ func (e *enqueueRequestsFromMapFunc[object, request]) mapAndEnqueue( if !ok { if lowPriority { q.(priorityqueue.PriorityQueue[request]).AddWithOpts(priorityqueue.AddOpts{ - Priority: ptr.To(LowPriority), + Priority: new(LowPriority), }, req) } else { q.Add(req) diff --git a/pkg/handler/eventhandler.go b/pkg/handler/eventhandler.go index 88510d29ed..582547eb86 100644 --- a/pkg/handler/eventhandler.go +++ b/pkg/handler/eventhandler.go @@ -22,7 +22,6 @@ import ( "time" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue" "sigs.k8s.io/controller-runtime/pkg/event" @@ -135,7 +134,7 @@ func (h TypedFuncs[object, request]) Create(ctx context.Context, e event.TypedCr PriorityQueue: q.(priorityqueue.PriorityQueue[request]), } if e.IsInInitialList { - wq.priority = ptr.To(LowPriority) + wq.priority = new(LowPriority) } h.CreateFunc(ctx, e, wq) } @@ -162,7 +161,7 @@ func (h TypedFuncs[object, request]) Update(ctx context.Context, e event.TypedUp PriorityQueue: q.(priorityqueue.PriorityQueue[request]), } if any(e.ObjectOld).(client.Object).GetResourceVersion() == any(e.ObjectNew).(client.Object).GetResourceVersion() { - wq.priority = ptr.To(LowPriority) + wq.priority = new(LowPriority) } h.UpdateFunc(ctx, e, wq) } @@ -225,7 +224,7 @@ func addToQueueCreate[T client.Object, request comparable](q workqueue.TypedRate var priority *int if evt.IsInInitialList { - priority = ptr.To(LowPriority) + priority = new(LowPriority) } priorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: priority}, item) } @@ -241,7 +240,7 @@ func addToQueueUpdate[T client.Object, request comparable](q workqueue.TypedRate var priority *int if evt.ObjectOld.GetResourceVersion() == evt.ObjectNew.GetResourceVersion() { - priority = ptr.To(LowPriority) + priority = new(LowPriority) } priorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: priority}, item) } diff --git a/pkg/handler/eventhandler_test.go b/pkg/handler/eventhandler_test.go index 2023156146..d5f6161583 100644 --- a/pkg/handler/eventhandler_test.go +++ b/pkg/handler/eventhandler_test.go @@ -31,7 +31,6 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" "sigs.k8s.io/controller-runtime/pkg/controller/controllertest" @@ -508,7 +507,7 @@ var _ = Describe("Eventhandler", func() { Name: "foo2-parent", Kind: "ReplicaSet", APIVersion: "apps/v1", - Controller: ptr.To(true), + Controller: new(true), }, { Name: "foo3-parent", @@ -519,7 +518,7 @@ var _ = Describe("Eventhandler", func() { Name: "foo4-parent", Kind: "ReplicaSet", APIVersion: "apps/v1", - Controller: ptr.To(true), + Controller: new(true), }, { Name: "foo5-parent", @@ -910,7 +909,7 @@ var _ = Describe("Eventhandler", func() { handler.TypedFuncs[client.Object, reconcile.Request]{ CreateFunc: func(ctx context.Context, tce event.TypedCreateEvent[client.Object], wq workqueue.TypedRateLimitingInterface[reconcile.Request]) { if pq, isPQ := wq.(priorityqueue.PriorityQueue[reconcile.Request]); isPQ { - pq.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(100)}, reconcile.Request{NamespacedName: types.NamespacedName{ + pq.AddWithOpts(priorityqueue.AddOpts{Priority: new(100)}, reconcile.Request{NamespacedName: types.NamespacedName{ Namespace: tce.Object.GetNamespace(), Name: tce.Object.GetName(), }}) @@ -923,7 +922,7 @@ var _ = Describe("Eventhandler", func() { }, UpdateFunc: func(ctx context.Context, tue event.TypedUpdateEvent[client.Object], wq workqueue.TypedRateLimitingInterface[reconcile.Request]) { if pq, isPQ := wq.(priorityqueue.PriorityQueue[reconcile.Request]); isPQ { - pq.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(100)}, reconcile.Request{NamespacedName: types.NamespacedName{ + pq.AddWithOpts(priorityqueue.AddOpts{Priority: new(100)}, reconcile.Request{NamespacedName: types.NamespacedName{ Namespace: tue.ObjectNew.GetNamespace(), Name: tue.ObjectNew.GetName(), }}) @@ -969,7 +968,7 @@ var _ = Describe("Eventhandler", func() { } Expect(actualOpts).To(Equal(priorityqueue.AddOpts{ - Priority: ptr.To(expected), + Priority: new(expected), After: test.after, RateLimited: test.ratelimited, })) @@ -1039,7 +1038,7 @@ var _ = Describe("Eventhandler", func() { expectedPriority = test.overridePriority } - Expect(actualOpts).To(Equal(priorityqueue.AddOpts{After: test.after, RateLimited: test.ratelimited, Priority: ptr.To(expectedPriority)})) + Expect(actualOpts).To(Equal(priorityqueue.AddOpts{After: test.after, RateLimited: test.ratelimited, Priority: new(expectedPriority)})) Expect(actualRequests).To(Equal([]reconcile.Request{{NamespacedName: types.NamespacedName{Name: "my-pod"}}})) }) diff --git a/pkg/internal/controller/controller.go b/pkg/internal/controller/controller.go index f2638b9d9b..bf81da39b6 100644 --- a/pkg/internal/controller/controller.go +++ b/pkg/internal/controller/controller.go @@ -30,7 +30,6 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue" ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics" @@ -485,7 +484,7 @@ func (c *Controller[request]) reconcileHandler(ctx context.Context, req request, if errors.Is(err, reconcile.TerminalError(nil)) { ctrlmetrics.TerminalReconcileErrors.WithLabelValues(c.Name).Inc() } else { - c.Queue.AddWithOpts(priorityqueue.AddOpts{RateLimited: true, Priority: ptr.To(priority)}, req) + c.Queue.AddWithOpts(priorityqueue.AddOpts{RateLimited: true, Priority: new(priority)}, req) } ctrlmetrics.ReconcileErrors.WithLabelValues(c.Name).Inc() ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, labelError).Inc() @@ -500,11 +499,11 @@ func (c *Controller[request]) reconcileHandler(ctx context.Context, req request, // We need to drive to stable reconcile loops before queuing due // to result.RequestAfter c.Queue.Forget(req) - c.Queue.AddWithOpts(priorityqueue.AddOpts{After: result.RequeueAfter, Priority: ptr.To(priority)}, req) + c.Queue.AddWithOpts(priorityqueue.AddOpts{After: result.RequeueAfter, Priority: new(priority)}, req) ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, labelRequeueAfter).Inc() case result.Requeue: //nolint: staticcheck // We have to handle it until it is removed log.V(5).Info("Reconcile done, requeueing") - c.Queue.AddWithOpts(priorityqueue.AddOpts{RateLimited: true, Priority: ptr.To(priority)}, req) + c.Queue.AddWithOpts(priorityqueue.AddOpts{RateLimited: true, Priority: new(priority)}, req) ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, labelRequeue).Inc() default: log.V(5).Info("Reconcile successful") diff --git a/pkg/internal/controller/controller_test.go b/pkg/internal/controller/controller_test.go index d54fcf7640..7803426983 100644 --- a/pkg/internal/controller/controller_test.go +++ b/pkg/internal/controller/controller_test.go @@ -38,7 +38,6 @@ import ( "k8s.io/apimachinery/pkg/types" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/cache/informertest" "sigs.k8s.io/controller-runtime/pkg/client" @@ -107,7 +106,7 @@ var _ = Describe("controller", func() { defer func() { Expect(recover()).ShouldNot(BeNil()) }() - ctrl.RecoverPanic = ptr.To(false) + ctrl.RecoverPanic = new(false) ctrl.Do = reconcile.Func(func(context.Context, reconcile.Request) (reconcile.Result, error) { var res *reconcile.Result return *res, nil @@ -135,7 +134,7 @@ var _ = Describe("controller", func() { defer func() { Expect(recover()).To(BeNil()) }() - ctrl.RecoverPanic = ptr.To(true) + ctrl.RecoverPanic = new(true) ctrl.Do = reconcile.Func(func(context.Context, reconcile.Request) (reconcile.Result, error) { var res *reconcile.Result return *res, nil @@ -637,7 +636,7 @@ var _ = Describe("controller", func() { It("should return an error if a source fails to sync", func(ctx SpecContext) { ctrl.startWatches = []source.TypedSource[reconcile.Request]{ - source.Kind(&informertest.FakeInformers{Synced: ptr.To(false)}, &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}), + source.Kind(&informertest.FakeInformers{Synced: new(false)}, &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}), } ctrl.Name = "test-controller" ctrl.CacheSyncTimeout = 5 * time.Second @@ -650,7 +649,7 @@ var _ = Describe("controller", func() { It("should not return an error when sources start and sync successfully", func(ctx SpecContext) { // Create a source that starts and syncs successfully ctrl.startWatches = []source.TypedSource[reconcile.Request]{ - source.Kind(&informertest.FakeInformers{Synced: ptr.To(true)}, &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}), + source.Kind(&informertest.FakeInformers{Synced: new(true)}, &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}), } ctrl.Name = "test-controller" ctrl.CacheSyncTimeout = 5 * time.Second @@ -940,7 +939,7 @@ var _ = Describe("controller", func() { Expect(ctrl.Start(ctx)).NotTo(HaveOccurred()) }() - q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(10)}, request) + q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: new(10)}, request) By("Invoking Reconciler which will request a requeue") fakeReconcile.AddResult(reconcile.Result{Requeue: true}, nil) @@ -952,7 +951,7 @@ var _ = Describe("controller", func() { }).Should(Equal([]priorityQueueAddition{{ AddOpts: priorityqueue.AddOpts{ RateLimited: true, - Priority: ptr.To(10), + Priority: new(10), }, items: []reconcile.Request{request}, }})) @@ -969,10 +968,10 @@ var _ = Describe("controller", func() { Expect(ctrl.Start(ctx)).NotTo(HaveOccurred()) }() - q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(10)}, request) + q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: new(10)}, request) By("Invoking Reconciler which will request a requeue") - fakeReconcile.AddResult(reconcile.Result{Requeue: true, Priority: ptr.To(99)}, nil) + fakeReconcile.AddResult(reconcile.Result{Requeue: true, Priority: new(99)}, nil) Expect(<-reconciled).To(Equal(request)) Eventually(func() []priorityQueueAddition { q.lock.Lock() @@ -981,7 +980,7 @@ var _ = Describe("controller", func() { }).Should(Equal([]priorityQueueAddition{{ AddOpts: priorityqueue.AddOpts{ RateLimited: true, - Priority: ptr.To(99), + Priority: new(99), }, items: []reconcile.Request{request}, }})) @@ -1028,7 +1027,7 @@ var _ = Describe("controller", func() { Expect(ctrl.Start(ctx)).NotTo(HaveOccurred()) }() - q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(10)}, request) + q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: new(10)}, request) By("Invoking Reconciler which will ask for RequeueAfter") fakeReconcile.AddResult(reconcile.Result{RequeueAfter: time.Millisecond * 100}, nil) @@ -1040,7 +1039,7 @@ var _ = Describe("controller", func() { }).Should(Equal([]priorityQueueAddition{{ AddOpts: priorityqueue.AddOpts{ After: time.Millisecond * 100, - Priority: ptr.To(10), + Priority: new(10), }, items: []reconcile.Request{request}, }})) @@ -1057,10 +1056,10 @@ var _ = Describe("controller", func() { Expect(ctrl.Start(ctx)).NotTo(HaveOccurred()) }() - q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(10)}, request) + q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: new(10)}, request) By("Invoking Reconciler which will ask for RequeueAfter") - fakeReconcile.AddResult(reconcile.Result{RequeueAfter: time.Millisecond * 100, Priority: ptr.To(99)}, nil) + fakeReconcile.AddResult(reconcile.Result{RequeueAfter: time.Millisecond * 100, Priority: new(99)}, nil) Expect(<-reconciled).To(Equal(request)) Eventually(func() []priorityQueueAddition { q.lock.Lock() @@ -1069,7 +1068,7 @@ var _ = Describe("controller", func() { }).Should(Equal([]priorityQueueAddition{{ AddOpts: priorityqueue.AddOpts{ After: time.Millisecond * 100, - Priority: ptr.To(99), + Priority: new(99), }, items: []reconcile.Request{request}, }})) @@ -1115,7 +1114,7 @@ var _ = Describe("controller", func() { Expect(ctrl.Start(ctx)).NotTo(HaveOccurred()) }() - q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(10)}, request) + q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: new(10)}, request) By("Invoking Reconciler which will return an error") fakeReconcile.AddResult(reconcile.Result{}, errors.New("oups, I did it again")) @@ -1127,7 +1126,7 @@ var _ = Describe("controller", func() { }).Should(Equal([]priorityQueueAddition{{ AddOpts: priorityqueue.AddOpts{ RateLimited: true, - Priority: ptr.To(10), + Priority: new(10), }, items: []reconcile.Request{request}, }})) @@ -1144,10 +1143,10 @@ var _ = Describe("controller", func() { Expect(ctrl.Start(ctx)).NotTo(HaveOccurred()) }() - q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: ptr.To(10)}, request) + q.PriorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: new(10)}, request) By("Invoking Reconciler which will return an error") - fakeReconcile.AddResult(reconcile.Result{Priority: ptr.To(99)}, errors.New("oups, I did it again")) + fakeReconcile.AddResult(reconcile.Result{Priority: new(99)}, errors.New("oups, I did it again")) Expect(<-reconciled).To(Equal(request)) Eventually(func() []priorityQueueAddition { q.lock.Lock() @@ -1156,7 +1155,7 @@ var _ = Describe("controller", func() { }).Should(Equal([]priorityQueueAddition{{ AddOpts: priorityqueue.AddOpts{ RateLimited: true, - Priority: ptr.To(99), + Priority: new(99), }, items: []reconcile.Request{request}, }})) @@ -1373,7 +1372,7 @@ var _ = Describe("controller", func() { Describe("Warmup", func() { JustBeforeEach(func() { - ctrl.EnableWarmup = ptr.To(true) + ctrl.EnableWarmup = new(true) }) It("should track warmup status correctly with successful sync", func(ctx SpecContext) { @@ -1391,7 +1390,7 @@ var _ = Describe("controller", func() { It("should return an error if there is an error waiting for the informers", func(ctx SpecContext) { ctrl.CacheSyncTimeout = time.Second ctrl.startWatches = []source.TypedSource[reconcile.Request]{ - source.Kind(&informertest.FakeInformers{Synced: ptr.To(false)}, &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}), + source.Kind(&informertest.FakeInformers{Synced: new(false)}, &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}), } ctrl.Name = testControllerName err := ctrl.Warmup(ctx) @@ -1652,8 +1651,8 @@ var _ = Describe("controller", func() { return log.RuntimeLog.WithName("controller").WithName("test") }, CacheSyncTimeout: time.Second, - EnableWarmup: ptr.To(false), - LeaderElected: ptr.To(true), + EnableWarmup: new(false), + LeaderElected: new(true), }) nonWarmupCtrl.startWatches = []source.TypedSource[reconcile.Request]{ source.Func(func(ctx context.Context, _ workqueue.TypedRateLimitingInterface[reconcile.Request]) error { @@ -1856,7 +1855,7 @@ var _ = Describe("controller", func() { Describe("Warmup with warmup disabled", func() { JustBeforeEach(func() { - ctrl.EnableWarmup = ptr.To(false) + ctrl.EnableWarmup = new(false) }) It("should not start sources when Warmup is called if warmup is disabled but start it when Start is called.", func(specCtx SpecContext) { diff --git a/pkg/internal/metrics/workqueue_test.go b/pkg/internal/metrics/workqueue_test.go index c3cb7378e7..d7f50feab0 100644 --- a/pkg/internal/metrics/workqueue_test.go +++ b/pkg/internal/metrics/workqueue_test.go @@ -17,6 +17,7 @@ limitations under the License. package metrics import ( + "strings" "sync" . "github.com/onsi/ginkgo/v2" @@ -41,10 +42,7 @@ func (f *fakeGaugeVec) WithLabelValues(lvs ...string) prometheus.Gauge { f.mu.Lock() defer f.mu.Unlock() - key := "" - for _, lv := range lvs { - key += lv + "|" - } + key := strings.Join(lvs, "|") + "|" if _, ok := f.gauges[key]; !ok { f.gauges[key] = 0 } diff --git a/pkg/manager/internal/integration/manager_test.go b/pkg/manager/internal/integration/manager_test.go index 570c932abc..3ea8fcb61b 100644 --- a/pkg/manager/internal/integration/manager_test.go +++ b/pkg/manager/internal/integration/manager_test.go @@ -34,7 +34,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" - "k8s.io/utils/ptr" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" ctrl "sigs.k8s.io/controller-runtime" @@ -169,7 +168,7 @@ var _ = Describe("manger.Manager Start", func() { ctrl.NewControllerManagedBy(mgr). For(&crewv2.Driver{}). Named(fmt.Sprintf("driver_warmup_%t", warmupEnabled)). - WithOptions(controller.Options{EnableWarmup: ptr.To(warmupEnabled)}). + WithOptions(controller.Options{EnableWarmup: new(warmupEnabled)}). Complete(driverReconciler), ).To(Succeed()) diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index af532ea741..d6fa7a4f28 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -34,7 +34,6 @@ import ( "k8s.io/client-go/tools/events" "k8s.io/client-go/tools/leaderelection/resourcelock" "k8s.io/client-go/tools/record" - "k8s.io/utils/ptr" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook/conversion" @@ -444,7 +443,7 @@ func New(config *rest.Config, options Options) (Manager, error) { errChan := make(chan error, 1) runnables := newRunnables(options.BaseContext, errChan).withLogger(options.Logger) return &controllerManager{ - stopProcedureEngaged: ptr.To(int64(0)), + stopProcedureEngaged: new(int64(0)), cluster: cluster, runnables: runnables, errChan: errChan, diff --git a/pkg/manager/manager_test.go b/pkg/manager/manager_test.go index 0e0d659c44..10a73072bb 100644 --- a/pkg/manager/manager_test.go +++ b/pkg/manager/manager_test.go @@ -895,11 +895,11 @@ var _ = Describe("manger.Manager", func() { } var lock sync.Mutex - var runnableDoneCount int64 + var runnableDoneCount atomic.Int64 runnableDoneFunc := func() { lock.Lock() defer lock.Unlock() - atomic.AddInt64(&runnableDoneCount, 1) + runnableDoneCount.Add(1) } var wgRunnableRunning sync.WaitGroup wgRunnableRunning.Add(2) @@ -929,9 +929,7 @@ var _ = Describe("manger.Manager", func() { defer GinkgoRecover() defer wgManagerRunning.Done() Expect(m.Start(ctx)).NotTo(HaveOccurred()) - Eventually(func() int64 { - return atomic.LoadInt64(&runnableDoneCount) - }).Should(BeEquivalentTo(2)) + Eventually(runnableDoneCount.Load).Should(BeEquivalentTo(2)) }() wgRunnableRunning.Wait() cancel() diff --git a/pkg/manager/runnable_group_test.go b/pkg/manager/runnable_group_test.go index 9a278a1495..67d3565780 100644 --- a/pkg/manager/runnable_group_test.go +++ b/pkg/manager/runnable_group_test.go @@ -11,7 +11,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/cache/informertest" "sigs.k8s.io/controller-runtime/pkg/webhook" @@ -197,7 +196,7 @@ var _ = Describe("runnableGroup", func() { It("should be able to close the group and wait for all runnables to finish", func(specCtx SpecContext) { ctx, cancel := context.WithCancel(specCtx) - exited := ptr.To(int64(0)) + exited := new(int64(0)) rg := newRunnableGroup(defaultBaseContext, errCh) for i := range 10 { Expect(rg.Add(RunnableFunc(func(c context.Context) error { diff --git a/pkg/metrics/filters/filters_test.go b/pkg/metrics/filters/filters_test.go index bd107fc56d..75f83f27c6 100644 --- a/pkg/metrics/filters/filters_test.go +++ b/pkg/metrics/filters/filters_test.go @@ -34,7 +34,6 @@ import ( rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/rest" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/metrics" @@ -256,7 +255,7 @@ func setupServiceAccountForURL(ctx context.Context, c client.Client, path string tokenRequest := &authenticationv1.TokenRequest{ Spec: authenticationv1.TokenRequestSpec{ - ExpirationSeconds: ptr.To(int64(2 * 60 * 60)), // 2 hours. + ExpirationSeconds: new(int64(2 * 60 * 60)), // 2 hours. }, } if err := c.SubResource("token").Create(ctx, sa, tokenRequest); err != nil { diff --git a/pkg/source/source.go b/pkg/source/source.go index c2c2dc4e07..e4f63ee5b5 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -24,7 +24,6 @@ import ( toolscache "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" @@ -186,7 +185,7 @@ func (cs *channel[object, request]) Start( } if cs.bufferSize == nil { - cs.bufferSize = ptr.To(1024) + cs.bufferSize = new(1024) } dst := make(chan event.TypedGenericEvent[object], *cs.bufferSize) diff --git a/pkg/webhook/admission/defaulter_custom_test.go b/pkg/webhook/admission/defaulter_custom_test.go index 8fcae2bed2..4daa9d31bd 100644 --- a/pkg/webhook/admission/defaulter_custom_test.go +++ b/pkg/webhook/admission/defaulter_custom_test.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/ptr" ) var _ = Describe("Defaulter Handler", func() { @@ -273,7 +272,7 @@ func createSuperPod(hostname string) *corev1.Pod { InitContainers: []corev1.Container{ { Name: "vault-init", Image: "vault:1.13.1", - SecurityContext: &corev1.SecurityContext{RunAsUser: ptr.To[int64](1000)}, + SecurityContext: &corev1.SecurityContext{RunAsUser: new(int64(1000))}, }, }, Containers: []corev1.Container{ @@ -328,10 +327,10 @@ func createSuperPod(hostname string) *corev1.Pod { }, }, SecurityContext: &corev1.PodSecurityContext{ - RunAsNonRoot: ptr.To(true), + RunAsNonRoot: new(true), SeccompProfile: &corev1.SeccompProfile{Type: corev1.SeccompProfileTypeRuntimeDefault}, }, - TerminationGracePeriodSeconds: ptr.To[int64](60), + TerminationGracePeriodSeconds: new(int64(60)), ReadinessGates: []corev1.PodReadinessGate{ {ConditionType: "target-health.lbv3.k8s.cloud/my-tg"}, }, diff --git a/pkg/webhook/admission/webhook_test.go b/pkg/webhook/admission/webhook_test.go index 5176077368..4612c533ef 100644 --- a/pkg/webhook/admission/webhook_test.go +++ b/pkg/webhook/admission/webhook_test.go @@ -30,7 +30,6 @@ import ( authenticationv1 "k8s.io/api/authentication/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" machinerytypes "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -236,7 +235,7 @@ var _ = Describe("Admission Webhooks", func() { } webhook := &Webhook{ Handler: handler, - RecoverPanic: ptr.To[bool](true), + RecoverPanic: new(true), } return webhook @@ -263,7 +262,7 @@ var _ = Describe("Admission Webhooks", func() { } webhook := &Webhook{ Handler: handler, - RecoverPanic: ptr.To[bool](false), + RecoverPanic: new(false), } return webhook