Skip to content

Commit

Permalink
IntOrString pkg/util -> pkg/util/intstr
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysh committed Dec 21, 2015
1 parent 8d4bdb8 commit cc3c089
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 143 deletions.
8 changes: 4 additions & 4 deletions pkg/api/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/v1/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/v1beta3/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/admin/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/admin/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/server/kubernetes/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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},
Expand Down
6 changes: 3 additions & 3 deletions pkg/deploy/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions pkg/deploy/api/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 22 additions & 21 deletions pkg/deploy/api/v1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
Expand All @@ -78,24 +79,24 @@ 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),
},
},
{
in: &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)),
},
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),
},
},
}
Expand All @@ -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%")),
},
},
{
Expand All @@ -140,32 +141,32 @@ 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)),
},
},
{
in: &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),
},
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)),
},
},
}
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/deploy/api/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
}
Expand Down
Loading

0 comments on commit cc3c089

Please sign in to comment.