Skip to content

Commit 3ddde48

Browse files
committed
replace k8s.io/utils/pointer with k8s.io/utils/ptr
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
1 parent b81fc66 commit 3ddde48

File tree

24 files changed

+64
-67
lines changed

24 files changed

+64
-67
lines changed

examples/scratch-env/go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,8 +2018,9 @@ k8s.io/kms v0.28.3/go.mod h1:kSMjU2tg7vjqqoWVVCcmPmNZ/CofPsoTbSxAipCvZuE=
20182018
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
20192019
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
20202020
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
2021-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
20222021
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
2022+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
2023+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
20232024
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
20242025
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
20252026
modernc.org/cc/v3 v3.36.0/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
k8s.io/client-go v0.28.3
2727
k8s.io/component-base v0.28.3
2828
k8s.io/klog/v2 v2.110.1
29-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
29+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
3030
sigs.k8s.io/yaml v1.4.0
3131
)
3232

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ k8s.io/kms v0.28.3 h1:jYwwAe96XELNjYWv1G4kNzizcFoZ50OOElvPansbw70=
644644
k8s.io/kms v0.28.3/go.mod h1:kSMjU2tg7vjqqoWVVCcmPmNZ/CofPsoTbSxAipCvZuE=
645645
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
646646
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
647-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
648-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
647+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
648+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
649649
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
650650
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
651651
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

pkg/builder/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"k8s.io/apimachinery/pkg/types"
3434
"k8s.io/client-go/rest"
3535
"k8s.io/client-go/util/workqueue"
36-
"k8s.io/utils/pointer"
36+
"k8s.io/utils/ptr"
3737

3838
"sigs.k8s.io/controller-runtime/pkg/cache"
3939
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -668,7 +668,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
668668
Name: deployName,
669669
Kind: "Deployment",
670670
APIVersion: "apps/v1",
671-
Controller: pointer.Bool(true),
671+
Controller: ptr.To(true),
672672
UID: dep.UID,
673673
},
674674
},

pkg/cache/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"k8s.io/client-go/kubernetes/scheme"
3434
"k8s.io/client-go/rest"
3535
toolscache "k8s.io/client-go/tools/cache"
36-
"k8s.io/utils/pointer"
36+
"k8s.io/utils/ptr"
3737

3838
"sigs.k8s.io/controller-runtime/pkg/cache/internal"
3939
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -381,7 +381,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
381381
},
382382
Transform: config.Transform,
383383
WatchErrorHandler: opts.DefaultWatchErrorHandler,
384-
UnsafeDisableDeepCopy: pointer.BoolDeref(config.UnsafeDisableDeepCopy, false),
384+
UnsafeDisableDeepCopy: ptr.Deref(config.UnsafeDisableDeepCopy, false),
385385
NewInformer: opts.newInformer,
386386
}),
387387
readerFailOnMissingInformer: opts.ReaderFailOnMissingInformer,

pkg/cache/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
kscheme "k8s.io/client-go/kubernetes/scheme"
4141
"k8s.io/client-go/rest"
4242
kcache "k8s.io/client-go/tools/cache"
43-
"k8s.io/utils/pointer"
43+
"k8s.io/utils/ptr"
4444

