From 0a77a9122fa4271c84d33a43b0908675c316c0fa Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Fri, 1 Jul 2022 14:51:39 +0800 Subject: [PATCH] convert int32 to pointer using library function --- pkg/controller/controller_utils_test.go | 5 +++-- pkg/controller/deployment/deployment_controller_test.go | 7 ++++--- pkg/controller/history/controller_history_test.go | 3 ++- pkg/controller/replicaset/replica_set_test.go | 3 ++- pkg/controller/statefulset/stateful_set_utils_test.go | 5 +++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/controller/controller_utils_test.go b/pkg/controller/controller_utils_test.go index 26d89e38978..ce57a010953 100644 --- a/pkg/controller/controller_utils_test.go +++ b/pkg/controller/controller_utils_test.go @@ -52,6 +52,7 @@ import ( "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/securitycontext" testingclock "k8s.io/utils/clock/testing" + "k8s.io/utils/pointer" "github.com/stretchr/testify/assert" ) @@ -76,7 +77,7 @@ func newReplicationController(replicas int) *v1.ReplicationController { ResourceVersion: "18", }, Spec: v1.ReplicationControllerSpec{ - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Selector: map[string]string{"foo": "bar"}, Template: &v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -138,7 +139,7 @@ func newReplicaSet(name string, replicas int) *apps.ReplicaSet { ResourceVersion: "18", }, Spec: apps.ReplicaSetSpec{ - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}}, Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/controller/deployment/deployment_controller_test.go b/pkg/controller/deployment/deployment_controller_test.go index 4178714f27f..45b7a005ad9 100644 --- a/pkg/controller/deployment/deployment_controller_test.go +++ b/pkg/controller/deployment/deployment_controller_test.go @@ -47,6 +47,7 @@ import ( "k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/controller/deployment/util" "k8s.io/kubernetes/pkg/controller/testutil" + "k8s.io/utils/pointer" ) var ( @@ -62,7 +63,7 @@ func rs(name string, replicas int, selector map[string]string, timestamp metav1. Namespace: metav1.NamespaceDefault, }, Spec: apps.ReplicaSetSpec{ - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Selector: &metav1.LabelSelector{MatchLabels: selector}, Template: v1.PodTemplateSpec{}, }, @@ -94,7 +95,7 @@ func newDeployment(name string, replicas int, revisionHistoryLimit *int32, maxSu MaxSurge: func() *intstr.IntOrString { i := intstr.FromInt(0); return &i }(), }, }, - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Selector: &metav1.LabelSelector{MatchLabels: selector}, Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -132,7 +133,7 @@ func newReplicaSet(d *apps.Deployment, name string, replicas int) *apps.ReplicaS }, Spec: apps.ReplicaSetSpec{ Selector: d.Spec.Selector, - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Template: d.Spec.Template, }, } diff --git a/pkg/controller/history/controller_history_test.go b/pkg/controller/history/controller_history_test.go index 56c7edd55ed..be24d18c1d5 100644 --- a/pkg/controller/history/controller_history_test.go +++ b/pkg/controller/history/controller_history_test.go @@ -41,6 +41,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/strategicpatch" + "k8s.io/utils/pointer" ) func TestRealHistory_ListControllerRevisions(t *testing.T) { @@ -1649,7 +1650,7 @@ func newStatefulSet(replicas int, name string, uid types.UID, labels map[string] MatchLabels: nil, MatchExpressions: testMatchExpressions, }, - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, diff --git a/pkg/controller/replicaset/replica_set_test.go b/pkg/controller/replicaset/replica_set_test.go index 01dfdc05397..ab314f776b3 100644 --- a/pkg/controller/replicaset/replica_set_test.go +++ b/pkg/controller/replicaset/replica_set_test.go @@ -53,6 +53,7 @@ import ( "k8s.io/kubernetes/pkg/controller" . "k8s.io/kubernetes/pkg/controller/testutil" "k8s.io/kubernetes/pkg/securitycontext" + "k8s.io/utils/pointer" ) var ( @@ -101,7 +102,7 @@ func newReplicaSet(replicas int, selectorMap map[string]string) *apps.ReplicaSet ResourceVersion: "18", }, Spec: apps.ReplicaSetSpec{ - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Selector: &metav1.LabelSelector{MatchLabels: selectorMap}, Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/controller/statefulset/stateful_set_utils_test.go b/pkg/controller/statefulset/stateful_set_utils_test.go index 969bcb8e52e..094290dbe62 100644 --- a/pkg/controller/statefulset/stateful_set_utils_test.go +++ b/pkg/controller/statefulset/stateful_set_utils_test.go @@ -36,6 +36,7 @@ import ( v1 "k8s.io/api/core/v1" podutil "k8s.io/kubernetes/pkg/api/v1/pod" "k8s.io/kubernetes/pkg/controller/history" + "k8s.io/utils/pointer" ) // noopRecorder is an EventRecorder that does nothing. record.FakeRecorder has a fixed @@ -838,7 +839,7 @@ func newStatefulSetWithVolumes(replicas int, name string, petMounts []v1.VolumeM Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{"foo": "bar"}, }, - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), Template: template, VolumeClaimTemplates: claims, ServiceName: "governingsvc", @@ -893,7 +894,7 @@ func newStatefulSetWithLabels(replicas int, name string, uid types.UID, labels m MatchLabels: nil, MatchExpressions: testMatchExpressions, }, - Replicas: func() *int32 { i := int32(replicas); return &i }(), + Replicas: pointer.Int32(int32(replicas)), PersistentVolumeClaimRetentionPolicy: &apps.StatefulSetPersistentVolumeClaimRetentionPolicy{ WhenScaled: apps.RetainPersistentVolumeClaimRetentionPolicyType, WhenDeleted: apps.RetainPersistentVolumeClaimRetentionPolicyType,