Skip to content

Commit caaf3ff

Browse files
committed
pkg/volume: drop pointer wrapper functions.
The new k8s.io/utils/ptr package provides generic wrapper functions, which can be used instead of type-specific pointer wrapper functions. This replaces the latter with the former, and migrates other uses of the deprecated pointer package to ptr in affacted files. See kubernetes/utils#283 for details. Signed-off-by: Lan Liang <[email protected]>
1 parent 6ac2067 commit caaf3ff

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

pkg/volume/csi/nodeinfomanager/nodeinfomanager_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
"k8s.io/kubernetes/pkg/apis/core/helper"
4242
volumetest "k8s.io/kubernetes/pkg/volume/testing"
4343
"k8s.io/kubernetes/pkg/volume/util"
44-
utilpointer "k8s.io/utils/pointer"
44+
"k8s.io/utils/ptr"
4545
)
4646

4747
type testcase struct {
@@ -459,7 +459,7 @@ func TestInstallCSIDriver(t *testing.T) {
459459
NodeID: "com.example.csi/csi-node1",
460460
TopologyKeys: nil,
461461
Allocatable: &storage.VolumeNodeResources{
462-
Count: utilpointer.Int32Ptr(10),
462+
Count: ptr.To[int32](10),
463463
},
464464
},
465465
},
@@ -488,7 +488,7 @@ func TestInstallCSIDriver(t *testing.T) {
488488
NodeID: "com.example.csi/csi-node1",
489489
TopologyKeys: nil,
490490
Allocatable: &storage.VolumeNodeResources{
491-
Count: utilpointer.Int32Ptr(math.MaxInt32),
491+
Count: ptr.To[int32](math.MaxInt32),
492492
},
493493
},
494494
},
@@ -517,7 +517,7 @@ func TestInstallCSIDriver(t *testing.T) {
517517
NodeID: "com.example.csi/csi-node1",
518518
TopologyKeys: nil,
519519
Allocatable: &storage.VolumeNodeResources{
520-
Count: utilpointer.Int32Ptr(math.MaxInt32),
520+
Count: ptr.To[int32](math.MaxInt32),
521521
},
522522
},
523523
},
@@ -606,7 +606,7 @@ func TestInstallCSIDriver(t *testing.T) {
606606

607607
func generateVolumeLimits(i int32) *storage.VolumeNodeResources {
608608
return &storage.VolumeNodeResources{
609-
Count: utilpointer.Int32Ptr(i),
609+
Count: ptr.To[int32](i),
610610
}
611611
}
612612

pkg/volume/projected/projected_test.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import (
4747
"k8s.io/kubernetes/pkg/volume/emptydir"
4848
volumetest "k8s.io/kubernetes/pkg/volume/testing"
4949
"k8s.io/kubernetes/pkg/volume/util"
50-
utilptr "k8s.io/utils/pointer"
50+
"k8s.io/utils/ptr"
5151
)
5252

5353
func TestCollectDataWithSecret(t *testing.T) {
@@ -260,7 +260,7 @@ func TestCollectDataWithSecret(t *testing.T) {
260260
Name: tc.name,
261261
}
262262

263-
source := makeProjection(tc.name, utilptr.Int32Ptr(tc.mode), "secret")
263+
source := makeProjection(tc.name, ptr.To[int32](tc.mode), "secret")
264264
source.Sources[0].Secret.Items = tc.mappings
265265
source.Sources[0].Secret.Optional = &tc.optional
266266

@@ -509,7 +509,7 @@ func TestCollectDataWithConfigMap(t *testing.T) {
509509
Name: tc.name,
510510
}
511511

512-
source := makeProjection(tc.name, utilptr.Int32Ptr(tc.mode), "configMap")
512+
source := makeProjection(tc.name, ptr.To[int32](tc.mode), "configMap")
513513
source.Sources[0].ConfigMap.Items = tc.mappings
514514
source.Sources[0].ConfigMap.Optional = &tc.optional
515515

@@ -683,7 +683,7 @@ func TestCollectDataWithDownwardAPI(t *testing.T) {
683683

684684
for _, tc := range cases {
685685
t.Run(tc.name, func(t *testing.T) {
686-
source := makeProjection("", utilptr.Int32Ptr(tc.mode), "downwardAPI")
686+
source := makeProjection("", ptr.To[int32](tc.mode), "downwardAPI")
687687
source.Sources[0].DownwardAPI.Items = tc.volumeFile
688688

689689
client := fake.NewSimpleClientset(tc.pod)
@@ -743,7 +743,7 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
743743
{
744744
name: "good service account",
745745
audience: "https://example.com",
746-
defaultMode: utilptr.Int32Ptr(0644),
746+
defaultMode: ptr.To[int32](0644),
747747
path: "token",
748748
expiration: &minute,
749749

@@ -754,7 +754,7 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
754754
{
755755
name: "good service account other path",
756756
audience: "https://example.com",
757-
defaultMode: utilptr.Int32Ptr(0644),
757+
defaultMode: ptr.To[int32](0644),
758758
path: "other-token",
759759
expiration: &minute,
760760
wantPayload: map[string]util.FileProjection{
@@ -763,7 +763,7 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
763763
},
764764
{
765765
name: "good service account defaults audience",
766-
defaultMode: utilptr.Int32Ptr(0644),
766+
defaultMode: ptr.To[int32](0644),
767767
path: "token",
768768
expiration: &minute,
769769

@@ -773,7 +773,7 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
773773
},
774774
{
775775
name: "good service account defaults expiration",
776-
defaultMode: utilptr.Int32Ptr(0644),
776+
defaultMode: ptr.To[int32](0644),
777777
path: "token",
778778

779779
wantPayload: map[string]util.FileProjection{
@@ -787,21 +787,21 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
787787
},
788788
{
789789
name: "fsUser != nil",
790-
defaultMode: utilptr.Int32Ptr(0644),
791-
fsUser: utilptr.Int64Ptr(1000),
790+
defaultMode: ptr.To[int32](0644),
791+
fsUser: ptr.To[int64](1000),
792792
path: "token",
793793
wantPayload: map[string]util.FileProjection{
794794
"token": {
795795
Data: []byte("test_projected_namespace:foo:3600:[https://api]"),
796796
Mode: 0600,
797-
FsUser: utilptr.Int64Ptr(1000),
797+
FsUser: ptr.To[int64](1000),
798798
},
799799
},
800800
},
801801
{
802802
name: "fsGroup != nil",
803-
defaultMode: utilptr.Int32Ptr(0644),
804-
fsGroup: utilptr.Int64Ptr(1000),
803+
defaultMode: ptr.To[int32](0644),
804+
fsGroup: ptr.To[int64](1000),
805805
path: "token",
806806
wantPayload: map[string]util.FileProjection{
807807
"token": {
@@ -812,15 +812,15 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
812812
},
813813
{
814814
name: "fsUser != nil && fsGroup != nil",
815-
defaultMode: utilptr.Int32Ptr(0644),
816-
fsGroup: utilptr.Int64Ptr(1000),
817-
fsUser: utilptr.Int64Ptr(1000),
815+
defaultMode: ptr.To[int32](0644),
816+
fsGroup: ptr.To[int64](1000),
817+
fsUser: ptr.To[int64](1000),
818818
path: "token",
819819
wantPayload: map[string]util.FileProjection{
820820
"token": {
821821
Data: []byte("test_projected_namespace:foo:3600:[https://api]"),
822822
Mode: 0600,
823-
FsUser: utilptr.Int64Ptr(1000),
823+
FsUser: ptr.To[int64](1000),
824824
},
825825
},
826826
},
@@ -904,12 +904,12 @@ func TestCollectDataWithClusterTrustBundle(t *testing.T) {
904904
Sources: []v1.VolumeProjection{
905905
{
906906
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
907-
Name: utilptr.String("foo"),
907+
Name: ptr.To("foo"),
908908
Path: "bundle.pem",
909909
},
910910
},
911911
},
912-
DefaultMode: utilptr.Int32(0644),
912+
DefaultMode: ptr.To[int32](0644),
913913
},
914914
bundles: []runtime.Object{
915915
&certificatesv1alpha1.ClusterTrustBundle{
@@ -934,7 +934,7 @@ func TestCollectDataWithClusterTrustBundle(t *testing.T) {
934934
Sources: []v1.VolumeProjection{
935935
{
936936
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
937-
SignerName: utilptr.String("foo.example/bar"), // Note: fake client doesn't understand selection by signer name.
937+
SignerName: ptr.To("foo.example/bar"), // Note: fake client doesn't understand selection by signer name.
938938
LabelSelector: &metav1.LabelSelector{
939939
MatchLabels: map[string]string{
940940
"key": "non-value", // Note: fake client doesn't actually act on label selectors.
@@ -944,7 +944,7 @@ func TestCollectDataWithClusterTrustBundle(t *testing.T) {
944944
},
945945
},
946946
},
947-
DefaultMode: utilptr.Int32(0644),
947+
DefaultMode: ptr.To[int32](0644),
948948
},
949949
bundles: []runtime.Object{
950950
&certificatesv1alpha1.ClusterTrustBundle{
@@ -973,12 +973,12 @@ func TestCollectDataWithClusterTrustBundle(t *testing.T) {
973973
Sources: []v1.VolumeProjection{
974974
{
975975
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
976-
Name: utilptr.String("foo"),
976+
Name: ptr.To("foo"),
977977
Path: "bundle.pem",
978978
},
979979
},
980980
},
981-
DefaultMode: utilptr.Int32(0600),
981+
DefaultMode: ptr.To[int32](0600),
982982
},
983983
bundles: []runtime.Object{
984984
&certificatesv1alpha1.ClusterTrustBundle{
@@ -1400,7 +1400,7 @@ func makeVolumeSpec(volumeName, name string, defaultMode int32) *v1.Volume {
14001400
return &v1.Volume{
14011401
Name: volumeName,
14021402
VolumeSource: v1.VolumeSource{
1403-
Projected: makeProjection(name, utilptr.Int32Ptr(defaultMode), "secret"),
1403+
Projected: makeProjection(name, ptr.To[int32](defaultMode), "secret"),
14041404
},
14051405
}
14061406
}

0 commit comments

Comments
 (0)