Merge pull request #60073 from justaugustus/int-to-int32ptr
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Use `pkg/util/pointer` functions instead of self-written versions **What this PR does / why we need it**: Replaces instances of module-written `int(32|64)? --> *int(32|64)?` functions with functions from k8s.io/kubernetes/pkg/util/pointer **Special notes for your reviewer**: Here's the grep used, based on the comments in: * https://github.com/kubernetes/kubernetes/pull/59924#issuecomment-366119396 * https://github.com/kubernetes/kubernetes/issues/59971#issue-297766556 ```bash $ git grep -E 'func\ [^ (]+\([^ ]+\ int(32|64)?\)\ \*int(32|64)?' !(vendor|staging) | grep -v pkg/util/pointer pkg/apis/apps/v1/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/apps/v1beta1/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/apps/v1beta2/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/autoscaling/v1/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/autoscaling/v2beta1/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/autoscaling/validation/validation_test.go:func newInt32(val int32) *int32 { pkg/apis/batch/v1/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/batch/v1beta1/defaults_test.go:func newInt32(val int32) *int32 { pkg/apis/core/v1/defaults_test.go:func newInt(val int32) *int32 { pkg/apis/core/validation/validation_test.go:func newInt32(val int) *int32 { pkg/apis/extensions/v1beta1/defaults_test.go:func newInt32(val int32) *int32 { pkg/controller/deployment/sync_test.go:func intOrStrP(val int) *intstr.IntOrString { pkg/kubectl/autoscale_test.go:func newInt32(value int) *int32 { plugin/pkg/admission/security/podsecuritypolicy/admission_test.go:func userIDPtr(i int) *int64 { plugin/pkg/admission/security/podsecuritypolicy/admission_test.go:func groupIDPtr(i int) *int64 { test/e2e/apps/deployment.go:func intOrStrP(num int) *intstr.IntOrString { test/e2e/auth/pod_security_policy.go:func intPtr(i int64) *int64 { test/integration/deployment/util.go:func intOrStrP(num int) *intstr.IntOrString { ``` **Release note**: ```release-note NONE ``` /kind cleanup /cc @php-coder /assign @tallclair
This commit is contained in:
@@ -38,6 +38,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/capabilities"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/security/apparmor"
|
||||
utilpointer "k8s.io/kubernetes/pkg/util/pointer"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -1560,7 +1561,7 @@ func TestValidateKeyToPath(t *testing.T) {
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
kp: core.KeyToPath{Key: "k", Path: "p", Mode: newInt32(0644)},
|
||||
kp: core.KeyToPath{Key: "k", Path: "p", Mode: utilpointer.Int32Ptr(0644)},
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
@@ -1594,12 +1595,12 @@ func TestValidateKeyToPath(t *testing.T) {
|
||||
errtype: field.ErrorTypeInvalid,
|
||||
},
|
||||
{
|
||||
kp: core.KeyToPath{Key: "k", Path: "p", Mode: newInt32(01000)},
|
||||
kp: core.KeyToPath{Key: "k", Path: "p", Mode: utilpointer.Int32Ptr(01000)},
|
||||
ok: false,
|
||||
errtype: field.ErrorTypeInvalid,
|
||||
},
|
||||
{
|
||||
kp: core.KeyToPath{Key: "k", Path: "p", Mode: newInt32(-1)},
|
||||
kp: core.KeyToPath{Key: "k", Path: "p", Mode: utilpointer.Int32Ptr(-1)},
|
||||
ok: false,
|
||||
errtype: field.ErrorTypeInvalid,
|
||||
},
|
||||
@@ -1836,14 +1837,6 @@ func TestValidateCSIVolumeSource(t *testing.T) {
|
||||
t.Errorf("Failed to disable feature gate for CSIPersistentVolumes: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// helper
|
||||
func newInt32(val int) *int32 {
|
||||
p := new(int32)
|
||||
*p = int32(val)
|
||||
return p
|
||||
}
|
||||
|
||||
// This test is a little too top-to-bottom. Ideally we would test each volume
|
||||
@@ -2330,7 +2323,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "my-secret",
|
||||
DefaultMode: newInt32(0644),
|
||||
DefaultMode: utilpointer.Int32Ptr(0644),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2345,7 +2338,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Items: []core.KeyToPath{{
|
||||
Key: "key",
|
||||
Path: "filename",
|
||||
Mode: newInt32(0644),
|
||||
Mode: utilpointer.Int32Ptr(0644),
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -2415,7 +2408,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "s",
|
||||
DefaultMode: newInt32(01000),
|
||||
DefaultMode: utilpointer.Int32Ptr(01000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2429,7 +2422,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "s",
|
||||
DefaultMode: newInt32(-1),
|
||||
DefaultMode: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2459,7 +2452,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
LocalObjectReference: core.LocalObjectReference{
|
||||
Name: "my-cfgmap",
|
||||
},
|
||||
DefaultMode: newInt32(0644),
|
||||
DefaultMode: utilpointer.Int32Ptr(0644),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2475,7 +2468,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Items: []core.KeyToPath{{
|
||||
Key: "key",
|
||||
Path: "filename",
|
||||
Mode: newInt32(0644),
|
||||
Mode: utilpointer.Int32Ptr(0644),
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -2546,7 +2539,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
ConfigMap: &core.ConfigMapVolumeSource{
|
||||
LocalObjectReference: core.LocalObjectReference{Name: "c"},
|
||||
DefaultMode: newInt32(01000),
|
||||
DefaultMode: utilpointer.Int32Ptr(01000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2560,7 +2553,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
ConfigMap: &core.ConfigMapVolumeSource{
|
||||
LocalObjectReference: core.LocalObjectReference{Name: "c"},
|
||||
DefaultMode: newInt32(-1),
|
||||
DefaultMode: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2889,7 +2882,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Name: "downapi",
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
DefaultMode: newInt32(0644),
|
||||
DefaultMode: utilpointer.Int32Ptr(0644),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2901,7 +2894,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
Items: []core.DownwardAPIVolumeFile{{
|
||||
Mode: newInt32(0644),
|
||||
Mode: utilpointer.Int32Ptr(0644),
|
||||
Path: "path",
|
||||
FieldRef: &core.ObjectFieldSelector{
|
||||
APIVersion: "v1",
|
||||
@@ -2919,7 +2912,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
Items: []core.DownwardAPIVolumeFile{{
|
||||
Mode: newInt32(01000),
|
||||
Mode: utilpointer.Int32Ptr(01000),
|
||||
Path: "path",
|
||||
FieldRef: &core.ObjectFieldSelector{
|
||||
APIVersion: "v1",
|
||||
@@ -2939,7 +2932,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
Items: []core.DownwardAPIVolumeFile{{
|
||||
Mode: newInt32(-1),
|
||||
Mode: utilpointer.Int32Ptr(-1),
|
||||
Path: "path",
|
||||
FieldRef: &core.ObjectFieldSelector{
|
||||
APIVersion: "v1",
|
||||
@@ -3080,7 +3073,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Name: "downapi",
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
DefaultMode: newInt32(01000),
|
||||
DefaultMode: utilpointer.Int32Ptr(01000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -3093,7 +3086,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Name: "downapi",
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
DefaultMode: newInt32(-1),
|
||||
DefaultMode: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -3108,7 +3101,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
FC: &core.FCVolumeSource{
|
||||
TargetWWNs: []string{"some_wwn"},
|
||||
Lun: newInt32(1),
|
||||
Lun: utilpointer.Int32Ptr(1),
|
||||
FSType: "ext4",
|
||||
ReadOnly: false,
|
||||
},
|
||||
@@ -3135,7 +3128,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
FC: &core.FCVolumeSource{
|
||||
TargetWWNs: []string{},
|
||||
Lun: newInt32(1),
|
||||
Lun: utilpointer.Int32Ptr(1),
|
||||
WWIDs: []string{},
|
||||
FSType: "ext4",
|
||||
ReadOnly: false,
|
||||
@@ -3153,7 +3146,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
FC: &core.FCVolumeSource{
|
||||
TargetWWNs: []string{"some_wwn"},
|
||||
Lun: newInt32(1),
|
||||
Lun: utilpointer.Int32Ptr(1),
|
||||
WWIDs: []string{"some_wwid"},
|
||||
FSType: "ext4",
|
||||
ReadOnly: false,
|
||||
@@ -3188,7 +3181,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
FC: &core.FCVolumeSource{
|
||||
TargetWWNs: []string{"wwn"},
|
||||
Lun: newInt32(256),
|
||||
Lun: utilpointer.Int32Ptr(256),
|
||||
FSType: "ext4",
|
||||
ReadOnly: false,
|
||||
},
|
||||
@@ -8692,7 +8685,7 @@ func TestValidateService(t *testing.T) {
|
||||
s.Spec.SessionAffinity = core.ServiceAffinityClientIP
|
||||
s.Spec.SessionAffinityConfig = &core.SessionAffinityConfig{
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(-1),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -8705,7 +8698,7 @@ func TestValidateService(t *testing.T) {
|
||||
s.Spec.SessionAffinity = core.ServiceAffinityNone
|
||||
s.Spec.SessionAffinityConfig = &core.SessionAffinityConfig{
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(90),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(90),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -10200,7 +10193,7 @@ func TestValidateServiceUpdate(t *testing.T) {
|
||||
newSvc.Spec.SessionAffinity = "ClientIP"
|
||||
newSvc.Spec.SessionAffinityConfig = &core.SessionAffinityConfig{
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(90),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(90),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -12494,17 +12487,17 @@ func TestValidateOrSetClientIPAffinityConfig(t *testing.T) {
|
||||
successCases := map[string]*core.SessionAffinityConfig{
|
||||
"non-empty config, valid timeout: 1": {
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(1),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(1),
|
||||
},
|
||||
},
|
||||
"non-empty config, valid timeout: core.MaxClientIPServiceAffinitySeconds-1": {
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(int(core.MaxClientIPServiceAffinitySeconds - 1)),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(core.MaxClientIPServiceAffinitySeconds - 1),
|
||||
},
|
||||
},
|
||||
"non-empty config, valid timeout: core.MaxClientIPServiceAffinitySeconds": {
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(int(core.MaxClientIPServiceAffinitySeconds)),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(core.MaxClientIPServiceAffinitySeconds),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -12527,17 +12520,17 @@ func TestValidateOrSetClientIPAffinityConfig(t *testing.T) {
|
||||
},
|
||||
"non-empty config, invalid timeout: core.MaxClientIPServiceAffinitySeconds+1": {
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(int(core.MaxClientIPServiceAffinitySeconds + 1)),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(core.MaxClientIPServiceAffinitySeconds + 1),
|
||||
},
|
||||
},
|
||||
"non-empty config, invalid timeout: -1": {
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(-1),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
"non-empty config, invalid timeout: 0": {
|
||||
ClientIP: &core.ClientIPConfig{
|
||||
TimeoutSeconds: newInt32(0),
|
||||
TimeoutSeconds: utilpointer.Int32Ptr(0),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user