4545
"sigs.k8s.io/controller-runtime/pkg/cache"
4646
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -146,10 +146,10 @@ var _ = Describe("Multi-Namespace Informer Cache", func() {
146146

147147
var _ = Describe("Informer Cache without global DeepCopy", func() {
148148
CacheTest(cache.New, cache.Options{
149-
DefaultUnsafeDisableDeepCopy: pointer.Bool(true),
149+
DefaultUnsafeDisableDeepCopy: ptr.To(true),
150150
})
151151
NonBlockingGetTest(cache.New, cache.Options{
152-
DefaultUnsafeDisableDeepCopy: pointer.Bool(true),
152+
DefaultUnsafeDisableDeepCopy: ptr.To(true),
153153
})
154154
})
155155

pkg/cache/defaulting_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/runtime/schema"
3131
"k8s.io/client-go/rest"
3232
"k8s.io/client-go/tools/cache"
33-
"k8s.io/utils/pointer"
33+
"k8s.io/utils/ptr"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535
)
3636

@@ -187,23 +187,23 @@ func TestDefaultOpts(t *testing.T) {
187187
name: "ByObject.UnsafeDisableDeepCopy gets defaulted from DefaultUnsafeDisableDeepCopy",
188188
in: Options{
189189
ByObject: map[client.Object]ByObject{pod: {}},
190-
DefaultUnsafeDisableDeepCopy: pointer.Bool(true),
190+
DefaultUnsafeDisableDeepCopy: ptr.To(true),
191191
},
192192

193193
verification: func(o Options) string {
194-
expected := pointer.Bool(true)
194+
expected := ptr.To(true)
195195
return cmp.Diff(expected, o.ByObject[pod].UnsafeDisableDeepCopy)
196196
},
197197
},
198198
{
199199
name: "ByObject.UnsafeDisableDeepCopy doesn't get defaulted when set",
200200
in: Options{
201-
ByObject: map[client.Object]ByObject{pod: {UnsafeDisableDeepCopy: pointer.Bool(false)}},
202-
DefaultUnsafeDisableDeepCopy: pointer.Bool(true),
201+
ByObject: map[client.Object]ByObject{pod: {UnsafeDisableDeepCopy: ptr.To(false)}},
202+
DefaultUnsafeDisableDeepCopy: ptr.To(true),
203203
},
204204

205205
verification: func(o Options) string {
206-
expected := pointer.Bool(false)
206+
expected := ptr.To(false)
207207
return cmp.Diff(expected, o.ByObject[pod].UnsafeDisableDeepCopy)
208208
},
209209
},

pkg/client/client_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
"k8s.io/apimachinery/pkg/runtime/schema"
4242
"k8s.io/apimachinery/pkg/types"
4343
kscheme "k8s.io/client-go/kubernetes/scheme"
44-
"k8s.io/utils/pointer"
44+
"k8s.io/utils/ptr"
4545

4646
"sigs.k8s.io/controller-runtime/examples/crd/pkg"
4747
"sigs.k8s.io/controller-runtime/pkg/cache"
@@ -391,7 +391,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
391391

392392
Context("with the DryRun option", func() {
393393
It("should not create a new object, global option", func() {
394-
cl, err := client.New(cfg, client.Options{DryRun: pointer.Bool(true)})
394+
cl, err := client.New(cfg, client.Options{DryRun: ptr.To(true)})
395395
Expect(err).NotTo(HaveOccurred())
396396
Expect(cl).NotTo(BeNil())
397397

@@ -843,7 +843,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
843843

844844
By("Creating the eviction")
845845
eviction := &policyv1.Eviction{
846-
DeleteOptions: &metav1.DeleteOptions{GracePeriodSeconds: ptr(int64(0))},
846+
DeleteOptions: &metav1.DeleteOptions{GracePeriodSeconds: ptr.To(int64(0))},
847847
}
848848
err = cl.SubResource("eviction").Create(ctx, pod, eviction)
849849
Expect((err)).NotTo(HaveOccurred())
@@ -3965,10 +3965,6 @@ func (f *fakeUncachedReader) List(_ context.Context, _ client.ObjectList, _ ...c
39653965
return &cache.ErrResourceNotCached{}
39663966
}
39673967

3968-
func ptr[T any](to T) *T {
3969-
return &to
3970-
}
3971-
39723968
func toUnstructured(o client.Object) (*unstructured.Unstructured, error) {
39733969
serialized, err := json.Marshal(o)
39743970
if err != nil {

pkg/client/dryrun_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/types"
31-
"k8s.io/utils/pointer"
31+
"k8s.io/utils/ptr"
3232

3333
"sigs.k8s.io/controller-runtime/pkg/client"
3434
)
@@ -41,7 +41,7 @@ var _ = Describe("DryRunClient", func() {
4141
ctx := context.Background()
4242

4343
getClient := func() client.Client {
44-
cl, err := client.New(cfg, client.Options{DryRun: pointer.Bool(true)})
44+
cl, err := client.New(cfg, client.Options{DryRun: ptr.To(true)})
4545
Expect(err).NotTo(HaveOccurred())
4646
Expect(cl).NotTo(BeNil())
4747
return cl

pkg/client/fake/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
"k8s.io/apimachinery/pkg/types"
4141
"k8s.io/apimachinery/pkg/watch"
4242
"k8s.io/client-go/kubernetes/fake"
43-
"k8s.io/utils/pointer"
43+
"k8s.io/utils/ptr"
4444

4545
"sigs.k8s.io/controller-runtime/pkg/client"
4646
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"
@@ -1610,7 +1610,7 @@ var _ = Describe("Fake client", func() {
16101610
objOriginal.APIVersion = actual.APIVersion
16111611
objOriginal.Kind = actual.Kind
16121612
objOriginal.ResourceVersion = actual.ResourceVersion
1613-
objOriginal.Spec.Replicas = pointer.Int32(2)
1613+
objOriginal.Spec.Replicas = ptr.To(int32(2))
16141614
Expect(cmp.Diff(objOriginal, actual)).To(BeEmpty())
16151615
})
16161616

0 commit comments

Comments
 (0)