Refactor IntOrString into a new pkg

pkg/util/intstr is a cleaner encapsulation for this type and supporting
functions.  No behavioral change.
This commit is contained in:
Tim Hockin 2015-11-09 22:28:45 -08:00
parent 3a07af0b28
commit ba383bcfeb
63 changed files with 676 additions and 656 deletions

View File

@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/workqueue"
"k8s.io/kubernetes/pkg/watch"
@ -408,8 +409,8 @@ func (e *endpointController) checkLeftoverEndpoints() {
// HACK(jdef): return the HostPort in addition to the ContainerPort for generic mesos compatibility
func findPort(pod *api.Pod, svcPort *api.ServicePort) (int, int, error) {
portName := svcPort.TargetPort
switch portName.Kind {
case util.IntstrString:
switch portName.Type {
case intstr.String:
name := portName.StrVal
for _, container := range pod.Spec.Containers {
for _, port := range container.Ports {
@ -419,7 +420,7 @@ func findPort(pod *api.Pod, svcPort *api.ServicePort) (int, int, error) {
}
}
}
case util.IntstrInt:
case intstr.Int:
// HACK(jdef): slightly different semantics from upstream here:
// we ensure that if the user spec'd a port in the service that
// it actually maps to a host-port assigned to the pod. upstream

View File

@ -27,7 +27,7 @@ import (
fields "k8s.io/kubernetes/pkg/fields"
labels "k8s.io/kubernetes/pkg/labels"
runtime "k8s.io/kubernetes/pkg/runtime"
util "k8s.io/kubernetes/pkg/util"
intstr "k8s.io/kubernetes/pkg/util/intstr"
inf "speter.net/go/exp/math/dec/inf"
)
@ -600,7 +600,7 @@ func deepCopy_api_GlusterfsVolumeSource(in GlusterfsVolumeSource, out *Glusterfs
func deepCopy_api_HTTPGetAction(in HTTPGetAction, out *HTTPGetAction, c *conversion.Cloner) error {
out.Path = in.Path
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
out.Host = in.Host
@ -2110,7 +2110,7 @@ func deepCopy_api_ServicePort(in ServicePort, out *ServicePort, c *conversion.Cl
out.Name = in.Name
out.Protocol = in.Protocol
out.Port = in.Port
if err := deepCopy_util_IntOrString(in.TargetPort, &out.TargetPort, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.TargetPort, &out.TargetPort, c); err != nil {
return err
}
out.NodePort = in.NodePort
@ -2159,7 +2159,7 @@ func deepCopy_api_ServiceStatus(in ServiceStatus, out *ServiceStatus, c *convers
}
func deepCopy_api_TCPSocketAction(in TCPSocketAction, out *TCPSocketAction, c *conversion.Cloner) error {
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
return nil
@ -2347,8 +2347,8 @@ func deepCopy_unversioned_TypeMeta(in unversioned.TypeMeta, out *unversioned.Typ
return nil
}
func deepCopy_util_IntOrString(in util.IntOrString, out *util.IntOrString, c *conversion.Cloner) error {
out.Kind = in.Kind
func deepCopy_intstr_IntOrString(in intstr.IntOrString, out *intstr.IntOrString, c *conversion.Cloner) error {
out.Type = in.Type
out.IntVal = in.IntVal
out.StrVal = in.StrVal
return nil
@ -2479,7 +2479,7 @@ func init() {
deepCopy_unversioned_ListMeta,
deepCopy_unversioned_Time,
deepCopy_unversioned_TypeMeta,
deepCopy_util_IntOrString,
deepCopy_intstr_IntOrString,
)
if err != nil {
// if one of the deep copy functions is malformed, detect it immediately.

View File

@ -33,7 +33,7 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"github.com/google/gofuzz"
)
@ -128,10 +128,10 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
} else {
rollingUpdate := extensions.RollingUpdateDeployment{}
if c.RandBool() {
rollingUpdate.MaxUnavailable = util.NewIntOrStringFromInt(int(c.RandUint64()))
rollingUpdate.MaxSurge = util.NewIntOrStringFromInt(int(c.RandUint64()))
rollingUpdate.MaxUnavailable = intstr.FromInt(int(c.RandUint64()))
rollingUpdate.MaxSurge = intstr.FromInt(int(c.RandUint64()))
} else {
rollingUpdate.MaxSurge = util.NewIntOrStringFromString(fmt.Sprintf("%d%%", c.RandUint64()))
rollingUpdate.MaxSurge = intstr.FromString(fmt.Sprintf("%d%%", c.RandUint64()))
}
j.RollingUpdate = &rollingUpdate
}
@ -342,10 +342,10 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
c.Fuzz(&ss.Ports[0])
}
for i := range ss.Ports {
switch ss.Ports[i].TargetPort.Kind {
case util.IntstrInt:
switch ss.Ports[i].TargetPort.Type {
case intstr.Int:
ss.Ports[i].TargetPort.IntVal = 1 + ss.Ports[i].TargetPort.IntVal%65535 // non-zero
case util.IntstrString:
case intstr.String:
ss.Ports[i].TargetPort.StrVal = "x" + ss.Ports[i].TargetPort.StrVal // non-empty
}
}

View File

@ -31,7 +31,7 @@ import (
pkg6_labels "k8s.io/kubernetes/pkg/labels"
pkg8_runtime "k8s.io/kubernetes/pkg/runtime"
pkg1_types "k8s.io/kubernetes/pkg/types"
pkg5_util "k8s.io/kubernetes/pkg/util"
pkg5_intstr "k8s.io/kubernetes/pkg/util/intstr"
"reflect"
"runtime"
pkg4_inf "speter.net/go/exp/math/dec/inf"
@ -66,7 +66,7 @@ func init() {
var v3 pkg6_labels.Selector
var v4 pkg8_runtime.Object
var v5 pkg1_types.UID
var v6 pkg5_util.IntOrString
var v6 pkg5_intstr.IntOrString
var v7 pkg4_inf.Dec
var v8 time.Time
_, _, _, _, _, _, _, _, _ = v0, v1, v2, v3, v4, v5, v6, v7, v8
@ -12423,7 +12423,7 @@ func (x *HTTPGetAction) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
}
case "port":
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv957 := &x.Port
yym958 := z.DecBinary()
@ -12490,7 +12490,7 @@ func (x *HTTPGetAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
return
}
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv963 := &x.Port
yym964 := z.DecBinary()
@ -12691,7 +12691,7 @@ func (x *TCPSocketAction) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
switch yys978 {
case "port":
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv979 := &x.Port
yym980 := z.DecBinary()
@ -12731,7 +12731,7 @@ func (x *TCPSocketAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder)
return
}
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv982 := &x.Port
yym983 := z.DecBinary()
@ -23766,7 +23766,7 @@ func (x *ServicePort) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
}
case "targetPort":
if r.TryDecodeAsNil() {
x.TargetPort = pkg5_util.IntOrString{}
x.TargetPort = pkg5_intstr.IntOrString{}
} else {
yyv1971 := &x.TargetPort
yym1972 := z.DecBinary()
@ -23857,7 +23857,7 @@ func (x *ServicePort) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
return
}
if r.TryDecodeAsNil() {
x.TargetPort = pkg5_util.IntOrString{}
x.TargetPort = pkg5_intstr.IntOrString{}
} else {
yyv1978 := &x.TargetPort
yym1979 := z.DecBinary()

View File

@ -23,7 +23,7 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// Common string formats
@ -681,7 +681,7 @@ type HTTPGetAction struct {
// Optional: Path to access on the HTTP server.
Path string `json:"path,omitempty"`
// Required: Name or number of the port to access on the container.
Port util.IntOrString `json:"port,omitempty"`
Port intstr.IntOrString `json:"port,omitempty"`
// Optional: Host name to connect to, defaults to the pod IP.
Host string `json:"host,omitempty"`
// Optional: Scheme to use for connecting to the host, defaults to HTTP.
@ -701,7 +701,7 @@ const (
// TCPSocketAction describes an action based on opening a socket
type TCPSocketAction struct {
// Required: Port to connect to.
Port util.IntOrString `json:"port,omitempty"`
Port intstr.IntOrString `json:"port,omitempty"`
}
// ExecAction describes a "run in container" action.
@ -1300,7 +1300,7 @@ type ServicePort struct {
// is a string, it will be looked up as a named port in the target
// Pod's container ports. If this is not specified, the default value
// is the sames as the Port field (an identity map).
TargetPort util.IntOrString `json:"targetPort"`
TargetPort intstr.IntOrString `json:"targetPort"`
// The port on each node on which this service is exposed.
// Default is to auto-allocate a port if the ServiceType of this Service requires one.

View File

@ -26,7 +26,7 @@ import (
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
conversion "k8s.io/kubernetes/pkg/conversion"
runtime "k8s.io/kubernetes/pkg/runtime"
util "k8s.io/kubernetes/pkg/util"
intstr "k8s.io/kubernetes/pkg/util/intstr"
inf "speter.net/go/exp/math/dec/inf"
)
@ -634,7 +634,7 @@ func deepCopy_v1_GlusterfsVolumeSource(in GlusterfsVolumeSource, out *GlusterfsV
func deepCopy_v1_HTTPGetAction(in HTTPGetAction, out *HTTPGetAction, c *conversion.Cloner) error {
out.Path = in.Path
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
out.Host = in.Host
@ -2134,7 +2134,7 @@ func deepCopy_v1_ServicePort(in ServicePort, out *ServicePort, c *conversion.Clo
out.Name = in.Name
out.Protocol = in.Protocol
out.Port = in.Port
if err := deepCopy_util_IntOrString(in.TargetPort, &out.TargetPort, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.TargetPort, &out.TargetPort, c); err != nil {
return err
}
out.NodePort = in.NodePort
@ -2191,7 +2191,7 @@ func deepCopy_v1_ServiceStatus(in ServiceStatus, out *ServiceStatus, c *conversi
}
func deepCopy_v1_TCPSocketAction(in TCPSocketAction, out *TCPSocketAction, c *conversion.Cloner) error {
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
return nil
@ -2356,8 +2356,8 @@ func deepCopy_runtime_RawExtension(in runtime.RawExtension, out *runtime.RawExte
return nil
}
func deepCopy_util_IntOrString(in util.IntOrString, out *util.IntOrString, c *conversion.Cloner) error {
out.Kind = in.Kind
func deepCopy_intstr_IntOrString(in intstr.IntOrString, out *intstr.IntOrString, c *conversion.Cloner) error {
out.Type = in.Type
out.IntVal = in.IntVal
out.StrVal = in.StrVal
return nil
@ -2489,7 +2489,7 @@ func init() {
deepCopy_v1_VolumeMount,
deepCopy_v1_VolumeSource,
deepCopy_runtime_RawExtension,
deepCopy_util_IntOrString,
deepCopy_intstr_IntOrString,
)
if err != nil {
// if one of the deep copy functions is malformed, detect it immediately.

View File

@ -21,6 +21,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func addDefaultingFuncs() {
@ -83,8 +84,8 @@ func addDefaultingFuncs() {
if sp.Protocol == "" {
sp.Protocol = ProtocolTCP
}
if sp.TargetPort == util.NewIntOrStringFromInt(0) || sp.TargetPort == util.NewIntOrStringFromString("") {
sp.TargetPort = util.NewIntOrStringFromInt(sp.Port)
if sp.TargetPort == intstr.FromInt(0) || sp.TargetPort == intstr.FromString("") {
sp.TargetPort = intstr.FromInt(sp.Port)
}
}
},

View File

@ -24,7 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
versioned "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
@ -300,14 +300,14 @@ func TestSetDefaulServiceTargetPort(t *testing.T) {
in := &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234}}}}
obj := roundTrip(t, runtime.Object(in))
out := obj.(*versioned.Service)
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) {
if out.Spec.Ports[0].TargetPort != intstr.FromInt(1234) {
t.Errorf("Expected TargetPort to be defaulted, got %v", out.Spec.Ports[0].TargetPort)
}
in = &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}}}
in = &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234, TargetPort: intstr.FromInt(5678)}}}}
obj = roundTrip(t, runtime.Object(in))
out = obj.(*versioned.Service)
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) {
if out.Spec.Ports[0].TargetPort != intstr.FromInt(5678) {
t.Errorf("Expected TargetPort to be unchanged, got %v", out.Spec.Ports[0].TargetPort)
}
}
@ -316,42 +316,42 @@ func TestSetDefaultServicePort(t *testing.T) {
// Unchanged if set.
in := &versioned.Service{Spec: versioned.ServiceSpec{
Ports: []versioned.ServicePort{
{Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")},
{Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)},
{Protocol: "UDP", Port: 9376, TargetPort: intstr.FromString("p")},
{Protocol: "UDP", Port: 8675, TargetPort: intstr.FromInt(309)},
},
}}
out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Spec.Ports[0].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[0].Protocol)
}
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromString("p") {
if out.Spec.Ports[0].TargetPort != intstr.FromString("p") {
t.Errorf("Expected port %v, got %v", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
}
if out.Spec.Ports[1].Protocol != versioned.ProtocolUDP {
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[1].Protocol)
}
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(309) {
if out.Spec.Ports[1].TargetPort != intstr.FromInt(309) {
t.Errorf("Expected port %v, got %v", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
}
// Defaulted.
in = &versioned.Service{Spec: versioned.ServiceSpec{
Ports: []versioned.ServicePort{
{Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")},
{Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)},
{Protocol: "", Port: 9376, TargetPort: intstr.FromString("")},
{Protocol: "", Port: 8675, TargetPort: intstr.FromInt(0)},
},
}}
out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
}
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[0].Port) {
if out.Spec.Ports[0].TargetPort != intstr.FromInt(in.Spec.Ports[0].Port) {
t.Errorf("Expected port %v, got %v", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
}
if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
}
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[1].Port) {
if out.Spec.Ports[1].TargetPort != intstr.FromInt(in.Spec.Ports[1].Port) {
t.Errorf("Expected port %v, got %v", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
}
}

View File

@ -29,7 +29,7 @@ import (
pkg2_unversioned "k8s.io/kubernetes/pkg/api/unversioned"
pkg6_runtime "k8s.io/kubernetes/pkg/runtime"
pkg1_types "k8s.io/kubernetes/pkg/types"
pkg5_util "k8s.io/kubernetes/pkg/util"
pkg5_intstr "k8s.io/kubernetes/pkg/util/intstr"
"reflect"
"runtime"
pkg4_inf "speter.net/go/exp/math/dec/inf"
@ -62,7 +62,7 @@ func init() {
var v1 pkg2_unversioned.Time
var v2 pkg6_runtime.RawExtension
var v3 pkg1_types.UID
var v4 pkg5_util.IntOrString
var v4 pkg5_intstr.IntOrString
var v5 pkg4_inf.Dec
var v6 time.Time
_, _, _, _, _, _, _ = v0, v1, v2, v3, v4, v5, v6
@ -12029,7 +12029,7 @@ func (x *HTTPGetAction) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
}
case "port":
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv928 := &x.Port
yym929 := z.DecBinary()
@ -12096,7 +12096,7 @@ func (x *HTTPGetAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
return
}
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv934 := &x.Port
yym935 := z.DecBinary()
@ -12290,7 +12290,7 @@ func (x *TCPSocketAction) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
switch yys949 {
case "port":
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv950 := &x.Port
yym951 := z.DecBinary()
@ -12330,7 +12330,7 @@ func (x *TCPSocketAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder)
return
}
if r.TryDecodeAsNil() {
x.Port = pkg5_util.IntOrString{}
x.Port = pkg5_intstr.IntOrString{}
} else {
yyv953 := &x.Port
yym954 := z.DecBinary()
@ -23258,7 +23258,7 @@ func (x *ServicePort) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
}
case "targetPort":
if r.TryDecodeAsNil() {
x.TargetPort = pkg5_util.IntOrString{}
x.TargetPort = pkg5_intstr.IntOrString{}
} else {
yyv1926 := &x.TargetPort
yym1927 := z.DecBinary()
@ -23349,7 +23349,7 @@ func (x *ServicePort) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
return
}
if r.TryDecodeAsNil() {
x.TargetPort = pkg5_util.IntOrString{}
x.TargetPort = pkg5_intstr.IntOrString{}
} else {
yyv1933 := &x.TargetPort
yym1934 := z.DecBinary()

View File

@ -21,7 +21,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// The comments for the structs and fields can be used from go-resful to
@ -810,7 +810,7 @@ type HTTPGetAction struct {
// Name or number of the port to access on the container.
// Number must be in the range 1 to 65535.
// Name must be an IANA_SVC_NAME.
Port util.IntOrString `json:"port"`
Port intstr.IntOrString `json:"port"`
// Host name to connect to, defaults to the pod IP.
Host string `json:"host,omitempty"`
// Scheme to use for connecting to the host.
@ -833,7 +833,7 @@ type TCPSocketAction struct {
// Number or name of the port to access on the container.
// Number must be in the range 1 to 65535.
// Name must be an IANA_SVC_NAME.
Port util.IntOrString `json:"port"`
Port intstr.IntOrString `json:"port"`
}
// ExecAction describes a "run in container" action.
@ -1621,7 +1621,7 @@ type ServicePort struct {
// of Port is used (an identity map).
// Defaults to the service port.
// More info: http://releases.k8s.io/HEAD/docs/user-guide/services.md#defining-a-service
TargetPort util.IntOrString `json:"targetPort,omitempty"`
TargetPort intstr.IntOrString `json:"targetPort,omitempty"`
// The port on each node on which this service is exposed when type=NodePort or LoadBalancer.
// Usually assigned by the system. If specified, it will be allocated to the service

View File

@ -30,8 +30,8 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
errs "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/validation"
@ -933,9 +933,9 @@ func validateHTTPGetAction(http *api.HTTPGetAction) errs.ValidationErrorList {
if len(http.Path) == 0 {
allErrors = append(allErrors, errs.NewFieldRequired("path"))
}
if http.Port.Kind == util.IntstrInt && !validation.IsValidPortNum(http.Port.IntVal) {
if http.Port.Type == intstr.Int && !validation.IsValidPortNum(http.Port.IntVal) {
allErrors = append(allErrors, errs.NewFieldInvalid("port", http.Port, PortRangeErrorMsg))
} else if http.Port.Kind == util.IntstrString && !validation.IsValidPortName(http.Port.StrVal) {
} else if http.Port.Type == intstr.String && !validation.IsValidPortName(http.Port.StrVal) {
allErrors = append(allErrors, errs.NewFieldInvalid("port", http.Port.StrVal, PortNameErrorMsg))
}
supportedSchemes := sets.NewString(string(api.URISchemeHTTP), string(api.URISchemeHTTPS))
@ -947,9 +947,9 @@ func validateHTTPGetAction(http *api.HTTPGetAction) errs.ValidationErrorList {
func validateTCPSocketAction(tcp *api.TCPSocketAction) errs.ValidationErrorList {
allErrors := errs.ValidationErrorList{}
if tcp.Port.Kind == util.IntstrInt && !validation.IsValidPortNum(tcp.Port.IntVal) {
if tcp.Port.Type == intstr.Int && !validation.IsValidPortNum(tcp.Port.IntVal) {
allErrors = append(allErrors, errs.NewFieldInvalid("port", tcp.Port, PortRangeErrorMsg))
} else if tcp.Port.Kind == util.IntstrString && !validation.IsValidPortName(tcp.Port.StrVal) {
} else if tcp.Port.Type == intstr.String && !validation.IsValidPortName(tcp.Port.StrVal) {
allErrors = append(allErrors, errs.NewFieldInvalid("port", tcp.Port.StrVal, PortNameErrorMsg))
}
return allErrors
@ -1334,10 +1334,10 @@ func validateServicePort(sp *api.ServicePort, requireName bool, allNames *sets.S
allErrs = append(allErrs, errs.NewFieldValueNotSupported("protocol", sp.Protocol, supportedPortProtocols.List()))
}
if sp.TargetPort.Kind == util.IntstrInt && !validation.IsValidPortNum(sp.TargetPort.IntVal) {
if sp.TargetPort.Type == intstr.Int && !validation.IsValidPortNum(sp.TargetPort.IntVal) {
allErrs = append(allErrs, errs.NewFieldInvalid("targetPort", sp.TargetPort, PortRangeErrorMsg))
}
if sp.TargetPort.Kind == util.IntstrString && !validation.IsValidPortName(sp.TargetPort.StrVal) {
if sp.TargetPort.Type == intstr.String && !validation.IsValidPortName(sp.TargetPort.StrVal) {
allErrs = append(allErrs, errs.NewFieldInvalid("targetPort", sp.TargetPort, PortNameErrorMsg))
}

View File

@ -28,10 +28,10 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/util"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/fielderrors"
errors "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
)
@ -839,9 +839,9 @@ func TestValidateProbe(t *testing.T) {
func TestValidateHandler(t *testing.T) {
successCases := []api.Handler{
{Exec: &api.ExecAction{Command: []string{"echo"}}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: util.NewIntOrStringFromInt(1), Host: "", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/foo", Port: util.NewIntOrStringFromInt(65535), Host: "host", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: util.NewIntOrStringFromString("port"), Host: "", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: intstr.FromInt(1), Host: "", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/foo", Port: intstr.FromInt(65535), Host: "host", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: intstr.FromString("port"), Host: "", Scheme: "HTTP"}},
}
for _, h := range successCases {
if errs := validateHandler(&h); len(errs) != 0 {
@ -852,9 +852,9 @@ func TestValidateHandler(t *testing.T) {
errorCases := []api.Handler{
{},
{Exec: &api.ExecAction{Command: []string{}}},
{HTTPGet: &api.HTTPGetAction{Path: "", Port: util.NewIntOrStringFromInt(0), Host: ""}},
{HTTPGet: &api.HTTPGetAction{Path: "/foo", Port: util.NewIntOrStringFromInt(65536), Host: "host"}},
{HTTPGet: &api.HTTPGetAction{Path: "", Port: util.NewIntOrStringFromString(""), Host: ""}},
{HTTPGet: &api.HTTPGetAction{Path: "", Port: intstr.FromInt(0), Host: ""}},
{HTTPGet: &api.HTTPGetAction{Path: "/foo", Port: intstr.FromInt(65536), Host: "host"}},
{HTTPGet: &api.HTTPGetAction{Path: "", Port: intstr.FromString(""), Host: ""}},
}
for _, h := range errorCases {
if errs := validateHandler(&h); len(errs) == 0 {
@ -1084,7 +1084,7 @@ func TestValidateContainers(t *testing.T) {
Lifecycle: &api.Lifecycle{
PreStop: &api.Handler{
TCPSocket: &api.TCPSocketAction{
Port: util.IntOrString{IntVal: 0},
Port: intstr.FromInt(0),
},
},
},
@ -1688,7 +1688,7 @@ func makeValidService() api.Service {
Selector: map[string]string{"key": "val"},
SessionAffinity: "None",
Type: api.ServiceTypeClusterIP,
Ports: []api.ServicePort{{Name: "p", Protocol: "TCP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(8675)}},
Ports: []api.ServicePort{{Name: "p", Protocol: "TCP", Port: 8675, TargetPort: intstr.FromInt(8675)}},
},
}
}
@ -1815,7 +1815,7 @@ func TestValidateService(t *testing.T) {
{
name: "empty port[1] name",
tweakSvc: func(s *api.Service) {
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "", Protocol: "TCP", Port: 12345, TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "", Protocol: "TCP", Port: 12345, TargetPort: intstr.FromInt(12345)})
},
numErrs: 1,
},
@ -1823,7 +1823,7 @@ func TestValidateService(t *testing.T) {
name: "empty multi-port port[0] name",
tweakSvc: func(s *api.Service) {
s.Spec.Ports[0].Name = ""
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Protocol: "TCP", Port: 12345, TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Protocol: "TCP", Port: 12345, TargetPort: intstr.FromInt(12345)})
},
numErrs: 1,
},
@ -1872,7 +1872,7 @@ func TestValidateService(t *testing.T) {
{
name: "invalid TargetPort int",
tweakSvc: func(s *api.Service) {
s.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(65536)
s.Spec.Ports[0].TargetPort = intstr.FromInt(65536)
},
numErrs: 1,
},
@ -1901,7 +1901,7 @@ func TestValidateService(t *testing.T) {
name: "dup port name",
tweakSvc: func(s *api.Service) {
s.Spec.Ports[0].Name = "p"
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 1,
},
@ -1917,7 +1917,7 @@ func TestValidateService(t *testing.T) {
name: "invalid load balancer protocol 2",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "UDP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "UDP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 1,
},
@ -1932,14 +1932,14 @@ func TestValidateService(t *testing.T) {
name: "valid 2",
tweakSvc: func(s *api.Service) {
s.Spec.Ports[0].Protocol = "UDP"
s.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(12345)
s.Spec.Ports[0].TargetPort = intstr.FromInt(12345)
},
numErrs: 0,
},
{
name: "valid 3",
tweakSvc: func(s *api.Service) {
s.Spec.Ports[0].TargetPort = util.NewIntOrStringFromString("http")
s.Spec.Ports[0].TargetPort = intstr.FromString("http")
},
numErrs: 0,
},
@ -1954,7 +1954,7 @@ func TestValidateService(t *testing.T) {
name: "valid cluster ip - empty",
tweakSvc: func(s *api.Service) {
s.Spec.ClusterIP = ""
s.Spec.Ports[0].TargetPort = util.NewIntOrStringFromString("http")
s.Spec.Ports[0].TargetPort = intstr.FromString("http")
},
numErrs: 0,
},
@ -1976,7 +1976,7 @@ func TestValidateService(t *testing.T) {
name: "valid type loadbalancer 2 ports",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -1984,7 +1984,7 @@ func TestValidateService(t *testing.T) {
name: "valid external load balancer 2 ports",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -1992,8 +1992,8 @@ func TestValidateService(t *testing.T) {
name: "duplicate nodeports",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeNodePort
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: util.NewIntOrStringFromInt(1)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "TCP", NodePort: 1, TargetPort: util.NewIntOrStringFromInt(2)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(1)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(2)})
},
numErrs: 1,
},
@ -2001,8 +2001,8 @@ func TestValidateService(t *testing.T) {
name: "duplicate nodeports (different protocols)",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeNodePort
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: util.NewIntOrStringFromInt(1)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "UDP", NodePort: 1, TargetPort: util.NewIntOrStringFromInt(2)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(1)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "UDP", NodePort: 1, TargetPort: intstr.FromInt(2)})
},
numErrs: 0,
},
@ -2031,7 +2031,7 @@ func TestValidateService(t *testing.T) {
name: "valid type loadbalancer 2 ports",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -2039,7 +2039,7 @@ func TestValidateService(t *testing.T) {
name: "valid type loadbalancer with NodePort",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", NodePort: 12345, TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", NodePort: 12345, TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -2047,7 +2047,7 @@ func TestValidateService(t *testing.T) {
name: "valid type=NodePort service with NodePort",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeNodePort
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", NodePort: 12345, TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", NodePort: 12345, TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -2055,7 +2055,7 @@ func TestValidateService(t *testing.T) {
name: "valid type=NodePort service without NodePort",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeNodePort
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -2063,7 +2063,7 @@ func TestValidateService(t *testing.T) {
name: "valid cluster service without NodePort",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -2071,7 +2071,7 @@ func TestValidateService(t *testing.T) {
name: "invalid cluster service with NodePort",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", NodePort: 12345, TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", NodePort: 12345, TargetPort: intstr.FromInt(12345)})
},
numErrs: 1,
},
@ -2079,8 +2079,8 @@ func TestValidateService(t *testing.T) {
name: "invalid public service with duplicate NodePort",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeNodePort
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p1", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: util.NewIntOrStringFromInt(1)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p2", Port: 2, Protocol: "TCP", NodePort: 1, TargetPort: util.NewIntOrStringFromInt(2)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p1", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(1)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p2", Port: 2, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(2)})
},
numErrs: 1,
},
@ -2088,7 +2088,7 @@ func TestValidateService(t *testing.T) {
name: "valid type=LoadBalancer",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 0,
},
@ -2098,7 +2098,7 @@ func TestValidateService(t *testing.T) {
name: "invalid port type=LoadBalancer",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeLoadBalancer
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "kubelet", Port: 10250, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(12345)})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "kubelet", Port: 10250, Protocol: "TCP", TargetPort: intstr.FromInt(12345)})
},
numErrs: 1,
},

View File

@ -25,7 +25,7 @@ import (
resource "k8s.io/kubernetes/pkg/api/resource"
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
conversion "k8s.io/kubernetes/pkg/conversion"
util "k8s.io/kubernetes/pkg/util"
intstr "k8s.io/kubernetes/pkg/util/intstr"
inf "speter.net/go/exp/math/dec/inf"
)
@ -302,7 +302,7 @@ func deepCopy_api_GlusterfsVolumeSource(in api.GlusterfsVolumeSource, out *api.G
func deepCopy_api_HTTPGetAction(in api.HTTPGetAction, out *api.HTTPGetAction, c *conversion.Cloner) error {
out.Path = in.Path
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
out.Host = in.Host
@ -695,7 +695,7 @@ func deepCopy_api_SecurityContext(in api.SecurityContext, out *api.SecurityConte
}
func deepCopy_api_TCPSocketAction(in api.TCPSocketAction, out *api.TCPSocketAction, c *conversion.Cloner) error {
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
return nil
@ -1205,7 +1205,7 @@ func deepCopy_extensions_Ingress(in Ingress, out *Ingress, c *conversion.Cloner)
func deepCopy_extensions_IngressBackend(in IngressBackend, out *IngressBackend, c *conversion.Cloner) error {
out.ServiceName = in.ServiceName
if err := deepCopy_util_IntOrString(in.ServicePort, &out.ServicePort, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.ServicePort, &out.ServicePort, c); err != nil {
return err
}
return nil
@ -1440,10 +1440,10 @@ func deepCopy_extensions_ReplicationControllerDummy(in ReplicationControllerDumm
}
func deepCopy_extensions_RollingUpdateDeployment(in RollingUpdateDeployment, out *RollingUpdateDeployment, c *conversion.Cloner) error {
if err := deepCopy_util_IntOrString(in.MaxUnavailable, &out.MaxUnavailable, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.MaxUnavailable, &out.MaxUnavailable, c); err != nil {
return err
}
if err := deepCopy_util_IntOrString(in.MaxSurge, &out.MaxSurge, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.MaxSurge, &out.MaxSurge, c); err != nil {
return err
}
out.MinReadySeconds = in.MinReadySeconds
@ -1571,8 +1571,8 @@ func deepCopy_extensions_ThirdPartyResourceList(in ThirdPartyResourceList, out *
return nil
}
func deepCopy_util_IntOrString(in util.IntOrString, out *util.IntOrString, c *conversion.Cloner) error {
out.Kind = in.Kind
func deepCopy_intstr_IntOrString(in intstr.IntOrString, out *intstr.IntOrString, c *conversion.Cloner) error {
out.Type = in.Type
out.IntVal = in.IntVal
out.StrVal = in.StrVal
return nil
@ -1671,7 +1671,7 @@ func init() {
deepCopy_extensions_ThirdPartyResourceData,
deepCopy_extensions_ThirdPartyResourceDataList,
deepCopy_extensions_ThirdPartyResourceList,
deepCopy_util_IntOrString,
deepCopy_intstr_IntOrString,
)
if err != nil {
// if one of the deep copy functions is malformed, detect it immediately.

View File

@ -29,7 +29,7 @@ import (
pkg4_resource "k8s.io/kubernetes/pkg/api/resource"
pkg1_unversioned "k8s.io/kubernetes/pkg/api/unversioned"
pkg3_types "k8s.io/kubernetes/pkg/types"
pkg6_util "k8s.io/kubernetes/pkg/util"
pkg6_intstr "k8s.io/kubernetes/pkg/util/intstr"
"reflect"
"runtime"
pkg5_inf "speter.net/go/exp/math/dec/inf"
@ -62,7 +62,7 @@ func init() {
var v1 pkg4_resource.Quantity
var v2 pkg1_unversioned.TypeMeta
var v3 pkg3_types.UID
var v4 pkg6_util.IntOrString
var v4 pkg6_intstr.IntOrString
var v5 pkg5_inf.Dec
var v6 time.Time
_, _, _, _, _, _, _ = v0, v1, v2, v3, v4, v5, v6
@ -5014,7 +5014,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromMap(l int, d *codec1978.Dec
switch yys450 {
case "maxUnavailable":
if r.TryDecodeAsNil() {
x.MaxUnavailable = pkg6_util.IntOrString{}
x.MaxUnavailable = pkg6_intstr.IntOrString{}
} else {
yyv451 := &x.MaxUnavailable
yym452 := z.DecBinary()
@ -5029,7 +5029,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromMap(l int, d *codec1978.Dec
}
case "maxSurge":
if r.TryDecodeAsNil() {
x.MaxSurge = pkg6_util.IntOrString{}
x.MaxSurge = pkg6_intstr.IntOrString{}
} else {
yyv453 := &x.MaxSurge
yym454 := z.DecBinary()
@ -5075,7 +5075,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromArray(l int, d *codec1978.D
return
}
if r.TryDecodeAsNil() {
x.MaxUnavailable = pkg6_util.IntOrString{}
x.MaxUnavailable = pkg6_intstr.IntOrString{}
} else {
yyv457 := &x.MaxUnavailable
yym458 := z.DecBinary()
@ -5099,7 +5099,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromArray(l int, d *codec1978.D
return
}
if r.TryDecodeAsNil() {
x.MaxSurge = pkg6_util.IntOrString{}
x.MaxSurge = pkg6_intstr.IntOrString{}
} else {
yyv459 := &x.MaxSurge
yym460 := z.DecBinary()
@ -10916,7 +10916,7 @@ func (x *IngressBackend) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
}
case "servicePort":
if r.TryDecodeAsNil() {
x.ServicePort = pkg6_util.IntOrString{}
x.ServicePort = pkg6_intstr.IntOrString{}
} else {
yyv975 := &x.ServicePort
yym976 := z.DecBinary()
@ -10971,7 +10971,7 @@ func (x *IngressBackend) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
return
}
if r.TryDecodeAsNil() {
x.ServicePort = pkg6_util.IntOrString{}
x.ServicePort = pkg6_intstr.IntOrString{}
} else {
yyv979 := &x.ServicePort
yym980 := z.DecBinary()

View File

@ -31,7 +31,7 @@ package extensions
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// describes the attributes of a scale subresource
@ -256,7 +256,7 @@ type RollingUpdateDeployment struct {
// can be scaled down further, followed by scaling up the new RC, ensuring
// that at least 70% of original number of pods are available at all times
// during the update.
MaxUnavailable util.IntOrString `json:"maxUnavailable,omitempty"`
MaxUnavailable intstr.IntOrString `json:"maxUnavailable,omitempty"`
// The maximum number of pods that can be scheduled above the original number of
// pods.
@ -268,7 +268,7 @@ type RollingUpdateDeployment struct {
// immediately when the rolling update starts. Once old pods have been killed,
// new RC can be scaled up further, ensuring that total number of pods running
// at any time during the update is atmost 130% of original pods.
MaxSurge util.IntOrString `json:"maxSurge,omitempty"`
MaxSurge intstr.IntOrString `json:"maxSurge,omitempty"`
// Minimum number of seconds for which a newly created pod should be ready
// without any of its container crashing, for it to be considered available.
@ -583,7 +583,7 @@ type IngressBackend struct {
ServiceName string `json:"serviceName"`
// Specifies the port of the referenced service.
ServicePort util.IntOrString `json:"servicePort"`
ServicePort intstr.IntOrString `json:"servicePort"`
}
type NodeResource string

View File

@ -23,7 +23,7 @@ import (
v1 "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func addConversionFuncs() {
@ -288,13 +288,13 @@ func convert_extensions_RollingUpdateDeployment_To_v1beta1_RollingUpdateDeployme
defaulting.(func(*extensions.RollingUpdateDeployment))(in)
}
if out.MaxUnavailable == nil {
out.MaxUnavailable = &util.IntOrString{}
out.MaxUnavailable = &intstr.IntOrString{}
}
if err := s.Convert(&in.MaxUnavailable, out.MaxUnavailable, 0); err != nil {
return err
}
if out.MaxSurge == nil {
out.MaxSurge = &util.IntOrString{}
out.MaxSurge = &intstr.IntOrString{}
}
if err := s.Convert(&in.MaxSurge, out.MaxSurge, 0); err != nil {
return err

View File

@ -26,7 +26,7 @@ import (
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
v1 "k8s.io/kubernetes/pkg/api/v1"
conversion "k8s.io/kubernetes/pkg/conversion"
util "k8s.io/kubernetes/pkg/util"
intstr "k8s.io/kubernetes/pkg/util/intstr"
inf "speter.net/go/exp/math/dec/inf"
)
@ -338,7 +338,7 @@ func deepCopy_v1_GlusterfsVolumeSource(in v1.GlusterfsVolumeSource, out *v1.Glus
func deepCopy_v1_HTTPGetAction(in v1.HTTPGetAction, out *v1.HTTPGetAction, c *conversion.Cloner) error {
out.Path = in.Path
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
out.Host = in.Host
@ -732,7 +732,7 @@ func deepCopy_v1_SecurityContext(in v1.SecurityContext, out *v1.SecurityContext,
}
func deepCopy_v1_TCPSocketAction(in v1.TCPSocketAction, out *v1.TCPSocketAction, c *conversion.Cloner) error {
if err := deepCopy_util_IntOrString(in.Port, &out.Port, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.Port, &out.Port, c); err != nil {
return err
}
return nil
@ -1217,7 +1217,7 @@ func deepCopy_v1beta1_Ingress(in Ingress, out *Ingress, c *conversion.Cloner) er
func deepCopy_v1beta1_IngressBackend(in IngressBackend, out *IngressBackend, c *conversion.Cloner) error {
out.ServiceName = in.ServiceName
if err := deepCopy_util_IntOrString(in.ServicePort, &out.ServicePort, c); err != nil {
if err := deepCopy_intstr_IntOrString(in.ServicePort, &out.ServicePort, c); err != nil {
return err
}
return nil
@ -1453,16 +1453,16 @@ func deepCopy_v1beta1_ReplicationControllerDummy(in ReplicationControllerDummy,
func deepCopy_v1beta1_RollingUpdateDeployment(in RollingUpdateDeployment, out *RollingUpdateDeployment, c *conversion.Cloner) error {
if in.MaxUnavailable != nil {
out.MaxUnavailable = new(util.IntOrString)
if err := deepCopy_util_IntOrString(*in.MaxUnavailable, out.MaxUnavailable, c); err != nil {
out.MaxUnavailable = new(intstr.IntOrString)
if err := deepCopy_intstr_IntOrString(*in.MaxUnavailable, out.MaxUnavailable, c); err != nil {
return err
}
} else {
out.MaxUnavailable = nil
}
if in.MaxSurge != nil {
out.MaxSurge = new(util.IntOrString)
if err := deepCopy_util_IntOrString(*in.MaxSurge, out.MaxSurge, c); err != nil {
out.MaxSurge = new(intstr.IntOrString)
if err := deepCopy_intstr_IntOrString(*in.MaxSurge, out.MaxSurge, c); err != nil {
return err
}
} else {
@ -1593,8 +1593,8 @@ func deepCopy_v1beta1_ThirdPartyResourceList(in ThirdPartyResourceList, out *Thi
return nil
}
func deepCopy_util_IntOrString(in util.IntOrString, out *util.IntOrString, c *conversion.Cloner) error {
out.Kind = in.Kind
func deepCopy_intstr_IntOrString(in intstr.IntOrString, out *intstr.IntOrString, c *conversion.Cloner) error {
out.Type = in.Type
out.IntVal = in.IntVal
out.StrVal = in.StrVal
return nil
@ -1693,7 +1693,7 @@ func init() {
deepCopy_v1beta1_ThirdPartyResourceData,
deepCopy_v1beta1_ThirdPartyResourceDataList,
deepCopy_v1beta1_ThirdPartyResourceList,
deepCopy_util_IntOrString,
deepCopy_intstr_IntOrString,
)
if err != nil {
// if one of the deep copy functions is malformed, detect it immediately.

View File

@ -18,7 +18,7 @@ package v1beta1
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func addDefaultingFuncs() {
@ -74,12 +74,12 @@ func addDefaultingFuncs() {
}
if strategy.RollingUpdate.MaxUnavailable == nil {
// Set default MaxUnavailable as 1 by default.
maxUnavailable := util.NewIntOrStringFromInt(1)
maxUnavailable := intstr.FromInt(1)
strategy.RollingUpdate.MaxUnavailable = &maxUnavailable
}
if strategy.RollingUpdate.MaxSurge == nil {
// Set default MaxSurge as 1 by default.
maxSurge := util.NewIntOrStringFromInt(1)
maxSurge := intstr.FromInt(1)
strategy.RollingUpdate.MaxSurge = &maxSurge
}
}

View File

@ -23,7 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestSetDefaultDaemonSet(t *testing.T) {
@ -85,8 +85,8 @@ func TestSetDefaultDaemonSet(t *testing.T) {
}
func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := util.NewIntOrStringFromInt(1)
differentIntOrString := util.NewIntOrStringFromInt(5)
defaultIntOrString := intstr.FromInt(1)
differentIntOrString := intstr.FromInt(5)
deploymentLabelKey := "deployment.kubernetes.io/podTemplateHash"
period := int64(v1.DefaultTerminationGracePeriodSeconds)
defaultTemplate := v1.PodTemplateSpec{

View File

@ -29,7 +29,7 @@ import (
pkg1_unversioned "k8s.io/kubernetes/pkg/api/unversioned"
pkg2_v1 "k8s.io/kubernetes/pkg/api/v1"
pkg3_types "k8s.io/kubernetes/pkg/types"
pkg6_util "k8s.io/kubernetes/pkg/util"
pkg6_intstr "k8s.io/kubernetes/pkg/util/intstr"
"reflect"
"runtime"
pkg5_inf "speter.net/go/exp/math/dec/inf"
@ -62,7 +62,7 @@ func init() {
var v1 pkg1_unversioned.TypeMeta
var v2 pkg2_v1.ObjectMeta
var v3 pkg3_types.UID
var v4 pkg6_util.IntOrString
var v4 pkg6_intstr.IntOrString
var v5 pkg5_inf.Dec
var v6 time.Time
_, _, _, _, _, _, _ = v0, v1, v2, v3, v4, v5, v6
@ -5091,7 +5091,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromMap(l int, d *codec1978.Dec
}
} else {
if x.MaxUnavailable == nil {
x.MaxUnavailable = new(pkg6_util.IntOrString)
x.MaxUnavailable = new(pkg6_intstr.IntOrString)
}
yym456 := z.DecBinary()
_ = yym456
@ -5110,7 +5110,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromMap(l int, d *codec1978.Dec
}
} else {
if x.MaxSurge == nil {
x.MaxSurge = new(pkg6_util.IntOrString)
x.MaxSurge = new(pkg6_intstr.IntOrString)
}
yym458 := z.DecBinary()
_ = yym458
@ -5160,7 +5160,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromArray(l int, d *codec1978.D
}
} else {
if x.MaxUnavailable == nil {
x.MaxUnavailable = new(pkg6_util.IntOrString)
x.MaxUnavailable = new(pkg6_intstr.IntOrString)
}
yym462 := z.DecBinary()
_ = yym462
@ -5188,7 +5188,7 @@ func (x *RollingUpdateDeployment) codecDecodeSelfFromArray(l int, d *codec1978.D
}
} else {
if x.MaxSurge == nil {
x.MaxSurge = new(pkg6_util.IntOrString)
x.MaxSurge = new(pkg6_intstr.IntOrString)
}
yym464 := z.DecBinary()
_ = yym464
@ -11004,7 +11004,7 @@ func (x *IngressBackend) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
}
case "servicePort":
if r.TryDecodeAsNil() {
x.ServicePort = pkg6_util.IntOrString{}
x.ServicePort = pkg6_intstr.IntOrString{}
} else {
yyv979 := &x.ServicePort
yym980 := z.DecBinary()
@ -11059,7 +11059,7 @@ func (x *IngressBackend) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
return
}
if r.TryDecodeAsNil() {
x.ServicePort = pkg6_util.IntOrString{}
x.ServicePort = pkg6_intstr.IntOrString{}
} else {
yyv983 := &x.ServicePort
yym984 := z.DecBinary()

View File

@ -19,7 +19,7 @@ package v1beta1
import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// describes the attributes of a scale subresource
@ -250,7 +250,7 @@ type RollingUpdateDeployment struct {
// can be scaled down further, followed by scaling up the new RC, ensuring
// that the total number of pods available at all times during the update is at
// least 70% of desired pods.
MaxUnavailable *util.IntOrString `json:"maxUnavailable,omitempty"`
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
// The maximum number of pods that can be scheduled above the desired number of
// pods.
@ -263,7 +263,7 @@ type RollingUpdateDeployment struct {
// 130% of desired pods. Once old pods have been killed,
// new RC can be scaled up further, ensuring that total number of pods running
// at any time during the update is atmost 130% of desired pods.
MaxSurge *util.IntOrString `json:"maxSurge,omitempty"`
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
// Minimum number of seconds for which a newly created pod should be ready
// without any of its container crashing, for it to be considered available.
@ -591,7 +591,7 @@ type IngressBackend struct {
ServiceName string `json:"serviceName"`
// Specifies the port of the referenced service.
ServicePort util.IntOrString `json:"servicePort"`
ServicePort intstr.IntOrString `json:"servicePort"`
}
type NodeResource string

View File

@ -27,8 +27,8 @@ import (
apivalidation "k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
errs "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/validation"
utilvalidation "k8s.io/kubernetes/pkg/util/validation"
@ -220,27 +220,27 @@ func ValidateDeploymentName(name string, prefix bool) (bool, string) {
return apivalidation.NameIsDNSSubdomain(name, prefix)
}
func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName string) errs.ValidationErrorList {
func ValidatePositiveIntOrPercent(intOrPercent intstr.IntOrString, fieldName string) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if intOrPercent.Kind == util.IntstrString {
if intOrPercent.Type == intstr.String {
if !validation.IsValidPercent(intOrPercent.StrVal) {
allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, intOrPercent, "value should be int(5) or percentage(5%)"))
}
} else if intOrPercent.Kind == util.IntstrInt {
} else if intOrPercent.Type == intstr.Int {
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(intOrPercent.IntVal), fieldName)...)
}
return allErrs
}
func getPercentValue(intOrStringValue util.IntOrString) (int, bool) {
if intOrStringValue.Kind != util.IntstrString || !validation.IsValidPercent(intOrStringValue.StrVal) {
func getPercentValue(intOrStringValue intstr.IntOrString) (int, bool) {
if intOrStringValue.Type != intstr.String || !validation.IsValidPercent(intOrStringValue.StrVal) {
return 0, false
}
value, _ := strconv.Atoi(intOrStringValue.StrVal[:len(intOrStringValue.StrVal)-1])
return value, true
}
func getIntOrPercentValue(intOrStringValue util.IntOrString) int {
func getIntOrPercentValue(intOrStringValue intstr.IntOrString) int {
value, isPercent := getPercentValue(intOrStringValue)
if isPercent {
return value
@ -248,7 +248,7 @@ func getIntOrPercentValue(intOrStringValue util.IntOrString) int {
return intOrStringValue.IntVal
}
func IsNotMoreThan100Percent(intOrStringValue util.IntOrString, fieldName string) errs.ValidationErrorList {
func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fieldName string) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
value, isPercent := getPercentValue(intOrStringValue)
if !isPercent || value <= 100 {
@ -511,7 +511,7 @@ func validateIngressBackend(backend *extensions.IngressBackend) errs.ValidationE
} else if ok, errMsg := apivalidation.ValidateServiceName(backend.ServiceName, false); !ok {
allErrs = append(allErrs, errs.NewFieldInvalid("serviceName", backend.ServiceName, errMsg))
}
if backend.ServicePort.Kind == util.IntstrString {
if backend.ServicePort.Type == intstr.String {
if !utilvalidation.IsDNS1123Label(backend.ServicePort.StrVal) {
allErrs = append(allErrs, errs.NewFieldInvalid("servicePort", backend.ServicePort.StrVal, apivalidation.DNS1123LabelErrorMsg))
}

View File

@ -23,8 +23,8 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/util"
errors "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestValidateHorizontalPodAutoscaler(t *testing.T) {
@ -772,7 +772,7 @@ func TestValidateDeployment(t *testing.T) {
invalidMaxSurgeDeployment.Spec.Strategy = extensions.DeploymentStrategy{
Type: extensions.RollingUpdateDeploymentStrategyType,
RollingUpdate: &extensions.RollingUpdateDeployment{
MaxSurge: util.NewIntOrStringFromString("20Percent"),
MaxSurge: intstr.FromString("20Percent"),
},
}
errorCases["value should be int(5) or percentage(5%)"] = invalidMaxSurgeDeployment
@ -782,8 +782,8 @@ func TestValidateDeployment(t *testing.T) {
invalidRollingUpdateDeployment.Spec.Strategy = extensions.DeploymentStrategy{
Type: extensions.RollingUpdateDeploymentStrategyType,
RollingUpdate: &extensions.RollingUpdateDeployment{
MaxSurge: util.NewIntOrStringFromString("0%"),
MaxUnavailable: util.NewIntOrStringFromInt(0),
MaxSurge: intstr.FromString("0%"),
MaxUnavailable: intstr.FromInt(0),
},
}
errorCases["cannot be 0 when maxSurge is 0 as well"] = invalidRollingUpdateDeployment
@ -793,7 +793,7 @@ func TestValidateDeployment(t *testing.T) {
invalidMaxUnavailableDeployment.Spec.Strategy = extensions.DeploymentStrategy{
Type: extensions.RollingUpdateDeploymentStrategyType,
RollingUpdate: &extensions.RollingUpdateDeployment{
MaxUnavailable: util.NewIntOrStringFromString("110%"),
MaxUnavailable: intstr.FromString("110%"),
},
}
errorCases["should not be more than 100%"] = invalidMaxUnavailableDeployment
@ -931,7 +931,7 @@ type ingressRules map[string]string
func TestValidateIngress(t *testing.T) {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
ServicePort: intstr.FromInt(80),
}
newValid := func() extensions.Ingress {
@ -943,7 +943,7 @@ func TestValidateIngress(t *testing.T) {
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
ServicePort: intstr.FromInt(80),
},
Rules: []extensions.IngressRule{
{
@ -1030,7 +1030,7 @@ func TestValidateIngress(t *testing.T) {
func TestValidateIngressStatusUpdate(t *testing.T) {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
ServicePort: intstr.FromInt(80),
}
newValid := func() extensions.Ingress {
@ -1043,7 +1043,7 @@ func TestValidateIngressStatusUpdate(t *testing.T) {
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
ServicePort: intstr.FromInt(80),
},
Rules: []extensions.IngressRule{
{

View File

@ -38,6 +38,7 @@ import (
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/httpstream"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/watch"
watchjson "k8s.io/kubernetes/pkg/watch/json"
)
@ -697,7 +698,7 @@ func TestDoRequestNewWay(t *testing.T) {
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
@ -828,7 +829,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
@ -870,7 +871,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
@ -926,7 +927,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
@ -973,7 +974,7 @@ func TestWasCreated(t *testing.T) {
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
TargetPort: intstr.FromInt(12345),
}}}}
expectedBody, _ := testapi.Default.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{

View File

@ -25,13 +25,13 @@ import (
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestDeploymentController_reconcileNewRC(t *testing.T) {
tests := []struct {
deploymentReplicas int
maxSurge util.IntOrString
maxSurge intstr.IntOrString
oldReplicas int
newReplicas int
scaleExpected bool
@ -40,14 +40,14 @@ func TestDeploymentController_reconcileNewRC(t *testing.T) {
{
// Should not scale up.
deploymentReplicas: 10,
maxSurge: util.NewIntOrStringFromInt(0),
maxSurge: intstr.FromInt(0),
oldReplicas: 10,
newReplicas: 0,
scaleExpected: false,
},
{
deploymentReplicas: 10,
maxSurge: util.NewIntOrStringFromInt(2),
maxSurge: intstr.FromInt(2),
oldReplicas: 10,
newReplicas: 0,
scaleExpected: true,
@ -55,7 +55,7 @@ func TestDeploymentController_reconcileNewRC(t *testing.T) {
},
{
deploymentReplicas: 10,
maxSurge: util.NewIntOrStringFromInt(2),
maxSurge: intstr.FromInt(2),
oldReplicas: 5,
newReplicas: 0,
scaleExpected: true,
@ -63,7 +63,7 @@ func TestDeploymentController_reconcileNewRC(t *testing.T) {
},
{
deploymentReplicas: 10,
maxSurge: util.NewIntOrStringFromInt(2),
maxSurge: intstr.FromInt(2),
oldReplicas: 10,
newReplicas: 2,
scaleExpected: false,
@ -71,7 +71,7 @@ func TestDeploymentController_reconcileNewRC(t *testing.T) {
{
// Should scale down.
deploymentReplicas: 10,
maxSurge: util.NewIntOrStringFromInt(2),
maxSurge: intstr.FromInt(2),
oldReplicas: 2,
newReplicas: 11,
scaleExpected: true,
@ -84,7 +84,7 @@ func TestDeploymentController_reconcileNewRC(t *testing.T) {
newRc := rc("foo-v2", test.newReplicas)
oldRc := rc("foo-v2", test.oldReplicas)
allRcs := []*api.ReplicationController{newRc, oldRc}
deployment := deployment("foo", test.deploymentReplicas, test.maxSurge, util.NewIntOrStringFromInt(0))
deployment := deployment("foo", test.deploymentReplicas, test.maxSurge, intstr.FromInt(0))
fake := &testclient.Fake{}
controller := &DeploymentController{
client: fake,
@ -119,7 +119,7 @@ func TestDeploymentController_reconcileNewRC(t *testing.T) {
func TestDeploymentController_reconcileOldRCs(t *testing.T) {
tests := []struct {
deploymentReplicas int
maxUnavailable util.IntOrString
maxUnavailable intstr.IntOrString
readyPods int
oldReplicas int
scaleExpected bool
@ -127,14 +127,14 @@ func TestDeploymentController_reconcileOldRCs(t *testing.T) {
}{
{
deploymentReplicas: 10,
maxUnavailable: util.NewIntOrStringFromInt(0),
maxUnavailable: intstr.FromInt(0),
readyPods: 10,
oldReplicas: 10,
scaleExpected: false,
},
{
deploymentReplicas: 10,
maxUnavailable: util.NewIntOrStringFromInt(2),
maxUnavailable: intstr.FromInt(2),
readyPods: 10,
oldReplicas: 10,
scaleExpected: true,
@ -142,14 +142,14 @@ func TestDeploymentController_reconcileOldRCs(t *testing.T) {
},
{
deploymentReplicas: 10,
maxUnavailable: util.NewIntOrStringFromInt(2),
maxUnavailable: intstr.FromInt(2),
readyPods: 8,
oldReplicas: 10,
scaleExpected: false,
},
{
deploymentReplicas: 10,
maxUnavailable: util.NewIntOrStringFromInt(2),
maxUnavailable: intstr.FromInt(2),
readyPods: 10,
oldReplicas: 0,
scaleExpected: false,
@ -161,7 +161,7 @@ func TestDeploymentController_reconcileOldRCs(t *testing.T) {
oldRc := rc("foo-v2", test.oldReplicas)
allRcs := []*api.ReplicationController{oldRc}
oldRcs := []*api.ReplicationController{oldRc}
deployment := deployment("foo", test.deploymentReplicas, util.NewIntOrStringFromInt(0), test.maxUnavailable)
deployment := deployment("foo", test.deploymentReplicas, intstr.FromInt(0), test.maxUnavailable)
fake := &testclient.Fake{}
fake.AddReactor("list", "pods", func(action testclient.Action) (handled bool, ret runtime.Object, err error) {
switch action.(type) {
@ -241,7 +241,7 @@ func rc(name string, replicas int) *api.ReplicationController {
}
}
func deployment(name string, replicas int, maxSurge, maxUnavailable util.IntOrString) exp.Deployment {
func deployment(name string, replicas int, maxSurge, maxUnavailable intstr.IntOrString) exp.Deployment {
return exp.Deployment{
ObjectMeta: api.ObjectMeta{
Name: name,

View File

@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/workqueue"
"k8s.io/kubernetes/pkg/watch"
@ -406,8 +407,8 @@ func (e *EndpointController) checkLeftoverEndpoints() {
// match is found, fail.
func findPort(pod *api.Pod, svcPort *api.ServicePort) (int, error) {
portName := svcPort.TargetPort
switch portName.Kind {
case util.IntstrString:
switch portName.Type {
case intstr.String:
name := portName.StrVal
for _, container := range pod.Spec.Containers {
for _, port := range container.Ports {
@ -416,7 +417,7 @@ func findPort(pod *api.Pod, svcPort *api.ServicePort) (int, error) {
}
}
}
case util.IntstrInt:
case intstr.Int:
return portName.IntVal, nil
}

View File

@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func addPods(store cache.Store, namespace string, nPods int, nPorts int, nNotReady int) {
@ -71,13 +72,13 @@ func TestFindPort(t *testing.T) {
testCases := []struct {
name string
containers []api.Container
port util.IntOrString
port intstr.IntOrString
expected int
pass bool
}{{
name: "valid int, no ports",
containers: []api.Container{{}},
port: util.NewIntOrStringFromInt(93),
port: intstr.FromInt(93),
expected: 93,
pass: true,
}, {
@ -91,13 +92,13 @@ func TestFindPort(t *testing.T) {
ContainerPort: 22,
Protocol: "TCP",
}}}},
port: util.NewIntOrStringFromInt(93),
port: intstr.FromInt(93),
expected: 93,
pass: true,
}, {
name: "valid str, no ports",
containers: []api.Container{{}},
port: util.NewIntOrStringFromString("p"),
port: intstr.FromString("p"),
expected: 0,
pass: false,
}, {
@ -115,7 +116,7 @@ func TestFindPort(t *testing.T) {
ContainerPort: 33,
Protocol: "TCP",
}}}},
port: util.NewIntOrStringFromString("q"),
port: intstr.FromString("q"),
expected: 33,
pass: true,
}, {
@ -133,7 +134,7 @@ func TestFindPort(t *testing.T) {
ContainerPort: 33,
Protocol: "TCP",
}}}},
port: util.NewIntOrStringFromString("q"),
port: intstr.FromString("q"),
expected: 33,
pass: true,
}}
@ -308,7 +309,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
Spec: api.ServiceSpec{
Selector: map[string]string{},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)}},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}},
},
})
endpoints.syncService(ns + "/foo")
@ -345,7 +346,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
Spec: api.ServiceSpec{
Selector: map[string]string{},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)}},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}},
},
})
endpoints.syncService(ns + "/foo")
@ -382,7 +383,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
Spec: api.ServiceSpec{
Selector: map[string]string{},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)}},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}},
},
})
endpoints.syncService(ns + "/foo")
@ -423,7 +424,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
Spec: api.ServiceSpec{
Selector: map[string]string{"foo": "bar"},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)}},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}},
},
})
endpoints.syncService(ns + "/foo")
@ -463,7 +464,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
Spec: api.ServiceSpec{
Selector: map[string]string{"foo": "bar"},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)}},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}},
},
})
endpoints.syncService(ns + "/foo")
@ -484,8 +485,8 @@ func TestSyncEndpointsItems(t *testing.T) {
Spec: api.ServiceSpec{
Selector: map[string]string{"foo": "bar"},
Ports: []api.ServicePort{
{Name: "port0", Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "port1", Port: 88, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8088)},
{Name: "port0", Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
{Name: "port1", Port: 88, Protocol: "TCP", TargetPort: intstr.FromInt(8088)},
},
},
})
@ -530,8 +531,8 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
Spec: api.ServiceSpec{
Selector: map[string]string{"foo": "bar"},
Ports: []api.ServicePort{
{Name: "port0", Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "port1", Port: 88, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8088)},
{Name: "port0", Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
{Name: "port1", Port: 88, Protocol: "TCP", TargetPort: intstr.FromInt(8088)},
},
},
})
@ -589,7 +590,7 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
},
Spec: api.ServiceSpec{
Selector: map[string]string{"foo": "bar"},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)}},
Ports: []api.ServicePort{{Port: 80, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}},
},
})
endpoints.syncService(ns + "/foo")

View File

@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
type internalType struct {
@ -671,12 +672,12 @@ func (testServiceGenerator) Generate(genericParams map[string]interface{}) (runt
}
if found && len(targetPort) > 0 {
if portNum, err := strconv.Atoi(targetPort); err != nil {
service.Spec.Ports[0].TargetPort = util.NewIntOrStringFromString(targetPort)
service.Spec.Ports[0].TargetPort = intstr.FromString(targetPort)
} else {
service.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(portNum)
service.Spec.Ports[0].TargetPort = intstr.FromInt(portNum)
}
} else {
service.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(port)
service.Spec.Ports[0].TargetPort = intstr.FromInt(port)
}
if params["create-external-load-balancer"] == "true" {
service.Spec.Type = api.ServiceTypeLoadBalancer

View File

@ -26,7 +26,7 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestRunExposeService(t *testing.T) {
@ -63,7 +63,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: util.NewIntOrStringFromInt(14),
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"app": "go"},
@ -94,7 +94,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: util.NewIntOrStringFromInt(14),
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
@ -126,7 +126,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolTCP,
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
},
},
Selector: map[string]string{"run": "this"},
@ -157,7 +157,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: util.NewIntOrStringFromInt(14),
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
@ -188,7 +188,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: util.NewIntOrStringFromInt(14),
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
@ -221,7 +221,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolTCP,
Port: 90,
TargetPort: util.NewIntOrStringFromInt(90),
TargetPort: intstr.FromInt(90),
},
},
},
@ -250,7 +250,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: util.NewIntOrStringFromInt(14),
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
@ -277,7 +277,7 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolTCP,
Port: 90,
TargetPort: util.NewIntOrStringFromInt(90),
TargetPort: intstr.FromInt(90),
},
},
Selector: map[string]string{"svc": "frompod"},
@ -301,12 +301,12 @@ func TestRunExposeService(t *testing.T) {
{
Protocol: api.ProtocolTCP,
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
},
{
Protocol: api.ProtocolTCP,
Port: 443,
TargetPort: util.NewIntOrStringFromInt(443),
TargetPort: intstr.FromInt(443),
},
},
},
@ -320,13 +320,13 @@ func TestRunExposeService(t *testing.T) {
Name: "port-1",
Protocol: api.ProtocolTCP,
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
},
{
Name: "port-2",
Protocol: api.ProtocolTCP,
Port: 443,
TargetPort: util.NewIntOrStringFromInt(443),
TargetPort: intstr.FromInt(443),
},
},
Selector: map[string]string{"svc": "fromfoo"},

View File

@ -33,7 +33,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// RollingUpdateOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
@ -329,8 +329,8 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
Interval: interval,
Timeout: timeout,
CleanupPolicy: updateCleanupPolicy,
MaxUnavailable: util.NewIntOrStringFromInt(0),
MaxSurge: util.NewIntOrStringFromInt(1),
MaxUnavailable: intstr.FromInt(0),
MaxSurge: intstr.FromInt(1),
}
if rollback {
err = kubectl.AbortRollingUpdate(config)

View File

@ -30,7 +30,7 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestGetRestartPolicy(t *testing.T) {
@ -136,7 +136,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
},
},
Selector: map[string]string{
@ -168,7 +168,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
},
},
Selector: map[string]string{

View File

@ -30,7 +30,7 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
)
@ -70,7 +70,7 @@ type RollingUpdaterConfig struct {
// can be scaled down further, followed by scaling up the new RC, ensuring
// that the total number of pods available at all times during the update is at
// least 70% of desired pods.
MaxUnavailable util.IntOrString
MaxUnavailable intstr.IntOrString
// MaxSurge is the maximum number of pods that can be scheduled above the desired number of pods.
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
// This can not be 0 if MaxUnavailable is 0.
@ -81,7 +81,7 @@ type RollingUpdaterConfig struct {
// 130% of desired pods. Once old pods have been killed, new RC can be scaled up
// further, ensuring that total number of pods running at any time during
// the update is atmost 130% of desired pods.
MaxSurge util.IntOrString
MaxSurge intstr.IntOrString
}
// RollingUpdaterCleanupPolicy is a cleanup action to take after the
@ -483,14 +483,14 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *api.ReplicationControl
// func extractMaxValue is a helper to extract config max values as either
// absolute numbers or based on percentages of the given value.
func extractMaxValue(field util.IntOrString, name string, value int) (int, error) {
switch field.Kind {
case util.IntstrInt:
func extractMaxValue(field intstr.IntOrString, name string, value int) (int, error) {
switch field.Type {
case intstr.Int:
if field.IntVal < 0 {
return 0, fmt.Errorf("%s must be >= 0", name)
}
return field.IntVal, nil
case util.IntstrString:
case intstr.String:
s := strings.Replace(field.StrVal, "%", "", -1)
v, err := strconv.Atoi(s)
if err != nil {
@ -501,7 +501,7 @@ func extractMaxValue(field util.IntOrString, name string, value int) (int, error
}
return int(math.Ceil(float64(value) * (float64(v)) / 100)), nil
}
return 0, fmt.Errorf("invalid kind %q for %s", field.Kind, name)
return 0, fmt.Errorf("invalid kind %q for %s", field.Type, name)
}
func Rename(c client.ReplicationControllersNamespacer, rc *api.ReplicationController, newName string) error {

View File

@ -33,7 +33,7 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
)
@ -114,8 +114,8 @@ func TestUpdate(t *testing.T) {
newRc *api.ReplicationController
// whether newRc existed (false means it was created)
newRcExists bool
maxUnavail util.IntOrString
maxSurge util.IntOrString
maxUnavail intstr.IntOrString
maxSurge intstr.IntOrString
// expected is the sequence of up/down events that will be simulated and
// verified
expected []interface{}
@ -127,8 +127,8 @@ func TestUpdate(t *testing.T) {
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("30%"),
maxSurge: util.NewIntOrStringFromString("0%"),
maxUnavail: intstr.FromString("30%"),
maxSurge: intstr.FromString("0%"),
expected: []interface{}{
down{oldReady: 10, newReady: 0, to: 7},
up{3},
@ -156,8 +156,8 @@ Scaling foo-v2 up to 10
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("30%"),
maxSurge: util.NewIntOrStringFromString("0%"),
maxUnavail: intstr.FromString("30%"),
maxSurge: intstr.FromString("0%"),
expected: []interface{}{
down{oldReady: 10, newReady: 0, to: 7},
up{3},
@ -185,8 +185,8 @@ Scaling foo-v2 up to 10
oldRc: oldRc(7, 10),
newRc: newRc(3, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("30%"),
maxSurge: util.NewIntOrStringFromString("0%"),
maxUnavail: intstr.FromString("30%"),
maxSurge: intstr.FromString("0%"),
expected: []interface{}{
down{oldReady: 7, newReady: 3, to: 4},
up{6},
@ -209,8 +209,8 @@ Scaling foo-v2 up to 10
oldRc: oldRc(7, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("30%"),
maxSurge: util.NewIntOrStringFromString("0%"),
maxUnavail: intstr.FromString("30%"),
maxSurge: intstr.FromString("0%"),
expected: []interface{}{
down{oldReady: 7, newReady: 0, noop: true},
up{3},
@ -236,8 +236,8 @@ Scaling foo-v2 up to 10
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("30%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("30%"),
expected: []interface{}{
up{3},
down{oldReady: 10, newReady: 3, to: 7},
@ -264,8 +264,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("30%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("30%"),
expected: []interface{}{
up{3},
down{oldReady: 10, newReady: 0, noop: true},
@ -298,8 +298,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("10%"),
maxSurge: util.NewIntOrStringFromString("20%"),
maxUnavail: intstr.FromString("10%"),
maxSurge: intstr.FromString("20%"),
expected: []interface{}{
up{2},
down{oldReady: 10, newReady: 2, to: 7},
@ -326,8 +326,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("10%"),
maxSurge: util.NewIntOrStringFromString("20%"),
maxUnavail: intstr.FromString("10%"),
maxSurge: intstr.FromString("20%"),
expected: []interface{}{
up{2},
down{oldReady: 10, newReady: 2, to: 7},
@ -355,8 +355,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(2, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("10%"),
maxSurge: util.NewIntOrStringFromString("20%"),
maxUnavail: intstr.FromString("10%"),
maxSurge: intstr.FromString("20%"),
expected: []interface{}{
down{oldReady: 10, newReady: 2, to: 7},
up{5},
@ -381,8 +381,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("100%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("100%"),
expected: []interface{}{
up{10},
down{oldReady: 10, newReady: 10, to: 0},
@ -397,8 +397,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("100%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("100%"),
expected: []interface{}{
up{10},
down{oldReady: 10, newReady: 0, noop: true},
@ -418,8 +418,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("100%"),
maxSurge: util.NewIntOrStringFromString("0%"),
maxUnavail: intstr.FromString("100%"),
maxSurge: intstr.FromString("0%"),
expected: []interface{}{
down{oldReady: 10, newReady: 0, to: 0},
up{10},
@ -434,8 +434,8 @@ Scaling foo-v2 up to 10
oldRc: oldRc(1, 1),
newRc: newRc(0, 1),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("10%"),
maxSurge: util.NewIntOrStringFromString("0%"),
maxUnavail: intstr.FromString("10%"),
maxSurge: intstr.FromString("0%"),
expected: []interface{}{
down{oldReady: 1, newReady: 0, to: 0},
up{1},
@ -450,8 +450,8 @@ Scaling foo-v2 up to 1
oldRc: oldRc(1, 1),
newRc: newRc(0, 1),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("10%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("10%"),
expected: []interface{}{
up{1},
down{oldReady: 1, newReady: 0, noop: true},
@ -467,8 +467,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(1, 1),
newRc: newRc(0, 1),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("10%"),
maxSurge: util.NewIntOrStringFromString("10%"),
maxUnavail: intstr.FromString("10%"),
maxSurge: intstr.FromString("10%"),
expected: []interface{}{
up{1},
down{oldReady: 1, newReady: 0, noop: true},
@ -484,8 +484,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(3, 3),
newRc: newRc(0, 3),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromInt(0),
maxSurge: util.NewIntOrStringFromInt(1),
maxUnavail: intstr.FromInt(0),
maxSurge: intstr.FromInt(1),
expected: []interface{}{
up{1},
down{oldReady: 3, newReady: 1, to: 2},
@ -508,8 +508,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(6, 10),
newRc: newRc(5, 10),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("20%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("20%"),
expected: []interface{}{
up{6},
down{oldReady: 6, newReady: 6, to: 4},
@ -532,8 +532,8 @@ Scaling foo-v1 down to 0
oldRc: oldRc(10, 10),
newRc: newRc(0, 20),
newRcExists: false,
maxUnavail: util.NewIntOrStringFromString("0%"),
maxSurge: util.NewIntOrStringFromString("300%"),
maxUnavail: intstr.FromString("0%"),
maxSurge: intstr.FromString("300%"),
expected: []interface{}{
up{20},
down{oldReady: 10, newReady: 20, to: 0},
@ -680,8 +680,8 @@ func TestUpdate_progressTimeout(t *testing.T) {
Interval: time.Millisecond,
Timeout: time.Millisecond,
CleanupPolicy: DeleteRollingUpdateCleanupPolicy,
MaxUnavailable: util.NewIntOrStringFromInt(0),
MaxSurge: util.NewIntOrStringFromInt(1),
MaxUnavailable: intstr.FromInt(0),
MaxSurge: intstr.FromInt(1),
}
err := updater.Update(config)
if err == nil {
@ -733,7 +733,7 @@ func TestUpdate_assignOriginalAnnotation(t *testing.T) {
Interval: time.Millisecond,
Timeout: time.Millisecond,
CleanupPolicy: DeleteRollingUpdateCleanupPolicy,
MaxUnavailable: util.NewIntOrStringFromString("100%"),
MaxUnavailable: intstr.FromString("100%"),
}
err := updater.Update(config)
if err != nil {
@ -1301,54 +1301,54 @@ func TestRollingUpdater_pollForReadyPods(t *testing.T) {
func TestRollingUpdater_extractMaxValue(t *testing.T) {
tests := []struct {
field util.IntOrString
field intstr.IntOrString
original int
expected int
valid bool
}{
{
field: util.NewIntOrStringFromInt(1),
field: intstr.FromInt(1),
original: 100,
expected: 1,
valid: true,
},
{
field: util.NewIntOrStringFromInt(0),
field: intstr.FromInt(0),
original: 100,
expected: 0,
valid: true,
},
{
field: util.NewIntOrStringFromInt(-1),
field: intstr.FromInt(-1),
original: 100,
valid: false,
},
{
field: util.NewIntOrStringFromString("10%"),
field: intstr.FromString("10%"),
original: 100,
expected: 10,
valid: true,
},
{
field: util.NewIntOrStringFromString("100%"),
field: intstr.FromString("100%"),
original: 100,
expected: 100,
valid: true,
},
{
field: util.NewIntOrStringFromString("200%"),
field: intstr.FromString("200%"),
original: 100,
expected: 200,
valid: true,
},
{
field: util.NewIntOrStringFromString("0%"),
field: intstr.FromString("0%"),
original: 100,
expected: 0,
valid: true,
},
{
field: util.NewIntOrStringFromString("-1%"),
field: intstr.FromString("-1%"),
original: 100,
valid: false,
},

View File

@ -23,7 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// The only difference between ServiceGeneratorV1 and V2 is that the service port is named "default" in V1, while it is left unnamed in V2.
@ -156,11 +156,11 @@ func generate(genericParams map[string]interface{}) (runtime.Object, error) {
targetPortString, found = params["container-port"]
}
if found && len(targetPortString) > 0 {
var targetPort util.IntOrString
var targetPort intstr.IntOrString
if portNum, err := strconv.Atoi(targetPortString); err != nil {
targetPort = util.NewIntOrStringFromString(targetPortString)
targetPort = intstr.FromString(targetPortString)
} else {
targetPort = util.NewIntOrStringFromInt(portNum)
targetPort = intstr.FromInt(portNum)
}
// Use the same target-port for every port
for i := range service.Spec.Ports {
@ -171,7 +171,7 @@ func generate(genericParams map[string]interface{}) (runtime.Object, error) {
// should be the same as Port
for i := range service.Spec.Ports {
port := service.Spec.Ports[i].Port
service.Spec.Ports[i].TargetPort = util.NewIntOrStringFromInt(port)
service.Spec.Ports[i].TargetPort = intstr.FromInt(port)
}
}
if params["create-external-load-balancer"] == "true" {

View File

@ -21,7 +21,7 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestGenerateService(t *testing.T) {
@ -52,7 +52,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
TargetPort: intstr.FromInt(1234),
},
},
},
@ -81,7 +81,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
},
},
@ -114,7 +114,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
TargetPort: intstr.FromInt(1234),
},
},
},
@ -143,7 +143,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
},
ExternalIPs: []string{"1.2.3.4"},
@ -174,7 +174,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
},
Type: api.ServiceTypeLoadBalancer,
@ -205,7 +205,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
},
Type: api.ServiceTypeNodePort,
@ -236,7 +236,7 @@ func TestGenerateService(t *testing.T) {
{
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
},
Type: api.ServiceTypeNodePort,
@ -266,7 +266,7 @@ func TestGenerateService(t *testing.T) {
Name: "default",
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
TargetPort: intstr.FromInt(1234),
},
},
},
@ -296,7 +296,7 @@ func TestGenerateService(t *testing.T) {
Name: "default",
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
TargetPort: intstr.FromInt(1234),
},
},
SessionAffinity: api.ServiceAffinityClientIP,
@ -325,13 +325,13 @@ func TestGenerateService(t *testing.T) {
Name: "port-1",
Port: 80,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
{
Name: "port-2",
Port: 443,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromString("foobar"),
TargetPort: intstr.FromString("foobar"),
},
},
},
@ -359,13 +359,13 @@ func TestGenerateService(t *testing.T) {
Name: "port-1",
Port: 80,
Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(1234),
TargetPort: intstr.FromInt(1234),
},
{
Name: "port-2",
Port: 443,
Protocol: api.ProtocolUDP,
TargetPort: util.NewIntOrStringFromInt(1234),
TargetPort: intstr.FromInt(1234),
},
},
},
@ -392,13 +392,13 @@ func TestGenerateService(t *testing.T) {
Name: "port-1",
Port: 80,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
},
{
Name: "port-2",
Port: 443,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(443),
TargetPort: intstr.FromInt(443),
},
},
},

View File

@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
uexec "k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
)
@ -1468,7 +1469,7 @@ func TestSyncPodWithPodInfraCreatesContainerCallsHandler(t *testing.T) {
PostStart: &api.Handler{
HTTPGet: &api.HTTPGetAction{
Host: "foo",
Port: util.IntOrString{IntVal: 8080, Kind: util.IntstrInt},
Port: intstr.FromInt(8080),
Path: "bar",
},
},
@ -1519,7 +1520,7 @@ func TestSyncPodEventHandlerFails(t *testing.T) {
PostStart: &api.Handler{
HTTPGet: &api.HTTPGetAction{
Host: "does.no.exist",
Port: util.IntOrString{IntVal: 8080, Kind: util.IntstrInt},
Port: intstr.FromInt(8080),
Path: "bar",
},
},

View File

@ -25,7 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
type HandlerRunner struct {
@ -66,8 +66,8 @@ func (hr *HandlerRunner) Run(containerID kubecontainer.ContainerID, pod *api.Pod
// an attempt is made to find a port with the same name in the container spec.
// If a port with the same name is found, it's ContainerPort value is returned. If no matching
// port is found, an error is returned.
func resolvePort(portReference util.IntOrString, container *api.Container) (int, error) {
if portReference.Kind == util.IntstrInt {
func resolvePort(portReference intstr.IntOrString, container *api.Container) (int, error) {
if portReference.Type == intstr.Int {
return portReference.IntVal, nil
} else {
portName := portReference.StrVal
@ -99,7 +99,7 @@ func (hr *HandlerRunner) runHTTPHandler(pod *api.Pod, container *api.Container,
host = status.PodIP
}
var port int
if handler.HTTPGet.Port.Kind == util.IntstrString && len(handler.HTTPGet.Port.StrVal) == 0 {
if handler.HTTPGet.Port.Type == intstr.String && len(handler.HTTPGet.Port.StrVal) == 0 {
port = 80
} else {
var err error

View File

@ -24,12 +24,12 @@ import (
"k8s.io/kubernetes/pkg/api"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestResolvePortInt(t *testing.T) {
expected := 80
port, err := resolvePort(util.IntOrString{Kind: util.IntstrInt, IntVal: expected}, &api.Container{})
port, err := resolvePort(intstr.FromInt(expected), &api.Container{})
if port != expected {
t.Errorf("expected: %d, saw: %d", expected, port)
}
@ -46,7 +46,7 @@ func TestResolvePortString(t *testing.T) {
{Name: name, ContainerPort: expected},
},
}
port, err := resolvePort(util.IntOrString{Kind: util.IntstrString, StrVal: name}, container)
port, err := resolvePort(intstr.FromString(name), container)
if port != expected {
t.Errorf("expected: %d, saw: %d", expected, port)
}
@ -63,7 +63,7 @@ func TestResolvePortStringUnknown(t *testing.T) {
{Name: "bar", ContainerPort: expected},
},
}
port, err := resolvePort(util.IntOrString{Kind: util.IntstrString, StrVal: name}, container)
port, err := resolvePort(intstr.FromString(name), container)
if port != -1 {
t.Errorf("expected: -1, saw: %d", port)
}
@ -146,7 +146,7 @@ func TestRunHandlerHttp(t *testing.T) {
PostStart: &api.Handler{
HTTPGet: &api.HTTPGetAction{
Host: "foo",
Port: util.IntOrString{IntVal: 8080, Kind: util.IntstrInt},
Port: intstr.FromInt(8080),
Path: "bar",
},
},

View File

@ -32,8 +32,8 @@ import (
execprobe "k8s.io/kubernetes/pkg/probe/exec"
httprobe "k8s.io/kubernetes/pkg/probe/http"
tcprobe "k8s.io/kubernetes/pkg/probe/tcp"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/intstr"
"github.com/golang/glog"
)
@ -158,13 +158,13 @@ func (pb *prober) runProbe(p *api.Probe, pod *api.Pod, status api.PodStatus, con
return probe.Unknown, "", fmt.Errorf("Missing probe handler for %s:%s", kubecontainer.GetPodFullName(pod), container.Name)
}
func extractPort(param util.IntOrString, container api.Container) (int, error) {
func extractPort(param intstr.IntOrString, container api.Container) (int, error) {
port := -1
var err error
switch param.Kind {
case util.IntstrInt:
switch param.Type {
case intstr.Int:
port = param.IntVal
case util.IntstrString:
case intstr.String:
if port, err = findPortByName(container, param.StrVal); err != nil {
// Last ditch effort - maybe it was an int stored as string?
if port, err = strconv.Atoi(param.StrVal); err != nil {

View File

@ -26,7 +26,7 @@ import (
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/prober/results"
"k8s.io/kubernetes/pkg/probe"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestFormatURL(t *testing.T) {
@ -76,14 +76,14 @@ func TestGetURLParts(t *testing.T) {
port int
path string
}{
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromInt(-1), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromString(""), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromString("-1"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromString("not-found"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromString("found"), Path: ""}, true, "127.0.0.1", 93, ""},
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromInt(76), Path: ""}, true, "127.0.0.1", 76, ""},
{&api.HTTPGetAction{Host: "", Port: util.NewIntOrStringFromString("118"), Path: ""}, true, "127.0.0.1", 118, ""},
{&api.HTTPGetAction{Host: "hostname", Port: util.NewIntOrStringFromInt(76), Path: "path"}, true, "hostname", 76, "path"},
{&api.HTTPGetAction{Host: "", Port: intstr.FromInt(-1), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: intstr.FromString(""), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: intstr.FromString("-1"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: intstr.FromString("not-found"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetAction{Host: "", Port: intstr.FromString("found"), Path: ""}, true, "127.0.0.1", 93, ""},
{&api.HTTPGetAction{Host: "", Port: intstr.FromInt(76), Path: ""}, true, "127.0.0.1", 76, ""},
{&api.HTTPGetAction{Host: "", Port: intstr.FromString("118"), Path: ""}, true, "127.0.0.1", 118, ""},
{&api.HTTPGetAction{Host: "hostname", Port: intstr.FromInt(76), Path: "path"}, true, "hostname", 76, "path"},
}
for _, test := range testCases {
@ -130,13 +130,13 @@ func TestGetTCPAddrParts(t *testing.T) {
host string
port int
}{
{&api.TCPSocketAction{Port: util.NewIntOrStringFromInt(-1)}, false, "", -1},
{&api.TCPSocketAction{Port: util.NewIntOrStringFromString("")}, false, "", -1},
{&api.TCPSocketAction{Port: util.NewIntOrStringFromString("-1")}, false, "", -1},
{&api.TCPSocketAction{Port: util.NewIntOrStringFromString("not-found")}, false, "", -1},
{&api.TCPSocketAction{Port: util.NewIntOrStringFromString("found")}, true, "1.2.3.4", 93},
{&api.TCPSocketAction{Port: util.NewIntOrStringFromInt(76)}, true, "1.2.3.4", 76},
{&api.TCPSocketAction{Port: util.NewIntOrStringFromString("118")}, true, "1.2.3.4", 118},
{&api.TCPSocketAction{Port: intstr.FromInt(-1)}, false, "", -1},
{&api.TCPSocketAction{Port: intstr.FromString("")}, false, "", -1},
{&api.TCPSocketAction{Port: intstr.FromString("-1")}, false, "", -1},
{&api.TCPSocketAction{Port: intstr.FromString("not-found")}, false, "", -1},
{&api.TCPSocketAction{Port: intstr.FromString("found")}, true, "1.2.3.4", 93},
{&api.TCPSocketAction{Port: intstr.FromInt(76)}, true, "1.2.3.4", 76},
{&api.TCPSocketAction{Port: intstr.FromString("118")}, true, "1.2.3.4", 118},
}
for _, test := range testCases {

View File

@ -31,6 +31,7 @@ import (
servicecontroller "k8s.io/kubernetes/pkg/registry/service/ipallocator/controller"
portallocatorcontroller "k8s.io/kubernetes/pkg/registry/service/portallocator/controller"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"github.com/golang/glog"
)
@ -157,7 +158,7 @@ func createPortAndServiceSpec(servicePort int, nodePort int, servicePortName str
servicePorts := []api.ServicePort{{Protocol: api.ProtocolTCP,
Port: servicePort,
Name: servicePortName,
TargetPort: util.NewIntOrStringFromInt(servicePort)}}
TargetPort: intstr.FromInt(servicePort)}}
serviceType := api.ServiceTypeClusterIP
if nodePort > 0 {
servicePorts[0].NodePort = nodePort

View File

@ -24,7 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestReconcileEndpoints(t *testing.T) {
@ -453,14 +453,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service does not exist",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
expectCreate: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -501,14 +501,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition wrong port",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8000, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8000, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -520,7 +520,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -533,15 +533,15 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition missing port",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "baz", Port: 1000, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(1000)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
{Name: "baz", Port: 1000, Protocol: "TCP", TargetPort: intstr.FromInt(1000)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -553,8 +553,8 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "baz", Port: 1000, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(1000)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
{Name: "baz", Port: 1000, Protocol: "TCP", TargetPort: intstr.FromInt(1000)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -567,14 +567,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition incorrect port",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "bar", Port: 1000, Protocol: "UDP", TargetPort: util.NewIntOrStringFromInt(1000)},
{Name: "bar", Port: 1000, Protocol: "UDP", TargetPort: intstr.FromInt(1000)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -586,7 +586,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -599,14 +599,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition incorrect port name",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 1000, Protocol: "UDP", TargetPort: util.NewIntOrStringFromInt(1000)},
{Name: "foo", Port: 1000, Protocol: "UDP", TargetPort: intstr.FromInt(1000)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -618,7 +618,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -631,14 +631,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition incorrect target port",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(1000)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(1000)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -650,7 +650,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -663,14 +663,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition incorrect protocol",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "UDP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "UDP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -682,7 +682,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -695,14 +695,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition has incorrect type",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -714,7 +714,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -727,14 +727,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition satisfies",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
Selector: nil,
ClusterIP: "1.2.3.4",
@ -779,14 +779,14 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
testName: "service definition wrong port, no expected update",
serviceName: "foo",
servicePorts: []api.ServicePort{
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(8080)},
{Name: "foo", Port: 8080, Protocol: "TCP", TargetPort: intstr.FromInt(8080)},
},
serviceType: api.ServiceTypeClusterIP,
service: &api.Service{
ObjectMeta: om("foo"),
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Name: "foo", Port: 1000, Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(1000)},
{Name: "foo", Port: 1000, Protocol: "TCP", TargetPort: intstr.FromInt(1000)},
},
Selector: nil,
ClusterIP: "1.2.3.4",

View File

@ -48,6 +48,7 @@ import (
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"github.com/coreos/go-etcd/etcd"
"github.com/emicklei/go-restful"
@ -221,13 +222,13 @@ func TestControllerServicePorts(t *testing.T) {
Name: "additional-port-1",
Port: 1000,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(1000),
TargetPort: intstr.FromInt(1000),
},
{
Name: "additional-port-2",
Port: 1010,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(1010),
TargetPort: intstr.FromInt(1010),
},
}

View File

@ -27,7 +27,7 @@ import (
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
@ -41,7 +41,7 @@ var (
name = "foo-ingress"
defaultHostname = "foo.bar.com"
defaultBackendName = "default-backend"
defaultBackendPort = util.IntOrString{Kind: util.IntstrInt, IntVal: 80}
defaultBackendPort = intstr.FromInt(80)
defaultLoadBalancer = "127.0.0.1"
defaultPath = "/foo"
defaultPathMap = map[string]string{defaultPath: defaultBackendName}

View File

@ -21,13 +21,13 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func newIngress() extensions.Ingress {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
ServicePort: intstr.FromInt(80),
}
return extensions.Ingress{
ObjectMeta: api.ObjectMeta{
@ -37,7 +37,7 @@ func newIngress() extensions.Ingress {
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: util.IntOrString{Kind: util.IntstrInt, IntVal: 80},
ServicePort: intstr.FromInt(80),
},
Rules: []extensions.IngressRule{
{

View File

@ -26,7 +26,7 @@ import (
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
@ -48,7 +48,7 @@ func validService() *api.Service {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -76,7 +76,7 @@ func TestCreate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
},
@ -99,7 +99,7 @@ func TestUpdate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
}
return object

View File

@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/registry/service/ipallocator"
"k8s.io/kubernetes/pkg/registry/service/portallocator"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
// TODO(wojtek-t): Cleanup this file.
@ -77,7 +78,7 @@ func TestServiceRegistryCreate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -120,7 +121,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
},
@ -170,7 +171,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
})
@ -189,7 +190,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
})
@ -234,7 +235,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
},
@ -247,7 +248,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
},
@ -275,7 +276,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -350,7 +351,7 @@ func TestServiceRegistryUpdateExternalService(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -388,12 +389,12 @@ func TestServiceRegistryUpdateMultiPortExternalService(t *testing.T) {
Name: "p",
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}, {
Name: "q",
Port: 8086,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(8086),
TargetPort: intstr.FromInt(8086),
}},
},
}
@ -569,7 +570,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -592,7 +593,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
}}
ctx = api.NewDefaultContext()
@ -624,7 +625,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -651,7 +652,7 @@ func TestServiceRegistryIPReallocation(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -679,7 +680,7 @@ func TestServiceRegistryIPReallocation(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -706,7 +707,7 @@ func TestServiceRegistryIPUpdate(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}
@ -760,7 +761,7 @@ func TestServiceRegistryIPLoadBalancer(t *testing.T) {
Ports: []api.ServicePort{{
Port: 6502,
Protocol: api.ProtocolTCP,
TargetPort: util.NewIntOrStringFromInt(6502),
TargetPort: intstr.FromInt(6502),
}},
},
}

View File

@ -23,7 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
func TestCheckGeneratedNameError(t *testing.T) {
@ -56,7 +56,7 @@ func makeValidService() api.Service {
Selector: map[string]string{"key": "val"},
SessionAffinity: "None",
Type: api.ServiceTypeClusterIP,
Ports: []api.ServicePort{{Name: "p", Protocol: "TCP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(8675)}},
Ports: []api.ServicePort{{Name: "p", Protocol: "TCP", Port: 8675, TargetPort: intstr.FromInt(8675)}},
},
}
}

98
pkg/util/intstr/intstr.go Normal file
View File

@ -0,0 +1,98 @@
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package intstr
import (
"encoding/json"
"fmt"
"strconv"
"github.com/google/gofuzz"
)
// IntOrString is a type that can hold an int or a string. When used in
// JSON or YAML marshalling and unmarshalling, it produces or consumes the
// inner type. This allows you to have, for example, a JSON field that can
// accept a name or number.
type IntOrString struct {
Type Type
IntVal int
StrVal string
}
// Type represents the stored type of IntOrString.
type Type int
const (
Int Type = iota // The IntOrString holds an int.
String // The IntOrString holds a string.
)
// FromInt creates an IntOrString object with an int value.
func FromInt(val int) 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}
}
// UnmarshalJSON implements the json.Unmarshaller interface.
func (intstr *IntOrString) UnmarshalJSON(value []byte) error {
if value[0] == '"' {
intstr.Type = String
return json.Unmarshal(value, &intstr.StrVal)
}
intstr.Type = Int
return json.Unmarshal(value, &intstr.IntVal)
}
// String returns the string value, or the Itoa of the int value.
func (intstr *IntOrString) String() string {
if intstr.Type == String {
return intstr.StrVal
}
return strconv.Itoa(intstr.IntVal)
}
// MarshalJSON implements the json.Marshaller interface.
func (intstr IntOrString) MarshalJSON() ([]byte, error) {
switch intstr.Type {
case Int:
return json.Marshal(intstr.IntVal)
case String:
return json.Marshal(intstr.StrVal)
default:
return []byte{}, fmt.Errorf("impossible IntOrString.Type")
}
}
func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
if intstr == nil {
return
}
if c.RandBool() {
intstr.Type = Int
c.Fuzz(&intstr.IntVal)
intstr.StrVal = ""
} else {
intstr.Type = String
intstr.IntVal = 0
c.Fuzz(&intstr.StrVal)
}
}

View File

@ -0,0 +1,111 @@
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package intstr
import (
"encoding/json"
"reflect"
"testing"
"github.com/ghodss/yaml"
)
func TestFromInt(t *testing.T) {
i := FromInt(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" {
t.Errorf("Expected StrVal=\"76\", got %+v", i)
}
}
type IntOrStringHolder struct {
IOrS IntOrString `json:"val"`
}
func TestIntOrStringUnmarshalJSON(t *testing.T) {
cases := []struct {
input string
result IntOrString
}{
{"{\"val\": 123}", FromInt(123)},
{"{\"val\": \"123\"}", FromString("123")},
}
for _, c := range cases {
var result IntOrStringHolder
if err := json.Unmarshal([]byte(c.input), &result); err != nil {
t.Errorf("Failed to unmarshal input '%v': %v", c.input, err)
}
if result.IOrS != c.result {
t.Errorf("Failed to unmarshal input '%v': expected %+v, got %+v", c.input, c.result, result)
}
}
}
func TestIntOrStringMarshalJSON(t *testing.T) {
cases := []struct {
input IntOrString
result string
}{
{FromInt(123), "{\"val\":123}"},
{FromString("123"), "{\"val\":\"123\"}"},
}
for _, c := range cases {
input := IntOrStringHolder{c.input}
result, err := json.Marshal(&input)
if err != nil {
t.Errorf("Failed to marshal input '%v': %v", input, err)
}
if string(result) != c.result {
t.Errorf("Failed to marshal input '%v': expected: %+v, got %q", input, c.result, string(result))
}
}
}
func TestIntOrStringMarshalJSONUnmarshalYAML(t *testing.T) {
cases := []struct {
input IntOrString
}{
{FromInt(123)},
{FromString("123")},
}
for _, c := range cases {
input := IntOrStringHolder{c.input}
jsonMarshalled, err := json.Marshal(&input)
if err != nil {
t.Errorf("1: Failed to marshal input: '%v': %v", input, err)
}
var result IntOrStringHolder
err = yaml.Unmarshal(jsonMarshalled, &result)
if err != nil {
t.Errorf("2: Failed to unmarshal '%+v': %v", string(jsonMarshalled), err)
}
if !reflect.DeepEqual(input, result) {
t.Errorf("3: Failed to marshal input '%+v': got %+v", input, result)
}
}
}

View File

@ -19,7 +19,6 @@ package util
import (
"bufio"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math"
@ -34,8 +33,9 @@ import (
"strings"
"time"
"k8s.io/kubernetes/pkg/util/intstr"
"github.com/golang/glog"
"github.com/google/gofuzz"
)
// For testing, bypass HandleCrash.
@ -133,88 +133,15 @@ func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
}
}
// IntOrString is a type that can hold an int or a string. When used in
// JSON or YAML marshalling and unmarshalling, it produces or consumes the
// inner type. This allows you to have, for example, a JSON field that can
// accept a name or number.
type IntOrString struct {
Kind IntstrKind
IntVal int
StrVal string
}
// IntstrKind represents the stored type of IntOrString.
type IntstrKind int
const (
IntstrInt IntstrKind = iota // The IntOrString holds an int.
IntstrString // The IntOrString holds a string.
)
// NewIntOrStringFromInt creates an IntOrString object with an int value.
func NewIntOrStringFromInt(val int) IntOrString {
return IntOrString{Kind: IntstrInt, IntVal: val}
}
// NewIntOrStringFromString creates an IntOrString object with a string value.
func NewIntOrStringFromString(val string) IntOrString {
return IntOrString{Kind: IntstrString, StrVal: val}
}
// UnmarshalJSON implements the json.Unmarshaller interface.
func (intstr *IntOrString) UnmarshalJSON(value []byte) error {
if value[0] == '"' {
intstr.Kind = IntstrString
return json.Unmarshal(value, &intstr.StrVal)
}
intstr.Kind = IntstrInt
return json.Unmarshal(value, &intstr.IntVal)
}
// String returns the string value, or Itoa's the int value.
func (intstr *IntOrString) String() string {
if intstr.Kind == IntstrString {
return intstr.StrVal
}
return strconv.Itoa(intstr.IntVal)
}
// MarshalJSON implements the json.Marshaller interface.
func (intstr IntOrString) MarshalJSON() ([]byte, error) {
switch intstr.Kind {
case IntstrInt:
return json.Marshal(intstr.IntVal)
case IntstrString:
return json.Marshal(intstr.StrVal)
default:
return []byte{}, fmt.Errorf("impossible IntOrString.Kind")
}
}
func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
if intstr == nil {
return
}
if c.RandBool() {
intstr.Kind = IntstrInt
c.Fuzz(&intstr.IntVal)
intstr.StrVal = ""
} else {
intstr.Kind = IntstrString
intstr.IntVal = 0
c.Fuzz(&intstr.StrVal)
}
}
func GetIntOrPercentValue(intStr *IntOrString) (int, bool, error) {
switch intStr.Kind {
case IntstrInt:
return intStr.IntVal, false, nil
case IntstrString:
s := strings.Replace(intStr.StrVal, "%", "", -1)
func GetIntOrPercentValue(intOrStr *intstr.IntOrString) (int, bool, error) {
switch intOrStr.Type {
case intstr.Int:
return intOrStr.IntVal, false, nil
case intstr.String:
s := strings.Replace(intOrStr.StrVal, "%", "", -1)
v, err := strconv.Atoi(s)
if err != nil {
return 0, false, fmt.Errorf("invalid value %q: %v", intStr.StrVal, err)
return 0, false, fmt.Errorf("invalid value %q: %v", intOrStr.StrVal, err)
}
return v, true, nil
}

View File

@ -17,16 +17,12 @@ limitations under the License.
package util
import (
"encoding/json"
"fmt"
"io"
"net"
"reflect"
"strings"
"testing"
"time"
"github.com/ghodss/yaml"
)
func TestUntil(t *testing.T) {
@ -109,133 +105,6 @@ func TestCustomHandleError(t *testing.T) {
}
}
func TestNewIntOrStringFromInt(t *testing.T) {
i := NewIntOrStringFromInt(93)
if i.Kind != IntstrInt || i.IntVal != 93 {
t.Errorf("Expected IntVal=93, got %+v", i)
}
}
func TestNewIntOrStringFromString(t *testing.T) {
i := NewIntOrStringFromString("76")
if i.Kind != IntstrString || i.StrVal != "76" {
t.Errorf("Expected StrVal=\"76\", got %+v", i)
}
}
type IntOrStringHolder struct {
IOrS IntOrString `json:"val"`
}
func TestIntOrStringUnmarshalYAML(t *testing.T) {
cases := []struct {
input string
result IntOrString
}{
{"val: 123\n", IntOrString{Kind: IntstrInt, IntVal: 123}},
{"val: \"123\"\n", IntOrString{Kind: IntstrString, StrVal: "123"}},
}
for _, c := range cases {
var result IntOrStringHolder
if err := yaml.Unmarshal([]byte(c.input), &result); err != nil {
t.Errorf("Failed to unmarshal input '%v': %v", c.input, err)
}
if result.IOrS != c.result {
t.Errorf("Failed to unmarshal input '%v': expected: %+v, got %+v", c.input, c.result, result)
}
}
}
func TestIntOrStringMarshalYAML(t *testing.T) {
cases := []struct {
input IntOrString
result string
}{
{IntOrString{Kind: IntstrInt, IntVal: 123}, "val: 123\n"},
{IntOrString{Kind: IntstrString, StrVal: "123"}, "val: \"123\"\n"},
}
for _, c := range cases {
input := IntOrStringHolder{c.input}
result, err := yaml.Marshal(&input)
if err != nil {
t.Errorf("Failed to marshal input '%v': %v", input, err)
}
if string(result) != c.result {
t.Errorf("Failed to marshal input '%v': expected: %+v, got %q", input, c.result, string(result))
}
}
}
func TestIntOrStringUnmarshalJSON(t *testing.T) {
cases := []struct {
input string
result IntOrString
}{
{"{\"val\": 123}", IntOrString{Kind: IntstrInt, IntVal: 123}},
{"{\"val\": \"123\"}", IntOrString{Kind: IntstrString, StrVal: "123"}},
}
for _, c := range cases {
var result IntOrStringHolder
if err := json.Unmarshal([]byte(c.input), &result); err != nil {
t.Errorf("Failed to unmarshal input '%v': %v", c.input, err)
}
if result.IOrS != c.result {
t.Errorf("Failed to unmarshal input '%v': expected %+v, got %+v", c.input, c.result, result)
}
}
}
func TestIntOrStringMarshalJSON(t *testing.T) {
cases := []struct {
input IntOrString
result string
}{
{IntOrString{Kind: IntstrInt, IntVal: 123}, "{\"val\":123}"},
{IntOrString{Kind: IntstrString, StrVal: "123"}, "{\"val\":\"123\"}"},
}
for _, c := range cases {
input := IntOrStringHolder{c.input}
result, err := json.Marshal(&input)
if err != nil {
t.Errorf("Failed to marshal input '%v': %v", input, err)
}
if string(result) != c.result {
t.Errorf("Failed to marshal input '%v': expected: %+v, got %q", input, c.result, string(result))
}
}
}
func TestIntOrStringMarshalJSONUnmarshalYAML(t *testing.T) {
cases := []struct {
input IntOrString
}{
{IntOrString{Kind: IntstrInt, IntVal: 123}},
{IntOrString{Kind: IntstrString, StrVal: "123"}},
}
for _, c := range cases {
input := IntOrStringHolder{c.input}
jsonMarshalled, err := json.Marshal(&input)
if err != nil {
t.Errorf("1: Failed to marshal input: '%v': %v", input, err)
}
var result IntOrStringHolder
err = yaml.Unmarshal(jsonMarshalled, &result)
if err != nil {
t.Errorf("2: Failed to unmarshal '%+v': %v", string(jsonMarshalled), err)
}
if !reflect.DeepEqual(input, result) {
t.Errorf("3: Failed to marshal input '%+v': got %+v", input, result)
}
}
}
func TestStringDiff(t *testing.T) {
diff := StringDiff("aaabb", "aaacc")
expect := "aaa\n\nA: bb\n\nB: cc\n\n"

View File

@ -23,7 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
. "github.com/onsi/ginkgo"
)
@ -279,7 +279,7 @@ func runServiceAndWorkloadForResourceConsumer(c *client.Client, ns, name, kind s
Spec: api.ServiceSpec{
Ports: []api.ServicePort{{
Port: port,
TargetPort: util.NewIntOrStringFromInt(targetPort),
TargetPort: intstr.FromInt(targetPort),
}},
Selector: map[string]string{

View File

@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
. "github.com/onsi/ginkgo"
@ -144,7 +145,7 @@ func (b webserverProbeBuilder) build() *api.Probe {
probe := &api.Probe{
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Port: util.NewIntOrStringFromInt(80),
Port: intstr.FromInt(80),
Path: "/",
},
},
@ -153,7 +154,7 @@ func (b webserverProbeBuilder) build() *api.Probe {
probe.InitialDelaySeconds = 30
}
if b.failing {
probe.HTTPGet.Port = util.NewIntOrStringFromInt(81)
probe.HTTPGet.Port = intstr.FromInt(81)
}
return probe
}

View File

@ -30,7 +30,7 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
. "github.com/onsi/ginkgo"
@ -105,7 +105,7 @@ func ruleByIndex(i int) extensions.IngressRule {
Path: fmt.Sprintf("/%v%d", pathPrefix, i),
Backend: extensions.IngressBackend{
ServiceName: fmt.Sprintf("%v%d", appPrefix, i),
ServicePort: util.NewIntOrStringFromInt(httpContainerPort),
ServicePort: intstr.FromInt(httpContainerPort),
},
},
},
@ -129,7 +129,7 @@ func createIngress(c *client.Client, ns string, start, num int) extensions.Ingre
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
ServiceName: fmt.Sprintf("%v%d", appPrefix, start),
ServicePort: util.NewIntOrStringFromInt(httpContainerPort),
ServicePort: intstr.FromInt(httpContainerPort),
},
Rules: []extensions.IngressRule{},
},

View File

@ -33,6 +33,7 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
)
@ -343,8 +344,8 @@ func (config *KubeProxyTestConfig) createNodePortService(selector map[string]str
Spec: api.ServiceSpec{
Type: api.ServiceTypeNodePort,
Ports: []api.ServicePort{
{Port: clusterHttpPort, Name: "http", Protocol: "TCP", NodePort: nodeHttpPort, TargetPort: util.NewIntOrStringFromInt(endpointHttpPort)},
{Port: clusterUdpPort, Name: "udp", Protocol: "UDP", NodePort: nodeUdpPort, TargetPort: util.NewIntOrStringFromInt(endpointUdpPort)},
{Port: clusterHttpPort, Name: "http", Protocol: "TCP", NodePort: nodeHttpPort, TargetPort: intstr.FromInt(endpointHttpPort)},
{Port: clusterUdpPort, Name: "udp", Protocol: "UDP", NodePort: nodeUdpPort, TargetPort: intstr.FromInt(endpointUdpPort)},
},
Selector: selector,
},
@ -366,7 +367,7 @@ func (config *KubeProxyTestConfig) createLoadBalancerService(selector map[string
Spec: api.ServiceSpec{
Type: api.ServiceTypeLoadBalancer,
Ports: []api.ServicePort{
{Port: loadBalancerHttpPort, Name: "http", Protocol: "TCP", TargetPort: util.NewIntOrStringFromInt(endpointHttpPort)},
{Port: loadBalancerHttpPort, Name: "http", Protocol: "TCP", TargetPort: intstr.FromInt(endpointHttpPort)},
},
Selector: selector,
},

View File

@ -26,7 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -117,7 +117,7 @@ var _ = Describe("Networking", func() {
Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 8080,
TargetPort: util.NewIntOrStringFromInt(8080),
TargetPort: intstr.FromInt(8080),
}},
Selector: map[string]string{
"name": svcname,

View File

@ -35,6 +35,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
@ -287,7 +288,7 @@ var _ = Describe("Pods", func() {
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/index.html",
Port: util.NewIntOrStringFromInt(8080),
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 30,
@ -396,7 +397,7 @@ var _ = Describe("Pods", func() {
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/index.html",
Port: util.NewIntOrStringFromInt(8080),
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 30,
@ -498,7 +499,7 @@ var _ = Describe("Pods", func() {
Spec: api.ServiceSpec{
Ports: []api.ServicePort{{
Port: 8765,
TargetPort: util.NewIntOrStringFromInt(8080),
TargetPort: intstr.FromInt(8080),
}},
Selector: map[string]string{
"name": serverName,
@ -611,7 +612,7 @@ var _ = Describe("Pods", func() {
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/healthz",
Port: util.NewIntOrStringFromInt(8080),
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 15,
@ -639,7 +640,7 @@ var _ = Describe("Pods", func() {
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/healthz",
Port: util.NewIntOrStringFromInt(8080),
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 5,
@ -673,7 +674,7 @@ var _ = Describe("Pods", func() {
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/read",
Port: util.NewIntOrStringFromInt(8080),
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 15,

View File

@ -30,6 +30,7 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -71,22 +72,22 @@ func proxyContext(version string) {
{
Name: "portname1",
Port: 80,
TargetPort: util.NewIntOrStringFromString("dest1"),
TargetPort: intstr.FromString("dest1"),
},
{
Name: "portname2",
Port: 81,
TargetPort: util.NewIntOrStringFromInt(162),
TargetPort: intstr.FromInt(162),
},
{
Name: "tlsportname1",
Port: 443,
TargetPort: util.NewIntOrStringFromString("tlsdest1"),
TargetPort: intstr.FromString("tlsdest1"),
},
{
Name: "tlsportname2",
Port: 444,
TargetPort: util.NewIntOrStringFromInt(462),
TargetPort: intstr.FromInt(462),
},
},
},

View File

@ -29,7 +29,7 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
. "github.com/onsi/ginkgo"
@ -123,8 +123,8 @@ func svcByName(name string, port int) *api.Service {
"name": name,
},
Ports: []api.ServicePort{{
Port: port,
TargetPort: util.NewIntOrStringFromInt(port),
Port: 9376,
TargetPort: intstr.FromInt(port),
}},
},
}

View File

@ -35,6 +35,7 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
)
@ -96,7 +97,7 @@ var _ = Describe("Services", func() {
Selector: labels,
Ports: []api.ServicePort{{
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
}},
},
}
@ -159,12 +160,12 @@ var _ = Describe("Services", func() {
{
Name: "portname1",
Port: 80,
TargetPort: util.NewIntOrStringFromString(svc1port),
TargetPort: intstr.FromString(svc1port),
},
{
Name: "portname2",
Port: 81,
TargetPort: util.NewIntOrStringFromString(svc2port),
TargetPort: intstr.FromString(svc2port),
},
},
},
@ -800,7 +801,7 @@ var _ = Describe("Services", func() {
svc1 := t1.BuildServiceSpec()
svc1.Spec.Type = api.ServiceTypeLoadBalancer
svc1.Spec.Ports[0].Port = servicePort
svc1.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(80)
svc1.Spec.Ports[0].TargetPort = intstr.FromInt(80)
_, err = t1.CreateService(svc1)
Expect(err).NotTo(HaveOccurred())
@ -825,7 +826,7 @@ var _ = Describe("Services", func() {
svc2 := t2.BuildServiceSpec()
svc2.Spec.Type = api.ServiceTypeLoadBalancer
svc2.Spec.Ports[0].Port = servicePort
svc2.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(80)
svc2.Spec.Ports[0].TargetPort = intstr.FromInt(80)
svc2.Spec.LoadBalancerIP = loadBalancerIP
_, err = t2.CreateService(svc2)
Expect(err).NotTo(HaveOccurred())
@ -1236,7 +1237,7 @@ func startServeHostnameService(c *client.Client, ns, name string, port, replicas
Spec: api.ServiceSpec{
Ports: []api.ServicePort{{
Port: port,
TargetPort: util.NewIntOrStringFromInt(9376),
TargetPort: intstr.FromInt(9376),
Protocol: "TCP",
}},
Selector: map[string]string{
@ -1411,7 +1412,7 @@ func (t *WebserverTest) BuildServiceSpec() *api.Service {
Selector: t.Labels,
Ports: []api.ServicePort{{
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
TargetPort: intstr.FromInt(80),
}},
},
}

View File

@ -35,7 +35,7 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
var (
@ -129,7 +129,7 @@ func main() {
Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 9376,
TargetPort: util.NewIntOrStringFromInt(9376),
TargetPort: intstr.FromInt(9376),
}},
Selector: map[string]string{
"name": "serve-hostname",

View File

@ -37,7 +37,7 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"
)
var (
@ -150,7 +150,7 @@ func main() {
Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 9376,
TargetPort: util.NewIntOrStringFromInt(9376),
TargetPort: intstr.FromInt(9376),
}},
Selector: map[string]string{
"name": "serve-hostname",