From cc3c0897ce1eaf22945e754ba2b0924eb2897773 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Mon, 21 Dec 2015 11:48:39 +0100 Subject: [PATCH] IntOrString pkg/util -> pkg/util/intstr --- pkg/api/deep_copy_generated.go | 8 ++-- pkg/api/serialization_test.go | 9 ++-- pkg/api/v1/deep_copy_generated.go | 8 ++-- pkg/api/v1beta3/deep_copy_generated.go | 8 ++-- pkg/cmd/admin/registry/registry.go | 2 +- pkg/cmd/admin/router/router.go | 4 +- pkg/cmd/server/kubernetes/master_config.go | 5 ++- pkg/deploy/api/types.go | 6 +-- pkg/deploy/api/v1/conversion.go | 10 ++--- pkg/deploy/api/v1/conversion_test.go | 43 ++++++++++---------- pkg/deploy/api/v1/defaults.go | 6 +-- pkg/deploy/api/v1/defaults_test.go | 15 +++---- pkg/deploy/api/v1/types.go | 6 +-- pkg/deploy/api/v1beta3/conversion.go | 10 ++--- pkg/deploy/api/v1beta3/conversion_test.go | 43 ++++++++++---------- pkg/deploy/api/v1beta3/defaults.go | 6 +-- pkg/deploy/api/v1beta3/defaults_test.go | 15 +++---- pkg/deploy/api/v1beta3/types.go | 6 +-- pkg/deploy/api/validation/validation.go | 16 ++++---- pkg/deploy/api/validation/validation_test.go | 24 +++++------ pkg/generate/app/pipeline.go | 4 +- pkg/generate/app/pipeline_test.go | 4 +- pkg/route/api/types.go | 4 +- pkg/route/api/v1/types.go | 4 +- pkg/route/api/v1beta3/types.go | 4 +- pkg/route/api/validation/validation_test.go | 6 +-- pkg/route/generator/generate.go | 4 +- pkg/route/generator/generate_test.go | 6 +-- test/integration/router_test.go | 4 +- test/util/verify.go | 4 +- 30 files changed, 151 insertions(+), 143 deletions(-) diff --git a/pkg/api/deep_copy_generated.go b/pkg/api/deep_copy_generated.go index 556cd44f2e6f..3109f70606db 100644 --- a/pkg/api/deep_copy_generated.go +++ b/pkg/api/deep_copy_generated.go @@ -16,7 +16,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" sets "k8s.io/kubernetes/pkg/util/sets" ) @@ -1672,12 +1672,12 @@ func deepCopy_api_RollingDeploymentStrategyParams(in deployapi.RollingDeployment if newVal, err := c.DeepCopy(in.MaxUnavailable); err != nil { return err } else { - out.MaxUnavailable = newVal.(util.IntOrString) + out.MaxUnavailable = newVal.(intstr.IntOrString) } if newVal, err := c.DeepCopy(in.MaxSurge); err != nil { return err } else { - out.MaxSurge = newVal.(util.IntOrString) + out.MaxSurge = newVal.(intstr.IntOrString) } if in.UpdatePercent != nil { out.UpdatePercent = new(int) @@ -2419,7 +2419,7 @@ func deepCopy_api_RoutePort(in routeapi.RoutePort, out *routeapi.RoutePort, c *c if newVal, err := c.DeepCopy(in.TargetPort); err != nil { return err } else { - out.TargetPort = newVal.(util.IntOrString) + out.TargetPort = newVal.(intstr.IntOrString) } return nil } diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index ca252e80053d..13f030fea6fa 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -17,6 +17,7 @@ import ( "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/sets" osapi "github.com/openshift/origin/pkg/api" @@ -269,11 +270,11 @@ func fuzzInternalObject(t *testing.T, forVersion string, item runtime.Object, se } } if c.RandBool() { - params.MaxUnavailable = util.NewIntOrStringFromInt(int(c.RandUint64())) - params.MaxSurge = util.NewIntOrStringFromInt(int(c.RandUint64())) + params.MaxUnavailable = intstr.FromInt(int(c.RandUint64())) + params.MaxSurge = intstr.FromInt(int(c.RandUint64())) } else { - params.MaxSurge = util.NewIntOrStringFromString(fmt.Sprintf("%d%%", c.RandUint64())) - params.MaxUnavailable = util.NewIntOrStringFromString(fmt.Sprintf("%d%%", c.RandUint64())) + params.MaxSurge = intstr.FromString(fmt.Sprintf("%d%%", c.RandUint64())) + params.MaxUnavailable = intstr.FromString(fmt.Sprintf("%d%%", c.RandUint64())) } j.RollingParams = params default: diff --git a/pkg/api/v1/deep_copy_generated.go b/pkg/api/v1/deep_copy_generated.go index dcd685aab872..53562e81c318 100644 --- a/pkg/api/v1/deep_copy_generated.go +++ b/pkg/api/v1/deep_copy_generated.go @@ -17,7 +17,7 @@ import ( pkgapiv1 "k8s.io/kubernetes/pkg/api/v1" 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" ) func deepCopy_v1_AuthorizationAttributes(in v1.AuthorizationAttributes, out *v1.AuthorizationAttributes, c *conversion.Cloner) error { @@ -1721,7 +1721,7 @@ func deepCopy_v1_RollingDeploymentStrategyParams(in deployapiv1.RollingDeploymen if newVal, err := c.DeepCopy(in.MaxUnavailable); err != nil { return err } else { - out.MaxUnavailable = newVal.(*util.IntOrString) + out.MaxUnavailable = newVal.(*intstr.IntOrString) } } else { out.MaxUnavailable = nil @@ -1730,7 +1730,7 @@ func deepCopy_v1_RollingDeploymentStrategyParams(in deployapiv1.RollingDeploymen if newVal, err := c.DeepCopy(in.MaxSurge); err != nil { return err } else { - out.MaxSurge = newVal.(*util.IntOrString) + out.MaxSurge = newVal.(*intstr.IntOrString) } } else { out.MaxSurge = nil @@ -2332,7 +2332,7 @@ func deepCopy_v1_RoutePort(in routeapiv1.RoutePort, out *routeapiv1.RoutePort, c if newVal, err := c.DeepCopy(in.TargetPort); err != nil { return err } else { - out.TargetPort = newVal.(util.IntOrString) + out.TargetPort = newVal.(intstr.IntOrString) } return nil } diff --git a/pkg/api/v1beta3/deep_copy_generated.go b/pkg/api/v1beta3/deep_copy_generated.go index ccef6c90dc72..84a8afa2034d 100644 --- a/pkg/api/v1beta3/deep_copy_generated.go +++ b/pkg/api/v1beta3/deep_copy_generated.go @@ -17,7 +17,7 @@ import ( pkgapiv1beta3 "k8s.io/kubernetes/pkg/api/v1beta3" 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" ) func deepCopy_v1beta3_AuthorizationAttributes(in v1beta3.AuthorizationAttributes, out *v1beta3.AuthorizationAttributes, c *conversion.Cloner) error { @@ -1729,7 +1729,7 @@ func deepCopy_v1beta3_RollingDeploymentStrategyParams(in deployapiv1beta3.Rollin if newVal, err := c.DeepCopy(in.MaxUnavailable); err != nil { return err } else { - out.MaxUnavailable = newVal.(*util.IntOrString) + out.MaxUnavailable = newVal.(*intstr.IntOrString) } } else { out.MaxUnavailable = nil @@ -1738,7 +1738,7 @@ func deepCopy_v1beta3_RollingDeploymentStrategyParams(in deployapiv1beta3.Rollin if newVal, err := c.DeepCopy(in.MaxSurge); err != nil { return err } else { - out.MaxSurge = newVal.(*util.IntOrString) + out.MaxSurge = newVal.(*intstr.IntOrString) } } else { out.MaxSurge = nil @@ -2322,7 +2322,7 @@ func deepCopy_v1beta3_RoutePort(in routeapiv1beta3.RoutePort, out *routeapiv1bet if newVal, err := c.DeepCopy(in.TargetPort); err != nil { return err } else { - out.TargetPort = newVal.(util.IntOrString) + out.TargetPort = newVal.(intstr.IntOrString) } return nil } diff --git a/pkg/cmd/admin/registry/registry.go b/pkg/cmd/admin/registry/registry.go index 5046fa6a8986..573b2ec94b6b 100644 --- a/pkg/cmd/admin/registry/registry.go +++ b/pkg/cmd/admin/registry/registry.go @@ -258,7 +258,7 @@ func RunCmdRegistry(f *clientcmd.Factory, cmd *cobra.Command, out io.Writer, cfg Handler: kapi.Handler{ HTTPGet: &kapi.HTTPGetAction{ Path: "/healthz", - Port: util.NewIntOrStringFromInt(5000), + Port: intstr.FromInt(5000), }, }, }, diff --git a/pkg/cmd/admin/router/router.go b/pkg/cmd/admin/router/router.go index 0a2ad749c35a..d17e88aa5584 100644 --- a/pkg/cmd/admin/router/router.go +++ b/pkg/cmd/admin/router/router.go @@ -22,6 +22,7 @@ import ( "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/runtime" kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "github.com/openshift/origin/pkg/cmd/util/clientcmd" "github.com/openshift/origin/pkg/cmd/util/variable" @@ -341,7 +342,8 @@ func generateProbeConfigForRouter(cfg *RouterConfig, ports []kapi.ContainerPort) probe.Handler.HTTPGet = &kapi.HTTPGetAction{ Path: "/healthz", - Port: kutil.IntOrString{ + Port: intstr.IntOrString{ + Type: intstr.Int, IntVal: healthzPort, }, } diff --git a/pkg/cmd/server/kubernetes/master_config.go b/pkg/cmd/server/kubernetes/master_config.go index 07308f7a9451..0e81595feb8e 100644 --- a/pkg/cmd/server/kubernetes/master_config.go +++ b/pkg/cmd/server/kubernetes/master_config.go @@ -22,6 +22,7 @@ import ( "k8s.io/kubernetes/pkg/master" "k8s.io/kubernetes/pkg/util" kerrors "k8s.io/kubernetes/pkg/util/errors" + "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/sets" saadmit "k8s.io/kubernetes/plugin/pkg/admission/serviceaccount" @@ -229,8 +230,8 @@ func BuildKubernetesMasterConfig(options configapi.MasterConfig, requestContextM return nil, fmt.Errorf("invalid DNS port: %v", err) } m.ExtraServicePorts = append(m.ExtraServicePorts, - kapi.ServicePort{Name: "dns", Port: dnsPort, Protocol: kapi.ProtocolUDP, TargetPort: util.NewIntOrStringFromInt(dnsPort)}, - kapi.ServicePort{Name: "dns-tcp", Port: dnsPort, Protocol: kapi.ProtocolTCP, TargetPort: util.NewIntOrStringFromInt(dnsPort)}, + kapi.ServicePort{Name: "dns", Port: dnsPort, Protocol: kapi.ProtocolUDP, TargetPort: intstr.FromInt(dnsPort)}, + kapi.ServicePort{Name: "dns-tcp", Port: dnsPort, Protocol: kapi.ProtocolTCP, TargetPort: intstr.FromInt(dnsPort)}, ) m.ExtraEndpointPorts = append(m.ExtraEndpointPorts, kapi.EndpointPort{Name: "dns", Port: dnsPort, Protocol: kapi.ProtocolUDP}, diff --git a/pkg/deploy/api/types.go b/pkg/deploy/api/types.go index 5a8fd1bfe1a2..d2793e10cb81 100644 --- a/pkg/deploy/api/types.go +++ b/pkg/deploy/api/types.go @@ -3,7 +3,7 @@ package api import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/unversioned" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) // DeploymentStatus describes the possible states a deployment can be in. @@ -134,7 +134,7 @@ type RollingDeploymentStrategyParams 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 kutil.IntOrString + MaxUnavailable intstr.IntOrString // The maximum number of pods that can be scheduled above the original number of // pods. // Value can be an absolute number (ex: 5) or a percentage of total pods at @@ -145,7 +145,7 @@ type RollingDeploymentStrategyParams 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 kutil.IntOrString + MaxSurge intstr.IntOrString // UpdatePercent is the percentage of replicas to scale up or down each // interval. If nil, one replica will be scaled up and down each interval. // If negative, the scale order will be down/up instead of up/down. diff --git a/pkg/deploy/api/v1/conversion.go b/pkg/deploy/api/v1/conversion.go index 62cb814b7892..41ff83d25d02 100644 --- a/pkg/deploy/api/v1/conversion.go +++ b/pkg/deploy/api/v1/conversion.go @@ -6,7 +6,7 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/conversion" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" oapi "github.com/openshift/origin/pkg/api" newer "github.com/openshift/origin/pkg/deploy/api" @@ -229,7 +229,7 @@ func convert_v1_RollingDeploymentStrategyParams_To_api_RollingDeploymentStrategy } if in.UpdatePercent != nil { - pct := kutil.NewIntOrStringFromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) + pct := intstr.FromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) if *in.UpdatePercent > 0 { out.MaxSurge = pct } else { @@ -264,13 +264,13 @@ func convert_api_RollingDeploymentStrategyParams_To_v1_RollingDeploymentStrategy } if out.MaxUnavailable == nil { - out.MaxUnavailable = &kutil.IntOrString{} + out.MaxUnavailable = &intstr.IntOrString{} } if out.MaxSurge == nil { - out.MaxSurge = &kutil.IntOrString{} + out.MaxSurge = &intstr.IntOrString{} } if in.UpdatePercent != nil { - pct := kutil.NewIntOrStringFromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) + pct := intstr.FromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) if *in.UpdatePercent > 0 { out.MaxSurge = &pct } else { diff --git a/pkg/deploy/api/v1/conversion_test.go b/pkg/deploy/api/v1/conversion_test.go index 65205d32a7cc..29d59d1b7e58 100644 --- a/pkg/deploy/api/v1/conversion_test.go +++ b/pkg/deploy/api/v1/conversion_test.go @@ -7,6 +7,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" kapiv1 "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" newer "github.com/openshift/origin/pkg/deploy/api" testutil "github.com/openshift/origin/test/util/api" @@ -56,8 +57,8 @@ func Test_convert_v1_RollingDeploymentStrategyParams_To_api_RollingDeploymentStr IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: util.NewIntOrStringFromInt(0), - MaxUnavailable: util.NewIntOrStringFromString("25%"), + MaxSurge: intstr.FromInt(0), + MaxUnavailable: intstr.FromString("25%"), Pre: &newer.LifecycleHook{ FailurePolicy: newer.LifecycleHookFailurePolicyIgnore, }, @@ -78,8 +79,8 @@ func Test_convert_v1_RollingDeploymentStrategyParams_To_api_RollingDeploymentStr IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(25), - MaxSurge: util.NewIntOrStringFromString("25%"), - MaxUnavailable: util.NewIntOrStringFromInt(0), + MaxSurge: intstr.FromString("25%"), + MaxUnavailable: intstr.FromInt(0), }, }, { @@ -87,15 +88,15 @@ func Test_convert_v1_RollingDeploymentStrategyParams_To_api_RollingDeploymentStr UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(10)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(20)), + MaxSurge: newIntOrString(intstr.FromInt(10)), + MaxUnavailable: newIntOrString(intstr.FromInt(20)), }, out: &newer.RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: util.NewIntOrStringFromInt(10), - MaxUnavailable: util.NewIntOrStringFromInt(20), + MaxSurge: intstr.FromInt(10), + MaxUnavailable: intstr.FromInt(20), }, }, } @@ -122,16 +123,16 @@ func Test_convert_api_RollingDeploymentStrategyParams_To_v1_RollingDeploymentStr IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: util.NewIntOrStringFromInt(0), - MaxUnavailable: util.NewIntOrStringFromString("25%"), + MaxSurge: intstr.FromInt(0), + MaxUnavailable: intstr.FromString("25%"), }, out: &RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(0)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromString("25%")), + MaxSurge: newIntOrString(intstr.FromInt(0)), + MaxUnavailable: newIntOrString(intstr.FromString("25%")), }, }, { @@ -140,16 +141,16 @@ func Test_convert_api_RollingDeploymentStrategyParams_To_v1_RollingDeploymentStr IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(25), - MaxSurge: util.NewIntOrStringFromString("25%"), - MaxUnavailable: util.NewIntOrStringFromInt(0), + MaxSurge: intstr.FromString("25%"), + MaxUnavailable: intstr.FromInt(0), }, out: &RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(25), - MaxSurge: newIntOrString(util.NewIntOrStringFromString("25%")), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(0)), + MaxSurge: newIntOrString(intstr.FromString("25%")), + MaxUnavailable: newIntOrString(intstr.FromInt(0)), }, }, { @@ -157,15 +158,15 @@ func Test_convert_api_RollingDeploymentStrategyParams_To_v1_RollingDeploymentStr UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: util.NewIntOrStringFromInt(10), - MaxUnavailable: util.NewIntOrStringFromInt(20), + MaxSurge: intstr.FromInt(10), + MaxUnavailable: intstr.FromInt(20), }, out: &RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(10)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(20)), + MaxSurge: newIntOrString(intstr.FromInt(10)), + MaxUnavailable: newIntOrString(intstr.FromInt(20)), }, }, } @@ -189,7 +190,7 @@ func newInt(val int) *int { return &val } -func newIntOrString(ios util.IntOrString) *util.IntOrString { +func newIntOrString(ios intstr.IntOrString) *intstr.IntOrString { return &ios } diff --git a/pkg/deploy/api/v1/defaults.go b/pkg/deploy/api/v1/defaults.go index f9930fcbb876..e6b24d77192f 100644 --- a/pkg/deploy/api/v1/defaults.go +++ b/pkg/deploy/api/v1/defaults.go @@ -2,7 +2,7 @@ package v1 import ( "k8s.io/kubernetes/pkg/api" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" deployapi "github.com/openshift/origin/pkg/deploy/api" ) @@ -49,11 +49,11 @@ func init() { if obj.UpdatePercent == nil { // Apply defaults. if obj.MaxUnavailable == nil { - maxUnavailable := kutil.NewIntOrStringFromString("25%") + maxUnavailable := intstr.FromString("25%") obj.MaxUnavailable = &maxUnavailable } if obj.MaxSurge == nil { - maxSurge := kutil.NewIntOrStringFromString("25%") + maxSurge := intstr.FromString("25%") obj.MaxSurge = &maxSurge } } diff --git a/pkg/deploy/api/v1/defaults_test.go b/pkg/deploy/api/v1/defaults_test.go index 884b5081f0cf..121f75a1d57a 100644 --- a/pkg/deploy/api/v1/defaults_test.go +++ b/pkg/deploy/api/v1/defaults_test.go @@ -7,6 +7,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" v1 "github.com/openshift/origin/pkg/api/v1" deployapi "github.com/openshift/origin/pkg/deploy/api" @@ -14,8 +15,8 @@ import ( ) func TestDefaults(t *testing.T) { - defaultIntOrString := util.NewIntOrStringFromString("25%") - differentIntOrString := util.NewIntOrStringFromInt(5) + defaultIntOrString := intstr.FromString("25%") + differentIntOrString := intstr.FromInt(5) tests := []struct { original *deployv1.DeploymentConfig expected *deployv1.DeploymentConfig @@ -110,8 +111,8 @@ func TestDefaults(t *testing.T) { IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(50), - MaxSurge: newIntOrString(util.NewIntOrStringFromString("50%")), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(0)), + MaxSurge: newIntOrString(intstr.FromString("50%")), + MaxUnavailable: newIntOrString(intstr.FromInt(0)), }, }, Triggers: []deployv1.DeploymentTriggerPolicy{ @@ -150,8 +151,8 @@ func TestDefaults(t *testing.T) { IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(0)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromString("25%")), + MaxSurge: newIntOrString(intstr.FromInt(0)), + MaxUnavailable: newIntOrString(intstr.FromString("25%")), }, }, Triggers: []deployv1.DeploymentTriggerPolicy{ @@ -208,6 +209,6 @@ func newInt(val int) *int { return &val } -func newIntOrString(ios util.IntOrString) *util.IntOrString { +func newIntOrString(ios intstr.IntOrString) *intstr.IntOrString { return &ios } diff --git a/pkg/deploy/api/v1/types.go b/pkg/deploy/api/v1/types.go index deaba98421e7..48e566a9b6a5 100644 --- a/pkg/deploy/api/v1/types.go +++ b/pkg/deploy/api/v1/types.go @@ -3,7 +3,7 @@ package v1 import ( "k8s.io/kubernetes/pkg/api/unversioned" kapi "k8s.io/kubernetes/pkg/api/v1" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) // DeploymentPhase describes the possible states a deployment can be in. @@ -137,7 +137,7 @@ type RollingDeploymentStrategyParams struct { // RC 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 *kutil.IntOrString `json:"maxUnavailable,omitempty" description:"max number of pods that can be unavailable during the update; value can be an absolute number or a percentage of total pods at start of update"` + MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" description:"max number of pods that can be unavailable during the update; value can be an absolute number or a percentage of total pods at start of update"` // MaxSurge is the maximum number of pods that can be scheduled above the // original number of pods. Value can be an absolute number (ex: 5) or a // percentage of total pods at the start of the update (ex: 10%). Absolute @@ -150,7 +150,7 @@ type RollingDeploymentStrategyParams struct { // 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 *kutil.IntOrString `json:"maxSurge,omitempty" description:"max number of pods that can be scheduled above the original number of pods; value can be an absolute number or a percentage of total pods at start of update"` + MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty" description:"max number of pods that can be scheduled above the original number of pods; value can be an absolute number or a percentage of total pods at start of update"` // UpdatePercent is the percentage of replicas to scale up or down each // interval. If nil, one replica will be scaled up and down each interval. // If negative, the scale order will be down/up instead of up/down. diff --git a/pkg/deploy/api/v1beta3/conversion.go b/pkg/deploy/api/v1beta3/conversion.go index 62709bd46722..db386ed61665 100644 --- a/pkg/deploy/api/v1beta3/conversion.go +++ b/pkg/deploy/api/v1beta3/conversion.go @@ -6,7 +6,7 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/conversion" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" newer "github.com/openshift/origin/pkg/deploy/api" imageapi "github.com/openshift/origin/pkg/image/api" @@ -228,7 +228,7 @@ func convert_v1beta3_RollingDeploymentStrategyParams_To_api_RollingDeploymentStr } if in.UpdatePercent != nil { - pct := kutil.NewIntOrStringFromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) + pct := intstr.FromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) if *in.UpdatePercent > 0 { out.MaxSurge = pct } else { @@ -263,13 +263,13 @@ func convert_api_RollingDeploymentStrategyParams_To_v1beta3_RollingDeploymentStr } if out.MaxUnavailable == nil { - out.MaxUnavailable = &kutil.IntOrString{} + out.MaxUnavailable = &intstr.IntOrString{} } if out.MaxSurge == nil { - out.MaxSurge = &kutil.IntOrString{} + out.MaxSurge = &intstr.IntOrString{} } if in.UpdatePercent != nil { - pct := kutil.NewIntOrStringFromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) + pct := intstr.FromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent))))) if *in.UpdatePercent > 0 { out.MaxSurge = &pct } else { diff --git a/pkg/deploy/api/v1beta3/conversion_test.go b/pkg/deploy/api/v1beta3/conversion_test.go index d3c6aff02f6b..4c84ebec6658 100644 --- a/pkg/deploy/api/v1beta3/conversion_test.go +++ b/pkg/deploy/api/v1beta3/conversion_test.go @@ -7,6 +7,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" kapiv1beta3 "k8s.io/kubernetes/pkg/api/v1beta3" "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" newer "github.com/openshift/origin/pkg/deploy/api" ) @@ -55,8 +56,8 @@ func Test_convert_v1beta3_RollingDeploymentStrategyParams_To_api_RollingDeployme IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: util.NewIntOrStringFromInt(0), - MaxUnavailable: util.NewIntOrStringFromString("25%"), + MaxSurge: intstr.FromInt(0), + MaxUnavailable: intstr.FromString("25%"), Pre: &newer.LifecycleHook{ FailurePolicy: newer.LifecycleHookFailurePolicyIgnore, }, @@ -77,8 +78,8 @@ func Test_convert_v1beta3_RollingDeploymentStrategyParams_To_api_RollingDeployme IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(25), - MaxSurge: util.NewIntOrStringFromString("25%"), - MaxUnavailable: util.NewIntOrStringFromInt(0), + MaxSurge: intstr.FromString("25%"), + MaxUnavailable: intstr.FromInt(0), }, }, { @@ -86,15 +87,15 @@ func Test_convert_v1beta3_RollingDeploymentStrategyParams_To_api_RollingDeployme UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(10)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(20)), + MaxSurge: newIntOrString(intstr.FromInt(10)), + MaxUnavailable: newIntOrString(intstr.FromInt(20)), }, out: &newer.RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: util.NewIntOrStringFromInt(10), - MaxUnavailable: util.NewIntOrStringFromInt(20), + MaxSurge: intstr.FromInt(10), + MaxUnavailable: intstr.FromInt(20), }, }, } @@ -121,16 +122,16 @@ func Test_convert_api_RollingDeploymentStrategyParams_To_v1beta3_RollingDeployme IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: util.NewIntOrStringFromInt(0), - MaxUnavailable: util.NewIntOrStringFromString("25%"), + MaxSurge: intstr.FromInt(0), + MaxUnavailable: intstr.FromString("25%"), }, out: &RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-25), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(0)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromString("25%")), + MaxSurge: newIntOrString(intstr.FromInt(0)), + MaxUnavailable: newIntOrString(intstr.FromString("25%")), }, }, { @@ -139,16 +140,16 @@ func Test_convert_api_RollingDeploymentStrategyParams_To_v1beta3_RollingDeployme IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(25), - MaxSurge: util.NewIntOrStringFromString("25%"), - MaxUnavailable: util.NewIntOrStringFromInt(0), + MaxSurge: intstr.FromString("25%"), + MaxUnavailable: intstr.FromInt(0), }, out: &RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(25), - MaxSurge: newIntOrString(util.NewIntOrStringFromString("25%")), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(0)), + MaxSurge: newIntOrString(intstr.FromString("25%")), + MaxUnavailable: newIntOrString(intstr.FromInt(0)), }, }, { @@ -156,15 +157,15 @@ func Test_convert_api_RollingDeploymentStrategyParams_To_v1beta3_RollingDeployme UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: util.NewIntOrStringFromInt(10), - MaxUnavailable: util.NewIntOrStringFromInt(20), + MaxSurge: intstr.FromInt(10), + MaxUnavailable: intstr.FromInt(20), }, out: &RollingDeploymentStrategyParams{ UpdatePeriodSeconds: newInt64(5), IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(10)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(20)), + MaxSurge: newIntOrString(intstr.FromInt(10)), + MaxUnavailable: newIntOrString(intstr.FromInt(20)), }, }, } @@ -188,6 +189,6 @@ func newInt(val int) *int { return &val } -func newIntOrString(ios util.IntOrString) *util.IntOrString { +func newIntOrString(ios intstr.IntOrString) *intstr.IntOrString { return &ios } diff --git a/pkg/deploy/api/v1beta3/defaults.go b/pkg/deploy/api/v1beta3/defaults.go index 275ec04d961e..807bfc09b840 100644 --- a/pkg/deploy/api/v1beta3/defaults.go +++ b/pkg/deploy/api/v1beta3/defaults.go @@ -2,7 +2,7 @@ package v1beta3 import ( "k8s.io/kubernetes/pkg/api" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" deployapi "github.com/openshift/origin/pkg/deploy/api" ) @@ -42,11 +42,11 @@ func init() { if obj.UpdatePercent == nil { // Apply defaults. if obj.MaxUnavailable == nil { - maxUnavailable := kutil.NewIntOrStringFromString("25%") + maxUnavailable := intstr.FromString("25%") obj.MaxUnavailable = &maxUnavailable } if obj.MaxSurge == nil { - maxSurge := kutil.NewIntOrStringFromString("25%") + maxSurge := intstr.FromString("25%") obj.MaxSurge = &maxSurge } } diff --git a/pkg/deploy/api/v1beta3/defaults_test.go b/pkg/deploy/api/v1beta3/defaults_test.go index a981293021f7..cf27f5e27051 100644 --- a/pkg/deploy/api/v1beta3/defaults_test.go +++ b/pkg/deploy/api/v1beta3/defaults_test.go @@ -7,6 +7,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" v1 "github.com/openshift/origin/pkg/api/v1beta3" deployapi "github.com/openshift/origin/pkg/deploy/api" @@ -14,8 +15,8 @@ import ( ) func TestDefaults(t *testing.T) { - defaultIntOrString := util.NewIntOrStringFromString("25%") - differentIntOrString := util.NewIntOrStringFromInt(5) + defaultIntOrString := intstr.FromString("25%") + differentIntOrString := intstr.FromInt(5) tests := []struct { original *deployv1.DeploymentConfig expected *deployv1.DeploymentConfig @@ -105,8 +106,8 @@ func TestDefaults(t *testing.T) { IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(50), - MaxSurge: newIntOrString(util.NewIntOrStringFromString("50%")), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromInt(0)), + MaxSurge: newIntOrString(intstr.FromString("50%")), + MaxUnavailable: newIntOrString(intstr.FromInt(0)), }, }, Triggers: []deployv1.DeploymentTriggerPolicy{ @@ -145,8 +146,8 @@ func TestDefaults(t *testing.T) { IntervalSeconds: newInt64(6), TimeoutSeconds: newInt64(7), UpdatePercent: newInt(-50), - MaxSurge: newIntOrString(util.NewIntOrStringFromInt(0)), - MaxUnavailable: newIntOrString(util.NewIntOrStringFromString("50%")), + MaxSurge: newIntOrString(intstr.FromInt(0)), + MaxUnavailable: newIntOrString(intstr.FromString("50%")), }, }, Triggers: []deployv1.DeploymentTriggerPolicy{ @@ -204,6 +205,6 @@ func newInt(val int) *int { return &val } -func newIntOrString(ios util.IntOrString) *util.IntOrString { +func newIntOrString(ios intstr.IntOrString) *intstr.IntOrString { return &ios } diff --git a/pkg/deploy/api/v1beta3/types.go b/pkg/deploy/api/v1beta3/types.go index 3148f1d9fddb..0aed0b4f9042 100644 --- a/pkg/deploy/api/v1beta3/types.go +++ b/pkg/deploy/api/v1beta3/types.go @@ -3,7 +3,7 @@ package v1beta3 import ( "k8s.io/kubernetes/pkg/api/unversioned" kapi "k8s.io/kubernetes/pkg/api/v1beta3" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) // DeploymentPhase describes the possible states a deployment can be in. @@ -137,7 +137,7 @@ type RollingDeploymentStrategyParams struct { // RC 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 *kutil.IntOrString `json:"maxUnavailable,omitempty" description:"max number of pods that can be unavailable during the update; value can be an absolute number or a percentage of total pods at start of update"` + MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" description:"max number of pods that can be unavailable during the update; value can be an absolute number or a percentage of total pods at start of update"` // MaxSurge is the maximum number of pods that can be scheduled above the // original number of pods. Value can be an absolute number (ex: 5) or a // percentage of total pods at the start of the update (ex: 10%). Absolute @@ -150,7 +150,7 @@ type RollingDeploymentStrategyParams struct { // 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 *kutil.IntOrString `json:"maxSurge,omitempty" description:"max number of pods that can be scheduled above the original number of pods; value can be an absolute number or a percentage of total pods at start of update"` + MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty" description:"max number of pods that can be scheduled above the original number of pods; value can be an absolute number or a percentage of total pods at start of update"` // UpdatePercent is the percentage of replicas to scale up or down each // interval. If nil, one replica will be scaled up and down each interval. // If negative, the scale order will be down/up instead of up/down. diff --git a/pkg/deploy/api/validation/validation.go b/pkg/deploy/api/validation/validation.go index 4508d35cb2cc..b3ef9a8f958f 100644 --- a/pkg/deploy/api/validation/validation.go +++ b/pkg/deploy/api/validation/validation.go @@ -8,7 +8,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/validation" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/sets" kvalidation "k8s.io/kubernetes/pkg/util/validation" "k8s.io/kubernetes/pkg/util/validation/field" @@ -288,28 +288,28 @@ func validateImageChangeParams(params *deployapi.DeploymentTriggerImageChangePar return errs } -func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fldPath *field.Path) field.ErrorList { +func ValidatePositiveIntOrPercent(intOrPercent intstr.IntOrString, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} - if intOrPercent.Kind == util.IntstrString { + if intOrPercent.Type == intstr.String { if !IsValidPercent(intOrPercent.StrVal) { allErrs = append(allErrs, field.Invalid(fldPath, intOrPercent, "value should be int(5) or percentage(5%)")) } - } else if intOrPercent.Kind == util.IntstrInt { + } else if intOrPercent.Type == intstr.Int { allErrs = append(allErrs, ValidatePositiveField(int64(intOrPercent.IntVal), fldPath)...) } return allErrs } -func getPercentValue(intOrStringValue util.IntOrString) (int, bool) { - if intOrStringValue.Kind != util.IntstrString || !IsValidPercent(intOrStringValue.StrVal) { +func getPercentValue(intOrStringValue intstr.IntOrString) (int, bool) { + if intOrStringValue.Type != intstr.String || !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 @@ -317,7 +317,7 @@ func getIntOrPercentValue(intOrStringValue util.IntOrString) int { return intOrStringValue.IntVal } -func IsNotMoreThan100Percent(intOrStringValue util.IntOrString, fldPath *field.Path) field.ErrorList { +func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} value, isPercent := getPercentValue(intOrStringValue) if !isPercent || value <= 100 { diff --git a/pkg/deploy/api/validation/validation_test.go b/pkg/deploy/api/validation/validation_test.go index 712ecf74f019..cb2aac60a2be 100644 --- a/pkg/deploy/api/validation/validation_test.go +++ b/pkg/deploy/api/validation/validation_test.go @@ -4,7 +4,7 @@ import ( "testing" kapi "k8s.io/kubernetes/pkg/api" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/validation/field" "github.com/openshift/origin/pkg/deploy/api" @@ -32,7 +32,7 @@ func rollingConfig(interval, updatePeriod, timeout int) api.DeploymentConfig { IntervalSeconds: mkint64p(interval), UpdatePeriodSeconds: mkint64p(updatePeriod), TimeoutSeconds: mkint64p(timeout), - MaxSurge: kutil.NewIntOrStringFromInt(1), + MaxSurge: intstr.FromInt(1), }, }, ControllerTemplate: test.OkControllerTemplate(), @@ -40,7 +40,7 @@ func rollingConfig(interval, updatePeriod, timeout int) api.DeploymentConfig { } } -func rollingConfigMax(maxSurge, maxUnavailable kutil.IntOrString) api.DeploymentConfig { +func rollingConfigMax(maxSurge, maxUnavailable intstr.IntOrString) api.DeploymentConfig { return api.DeploymentConfig{ ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"}, Triggers: manualTrigger(), @@ -372,7 +372,7 @@ func TestValidateDeploymentConfigMissingFields(t *testing.T) { IntervalSeconds: mkint64p(1), UpdatePeriodSeconds: mkint64p(1), TimeoutSeconds: mkint64p(20), - MaxSurge: kutil.NewIntOrStringFromInt(1), + MaxSurge: intstr.FromInt(1), Pre: &api.LifecycleHook{ ExecNewPod: &api.ExecNewPodHook{ Command: []string{"cmd"}, @@ -388,42 +388,42 @@ func TestValidateDeploymentConfigMissingFields(t *testing.T) { "template.strategy.rollingParams.pre.failurePolicy", }, "both maxSurge and maxUnavailable 0 template.strategy.rollingParams.maxUnavailable": { - rollingConfigMax(kutil.NewIntOrStringFromInt(0), kutil.NewIntOrStringFromInt(0)), + rollingConfigMax(intstr.FromInt(0), intstr.FromInt(0)), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxUnavailable", }, "invalid lower bound template.strategy.rollingParams.maxUnavailable": { - rollingConfigMax(kutil.NewIntOrStringFromInt(0), kutil.NewIntOrStringFromInt(-100)), + rollingConfigMax(intstr.FromInt(0), intstr.FromInt(-100)), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxUnavailable", }, "invalid lower bound template.strategy.rollingParams.maxSurge": { - rollingConfigMax(kutil.NewIntOrStringFromInt(-1), kutil.NewIntOrStringFromInt(0)), + rollingConfigMax(intstr.FromInt(-1), intstr.FromInt(0)), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxSurge", }, "both maxSurge and maxUnavailable 0 percent template.strategy.rollingParams.maxUnavailable": { - rollingConfigMax(kutil.NewIntOrStringFromString("0%"), kutil.NewIntOrStringFromString("0%")), + rollingConfigMax(intstr.FromString("0%"), intstr.FromString("0%")), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxUnavailable", }, "invalid lower bound percent template.strategy.rollingParams.maxUnavailable": { - rollingConfigMax(kutil.NewIntOrStringFromInt(0), kutil.NewIntOrStringFromString("-1%")), + rollingConfigMax(intstr.FromInt(0), intstr.FromString("-1%")), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxUnavailable", }, "invalid upper bound percent template.strategy.rollingParams.maxUnavailable": { - rollingConfigMax(kutil.NewIntOrStringFromInt(0), kutil.NewIntOrStringFromString("101%")), + rollingConfigMax(intstr.FromInt(0), intstr.FromString("101%")), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxUnavailable", }, "invalid percent template.strategy.rollingParams.maxUnavailable": { - rollingConfigMax(kutil.NewIntOrStringFromInt(0), kutil.NewIntOrStringFromString("foo")), + rollingConfigMax(intstr.FromInt(0), intstr.FromString("foo")), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxUnavailable", }, "invalid percent template.strategy.rollingParams.maxSurge": { - rollingConfigMax(kutil.NewIntOrStringFromString("foo"), kutil.NewIntOrStringFromString("100%")), + rollingConfigMax(intstr.FromString("foo"), intstr.FromString("100%")), field.ErrorTypeInvalid, "template.strategy.rollingParams.maxSurge", }, diff --git a/pkg/generate/app/pipeline.go b/pkg/generate/app/pipeline.go index 319d1ab3e8e4..c83cd078b04a 100644 --- a/pkg/generate/app/pipeline.go +++ b/pkg/generate/app/pipeline.go @@ -10,7 +10,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/validation" "k8s.io/kubernetes/pkg/runtime" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" kuval "k8s.io/kubernetes/pkg/util/validation" deploy "github.com/openshift/origin/pkg/deploy/api" @@ -349,7 +349,7 @@ func AddServices(objects Objects, firstPortOnly bool) Objects { Name: name, Port: p.ContainerPort, Protocol: p.Protocol, - TargetPort: kutil.NewIntOrStringFromInt(p.ContainerPort), + TargetPort: intstr.FromInt(p.ContainerPort), }) if firstPortOnly { break diff --git a/pkg/generate/app/pipeline_test.go b/pkg/generate/app/pipeline_test.go index 6374fccc2c3a..36187215da71 100644 --- a/pkg/generate/app/pipeline_test.go +++ b/pkg/generate/app/pipeline_test.go @@ -7,7 +7,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/runtime" - kutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" deployapi "github.com/openshift/origin/pkg/deploy/api" imageapi "github.com/openshift/origin/pkg/image/api" @@ -67,7 +67,7 @@ func expectedService(name string, ports ...portDesc) *kapi.Service { Name: fmt.Sprintf("%d-%s", p.port, p.protocol), Port: p.port, Protocol: kapi.Protocol(p.protocol), - TargetPort: kutil.NewIntOrStringFromInt(p.port), + TargetPort: intstr.FromInt(p.port), }) } diff --git a/pkg/route/api/types.go b/pkg/route/api/types.go index 4a71130e979b..6eed74739a22 100644 --- a/pkg/route/api/types.go +++ b/pkg/route/api/types.go @@ -3,7 +3,7 @@ package api import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/unversioned" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) // Route encapsulates the inputs needed to connect an alias to endpoints. @@ -43,7 +43,7 @@ type RoutePort struct { // The target port on pods selected by the service this route points to. // If this is a string, it will be looked up as a named port in the target // endpoints port list. Required - TargetPort util.IntOrString + TargetPort intstr.IntOrString } // RouteStatus provides relevant info about the status of a route, including which routers diff --git a/pkg/route/api/v1/types.go b/pkg/route/api/v1/types.go index baf46953c6c3..778a05828f28 100644 --- a/pkg/route/api/v1/types.go +++ b/pkg/route/api/v1/types.go @@ -3,7 +3,7 @@ package v1 import ( "k8s.io/kubernetes/pkg/api/unversioned" kapi "k8s.io/kubernetes/pkg/api/v1" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) // Route encapsulates the inputs needed to connect an alias to endpoints. @@ -55,7 +55,7 @@ type RoutePort struct { // The target port on pods selected by the service this route points to. // If this is a string, it will be looked up as a named port in the target // endpoints port list. Required - TargetPort util.IntOrString `json:"targetPort" description:"the target port on the endpoints for the service; if this is a string must match the named port, if an integer, must match the port number"` + TargetPort intstr.IntOrString `json:"targetPort" description:"the target port on the endpoints for the service; if this is a string must match the named port, if an integer, must match the port number"` } // RouteStatus provides relevant info about the status of a route, including which routers diff --git a/pkg/route/api/v1beta3/types.go b/pkg/route/api/v1beta3/types.go index fd53e27c9556..e2ce0a651147 100644 --- a/pkg/route/api/v1beta3/types.go +++ b/pkg/route/api/v1beta3/types.go @@ -3,7 +3,7 @@ package v1beta3 import ( "k8s.io/kubernetes/pkg/api/unversioned" kapi "k8s.io/kubernetes/pkg/api/v1beta3" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) // Route encapsulates the inputs needed to connect an alias to endpoints. @@ -51,7 +51,7 @@ type RoutePort struct { // The target port on pods selected by the service this route points to. // If this is a string, it will be looked up as a named port in the target // endpoints port list. Required - TargetPort util.IntOrString `json:"targetPort"` + TargetPort intstr.IntOrString `json:"targetPort"` } // RouteStatus provides relevant info about the status of a route, including which routers diff --git a/pkg/route/api/validation/validation_test.go b/pkg/route/api/validation/validation_test.go index 97f4906dfb97..bd98e7c0c49a 100644 --- a/pkg/route/api/validation/validation_test.go +++ b/pkg/route/api/validation/validation_test.go @@ -4,7 +4,7 @@ import ( "testing" kapi "k8s.io/kubernetes/pkg/api" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "github.com/openshift/origin/pkg/route/api" ) @@ -104,7 +104,7 @@ func TestValidateRoute(t *testing.T) { Name: "serviceName", }, Port: &api.RoutePort{ - TargetPort: util.NewIntOrStringFromInt(0), + TargetPort: intstr.FromInt(0), }, }, }, @@ -123,7 +123,7 @@ func TestValidateRoute(t *testing.T) { Name: "serviceName", }, Port: &api.RoutePort{ - TargetPort: util.NewIntOrStringFromString(""), + TargetPort: intstr.FromString(""), }, }, }, diff --git a/pkg/route/generator/generate.go b/pkg/route/generator/generate.go index e9c956a6a40d..cd8aaf85da8c 100644 --- a/pkg/route/generator/generate.go +++ b/pkg/route/generator/generate.go @@ -6,7 +6,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/kubectl" "k8s.io/kubernetes/pkg/runtime" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "github.com/openshift/origin/pkg/route/api" ) @@ -76,7 +76,7 @@ func (RouteGenerator) Generate(genericParams map[string]interface{}) (runtime.Ob portString := params["target-port"] if len(portString) > 0 { route.Spec.Port = &api.RoutePort{ - TargetPort: util.NewIntOrStringFromString(portString), + TargetPort: intstr.FromString(portString), } } diff --git a/pkg/route/generator/generate_test.go b/pkg/route/generator/generate_test.go index 35a95dd091a7..01ecd08538dc 100644 --- a/pkg/route/generator/generate_test.go +++ b/pkg/route/generator/generate_test.go @@ -5,7 +5,7 @@ import ( "testing" "k8s.io/kubernetes/pkg/api" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" routeapi "github.com/openshift/origin/pkg/route/api" ) @@ -40,8 +40,8 @@ func TestGenerateRoute(t *testing.T) { Name: "someservice", }, Port: &routeapi.RoutePort{ - TargetPort: util.IntOrString{ - Kind: util.IntstrString, + TargetPort: intstr.IntOrString{ + Type: intstr.String, StrVal: "svcportname", }, }, diff --git a/test/integration/router_test.go b/test/integration/router_test.go index 076463d95681..9db7225c4d9a 100644 --- a/test/integration/router_test.go +++ b/test/integration/router_test.go @@ -23,7 +23,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/v1beta3" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/watch" watchjson "k8s.io/kubernetes/pkg/watch/json" @@ -151,7 +151,7 @@ func TestRouter(t *testing.T) { expectedResponse: tr.HelloPod, routeTLS: nil, routerUrl: routeAddress, - preferredPort: &routeapi.RoutePort{TargetPort: util.NewIntOrStringFromInt(8888)}, + preferredPort: &routeapi.RoutePort{TargetPort: intstr.FromInt(8888)}, }, { name: "edge termination", diff --git a/test/util/verify.go b/test/util/verify.go index 0879bf407cfd..7d1f7a3c853b 100644 --- a/test/util/verify.go +++ b/test/util/verify.go @@ -9,7 +9,7 @@ import ( kapi "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" - kubeutil "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/intstr" ) type ValidateFunc func(string) error @@ -120,7 +120,7 @@ func CreateServiceForPod(pod *kapi.Pod, ns string) *kapi.Service { Selector: map[string]string{"name": ns}, Ports: []kapi.ServicePort{{ Port: 8080, - TargetPort: kubeutil.IntOrString{Kind: kubeutil.IntstrInt, IntVal: 8080}, + TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 8080}, }}, }, }