pkg/util/pointer: Update int
pointer functions
* Implement `Int64Ptr` function * Replace per module functions of `int(32|64)?` --> `*int(32|64)?` * Update bazel rules
This commit is contained in:
@@ -39,6 +39,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 (
|
||||
@@ -1694,7 +1695,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,
|
||||
},
|
||||
{
|
||||
@@ -1728,12 +1729,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,
|
||||
},
|
||||
@@ -1970,14 +1971,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
|
||||
@@ -2464,7 +2457,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "my-secret",
|
||||
DefaultMode: newInt32(0644),
|
||||
DefaultMode: utilpointer.Int32Ptr(0644),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2479,7 +2472,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Items: []core.KeyToPath{{
|
||||
Key: "key",
|
||||
Path: "filename",
|
||||
Mode: newInt32(0644),
|
||||
Mode: utilpointer.Int32Ptr(0644),
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -2549,7 +2542,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "s",
|
||||
DefaultMode: newInt32(01000),
|
||||
DefaultMode: utilpointer.Int32Ptr(01000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2563,7 +2556,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "s",
|
||||
DefaultMode: newInt32(-1),
|
||||
DefaultMode: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2593,7 +2586,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
LocalObjectReference: core.LocalObjectReference{
|
||||
Name: "my-cfgmap",
|
||||
},
|
||||
DefaultMode: newInt32(0644),
|
||||
DefaultMode: utilpointer.Int32Ptr(0644),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2609,7 +2602,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Items: []core.KeyToPath{{
|
||||
Key: "key",
|
||||
Path: "filename",
|
||||
Mode: newInt32(0644),
|
||||
Mode: utilpointer.Int32Ptr(0644),
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -2680,7 +2673,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
ConfigMap: &core.ConfigMapVolumeSource{
|
||||
LocalObjectReference: core.LocalObjectReference{Name: "c"},
|
||||
DefaultMode: newInt32(01000),
|
||||
DefaultMode: utilpointer.Int32Ptr(01000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2694,7 +2687,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
VolumeSource: core.VolumeSource{
|
||||
ConfigMap: &core.ConfigMapVolumeSource{
|
||||
LocalObjectReference: core.LocalObjectReference{Name: "c"},
|
||||
DefaultMode: newInt32(-1),
|
||||
DefaultMode: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -3023,7 +3016,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Name: "downapi",
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
DefaultMode: newInt32(0644),
|
||||
DefaultMode: utilpointer.Int32Ptr(0644),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -3035,7 +3028,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",
|
||||
@@ -3053,7 +3046,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",
|
||||
@@ -3073,7 +3066,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",
|
||||
@@ -3214,7 +3207,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Name: "downapi",
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
DefaultMode: newInt32(01000),
|
||||
DefaultMode: utilpointer.Int32Ptr(01000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -3227,7 +3220,7 @@ func TestValidateVolumes(t *testing.T) {
|
||||
Name: "downapi",
|
||||
VolumeSource: core.VolumeSource{
|
||||
DownwardAPI: &core.DownwardAPIVolumeSource{
|
||||
DefaultMode: newInt32(-1),
|
||||
DefaultMode: utilpointer.Int32Ptr(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -3242,7 +3235,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,
|
||||
},
|
||||
@@ -3269,7 +3262,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,
|
||||
@@ -3287,7 +3280,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,
|
||||
@@ -3322,7 +3315,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,
|
||||
},
|
||||
@@ -8826,7 +8819,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),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -8839,7 +8832,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),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -10334,7 +10327,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),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -12628,17 +12621,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),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -12661,17 +12654,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