diff --git a/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go b/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go index 5e800970453..0ea88156bef 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go @@ -54,7 +54,7 @@ const ( // FromInt creates an IntOrString object with an int32 value. It is // your responsibility not to call this method with a value greater // than int32. -// TODO: convert to (val int32) +// Deprecated: use FromInt32 instead. func FromInt(val int) IntOrString { if val > math.MaxInt32 || val < math.MinInt32 { klog.Errorf("value: %d overflows int32\n%s\n", val, debug.Stack()) @@ -62,6 +62,11 @@ func FromInt(val int) IntOrString { return IntOrString{Type: Int, IntVal: int32(val)} } +// FromInt32 creates an IntOrString object with an int32 value. +func FromInt32(val int32) IntOrString { + return IntOrString{Type: Int, IntVal: val} +} + // FromString creates an IntOrString object with a string value. func FromString(val string) IntOrString { return IntOrString{Type: String, StrVal: val} diff --git a/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr_test.go b/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr_test.go index a1ad9cb36d8..217d3cf4ecf 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr_test.go @@ -31,6 +31,13 @@ func TestFromInt(t *testing.T) { } } +func TestFromInt32(t *testing.T) { + i := FromInt32(93) + if i.Type != Int || i.IntVal != 93 { + t.Errorf("Expected IntVal=93, got %+v", i) + } +} + func TestFromString(t *testing.T) { i := FromString("76") if i.Type != String || i.StrVal != "76" { @@ -47,7 +54,7 @@ func TestIntOrStringUnmarshalJSON(t *testing.T) { input string result IntOrString }{ - {"{\"val\": 123}", FromInt(123)}, + {"{\"val\": 123}", FromInt32(123)}, {"{\"val\": \"123\"}", FromString("123")}, } @@ -67,7 +74,7 @@ func TestIntOrStringMarshalJSON(t *testing.T) { input IntOrString result string }{ - {FromInt(123), "{\"val\":123}"}, + {FromInt32(123), "{\"val\":123}"}, {FromString("123"), "{\"val\":\"123\"}"}, } @@ -87,7 +94,7 @@ func TestIntOrStringMarshalJSONUnmarshalYAML(t *testing.T) { cases := []struct { input IntOrString }{ - {FromInt(123)}, + {FromInt32(123)}, {FromString("123")}, } @@ -118,7 +125,7 @@ func TestGetIntFromIntOrString(t *testing.T) { expectPerc bool }{ { - input: FromInt(200), + input: FromInt32(200), expectErr: false, expectVal: 200, expectPerc: false, @@ -191,7 +198,7 @@ func TestGetIntFromIntOrPercent(t *testing.T) { expectVal int }{ { - input: FromInt(123), + input: FromInt32(123), expectErr: false, expectVal: 123, },