Merge pull request #5729 from thockin/plural_endpoints_30_restart

Rename Service.ContainerPort to TargetPort in v1b3
This commit is contained in:
Dawn Chen 2015-03-20 14:37:46 -07:00
commit 7a6490f572
28 changed files with 77 additions and 73 deletions

View File

@ -6,7 +6,7 @@ metadata:
kubernetes.io/cluster-service: "true"
name: monitoring-grafana
spec:
containerPort: 80
targetPort: 80
port: 80
selector:
name: influxGrafana

View File

@ -6,7 +6,7 @@ metadata:
kubernetes.io/cluster-service: "true"
name: monitoring-heapster
spec:
containerPort: 8082
targetPort: 8082
port: 80
selector:
name: heapster

View File

@ -5,7 +5,7 @@ metadata:
name: influxGrafana
name: monitoring-influxdb
spec:
containerPort: 8086
targetPort: 8086
port: 80
selector:
name: influxGrafana

View File

@ -5,7 +5,7 @@ metadata:
name: influxGrafana
name: monitoring-influxdb-ui
spec:
containerPort: 8083
targetPort: 8083
port: 80
selector:
name: influxGrafana

View File

@ -5,7 +5,7 @@ metadata:
name: cassandra
name: cassandra
spec:
containerPort: 9042
targetPort: 9042
port: 9042
selector:
name: cassandra

View File

@ -5,7 +5,7 @@ metadata:
name: hazelcast
name: hazelcast
spec:
containerPort: 5701
targetPort: 5701
port: 5701
selector:
name: hazelcast

View File

@ -5,7 +5,7 @@ metadata:
name: mysql
name: mysql
spec:
containerPort: 3306
targetPort: 3306
port: 3306
selector:
name: mysql

View File

@ -5,7 +5,7 @@ metadata:
name: wpfrontend
name: wpfrontend
spec:
containerPort: 80
targetPort: 80
port: 80
selector:
name: wpfrontend

View File

@ -6,7 +6,7 @@ metadata:
role: service
name: redis-sentinel
spec:
containerPort: 26379
targetPort: 26379
port: 26379
selector:
redis-sentinel: "true"

View File

@ -6,7 +6,7 @@ metadata:
name: rethinkdb-admin
namespace: rethinkdb
spec:
containerPort: 8080
targetPort: 8080
port: 8080
selector:
db: rethinkdb

View File

@ -6,7 +6,7 @@ metadata:
name: rethinkdb-driver
namespace: rethinkdb
spec:
containerPort: 28015
targetPort: 28015
port: 28015
selector:
db: rethinkdb

View File

@ -5,7 +5,7 @@ metadata:
spec:
# the container on each pod to connect to, can be a name
# (e.g. 'www') or a number (e.g. 80)
containerPort: 80
targetPort: 80
# the port that this service should serve on
port: 8000
protocol: TCP

View File

@ -27,9 +27,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/fsouza/go-dockerclient"
"github.com/google/gofuzz"
"speter.net/go/exp/math/dec/inf"
)
@ -212,11 +212,11 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
},
func(ss *api.ServiceSpec, c fuzz.Continue) {
c.FuzzNoCustom(ss) // fuzz self without calling this function again
switch ss.ContainerPort.Kind {
switch ss.TargetPort.Kind {
case util.IntstrInt:
ss.ContainerPort.IntVal = 1 + ss.ContainerPort.IntVal%65535 // non-zero
ss.TargetPort.IntVal = 1 + ss.TargetPort.IntVal%65535 // non-zero
case util.IntstrString:
ss.ContainerPort.StrVal = "x" + ss.ContainerPort.StrVal // non-empty
ss.TargetPort.StrVal = "x" + ss.TargetPort.StrVal // non-empty
}
},
)

View File

@ -768,12 +768,12 @@ type ServiceSpec struct {
// For hostnames, the user will use a CNAME record (instead of using an A record with the IP)
PublicIPs []string `json:"publicIPs,omitempty"`
// ContainerPort is the name or number of the port on the container to direct traffic to.
// TargetPort is the name or number of the port on the container to direct traffic to.
// This is useful if the containers the service points to have multiple open ports.
// Optional: If unspecified, the first port on the container will be used.
// As of v1beta3 this field will become required in the internal API,
// and the versioned APIs must provide a default value.
ContainerPort util.IntOrString `json:"containerPort,omitempty"`
TargetPort util.IntOrString `json:"targetPort,omitempty"`
// Required: Supports "ClientIP" and "None". Used to maintain session affinity.
SessionAffinity AffinityType `json:"sessionAffinity,omitempty"`

View File

@ -636,7 +636,7 @@ func init() {
}
out.CreateExternalLoadBalancer = in.Spec.CreateExternalLoadBalancer
out.PublicIPs = in.Spec.PublicIPs
out.ContainerPort = in.Spec.ContainerPort
out.ContainerPort = in.Spec.TargetPort
out.PortalIP = in.Spec.PortalIP
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
return err
@ -662,7 +662,7 @@ func init() {
}
out.Spec.CreateExternalLoadBalancer = in.CreateExternalLoadBalancer
out.Spec.PublicIPs = in.PublicIPs
out.Spec.ContainerPort = in.ContainerPort
out.Spec.TargetPort = in.ContainerPort
out.Spec.PortalIP = in.PortalIP
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
return err

View File

@ -568,7 +568,7 @@ func init() {
}
out.CreateExternalLoadBalancer = in.Spec.CreateExternalLoadBalancer
out.PublicIPs = in.Spec.PublicIPs
out.ContainerPort = in.Spec.ContainerPort
out.ContainerPort = in.Spec.TargetPort
out.PortalIP = in.Spec.PortalIP
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
return err
@ -594,7 +594,7 @@ func init() {
}
out.Spec.CreateExternalLoadBalancer = in.CreateExternalLoadBalancer
out.Spec.PublicIPs = in.PublicIPs
out.Spec.ContainerPort = in.ContainerPort
out.Spec.TargetPort = in.ContainerPort
out.Spec.PortalIP = in.PortalIP
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
return err

View File

@ -89,9 +89,9 @@ func init() {
}
},
func(obj *ServiceSpec) {
if obj.ContainerPort.Kind == util.IntstrInt && obj.ContainerPort.IntVal == 0 ||
obj.ContainerPort.Kind == util.IntstrString && obj.ContainerPort.StrVal == "" {
obj.ContainerPort = util.NewIntOrStringFromInt(obj.Port)
if obj.TargetPort.Kind == util.IntstrInt && obj.TargetPort.IntVal == 0 ||
obj.TargetPort.Kind == util.IntstrString && obj.TargetPort.StrVal == "" {
obj.TargetPort = util.NewIntOrStringFromInt(obj.Port)
}
},
func(obj *NamespaceStatus) {

View File

@ -72,19 +72,19 @@ func TestSetDefaulEndpointsProtocol(t *testing.T) {
}
}
func TestSetDefaulServiceDestinationPort(t *testing.T) {
func TestSetDefaulServiceTargetPort(t *testing.T) {
in := &current.Service{Spec: current.ServiceSpec{Port: 1234}}
obj := roundTrip(t, runtime.Object(in))
out := obj.(*current.Service)
if out.Spec.ContainerPort.Kind != util.IntstrInt || out.Spec.ContainerPort.IntVal != 1234 {
t.Errorf("Expected ContainerPort to be defaulted, got %s", out.Spec.ContainerPort)
if out.Spec.TargetPort.Kind != util.IntstrInt || out.Spec.TargetPort.IntVal != 1234 {
t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.TargetPort)
}
in = &current.Service{Spec: current.ServiceSpec{Port: 1234, ContainerPort: util.NewIntOrStringFromInt(5678)}}
in = &current.Service{Spec: current.ServiceSpec{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}
obj = roundTrip(t, runtime.Object(in))
out = obj.(*current.Service)
if out.Spec.ContainerPort.Kind != util.IntstrInt || out.Spec.ContainerPort.IntVal != 5678 {
t.Errorf("Expected ContainerPort to be unchanged, got %s", out.Spec.ContainerPort)
if out.Spec.TargetPort.Kind != util.IntstrInt || out.Spec.TargetPort.IntVal != 5678 {
t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.TargetPort)
}
}

View File

@ -754,10 +754,10 @@ type ServiceSpec struct {
// users to handle external traffic that arrives at a node.
PublicIPs []string `json:"publicIPs,omitempty" description:"externally visible IPs (e.g. load balancers) that should be proxied to this service"`
// ContainerPort is the name or number of the port on the container to direct traffic to.
// TargetPort is the name or number of the port on the container to direct traffic to.
// This is useful if the containers the service points to have multiple open ports.
// Optional: If unspecified, the service port is used (an identity map).
ContainerPort util.IntOrString `json:"containerPort,omitempty" description:"number or name of the port to access on the containers belonging to pods targeted by the service; defaults to the container's first open port"`
TargetPort util.IntOrString `json:"targetPort,omitempty" description:"number or name of the port to access on the containers belonging to pods targeted by the service; defaults to the container's first open port"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity.
SessionAffinity AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`

View File

@ -736,9 +736,9 @@ func ValidateService(service *api.Service) errs.ValidationErrorList {
} else if !supportedPortProtocols.Has(strings.ToUpper(string(service.Spec.Protocol))) {
allErrs = append(allErrs, errs.NewFieldNotSupported("spec.protocol", service.Spec.Protocol))
}
if service.Spec.ContainerPort.Kind == util.IntstrInt && service.Spec.ContainerPort.IntVal != 0 && !util.IsValidPortNum(service.Spec.ContainerPort.IntVal) {
if service.Spec.TargetPort.Kind == util.IntstrInt && service.Spec.TargetPort.IntVal != 0 && !util.IsValidPortNum(service.Spec.TargetPort.IntVal) {
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containerPort", service.Spec.Port, portRangeErrorMsg))
} else if service.Spec.ContainerPort.Kind == util.IntstrString && len(service.Spec.ContainerPort.StrVal) == 0 {
} else if service.Spec.TargetPort.Kind == util.IntstrString && len(service.Spec.TargetPort.StrVal) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("spec.containerPort"))
}

View File

@ -1156,16 +1156,16 @@ func TestValidateService(t *testing.T) {
numErrs: 1,
},
{
name: "missing destinationPort string",
name: "missing targetPort string",
makeSvc: func(s *api.Service) {
s.Spec.ContainerPort = util.NewIntOrStringFromString("")
s.Spec.TargetPort = util.NewIntOrStringFromString("")
},
numErrs: 1,
},
{
name: "invalid destinationPort int",
name: "invalid targetPort int",
makeSvc: func(s *api.Service) {
s.Spec.ContainerPort = util.NewIntOrStringFromInt(65536)
s.Spec.TargetPort = util.NewIntOrStringFromInt(65536)
},
numErrs: 1,
},
@ -1187,14 +1187,14 @@ func TestValidateService(t *testing.T) {
name: "valid 2",
makeSvc: func(s *api.Service) {
s.Spec.Protocol = "UDP"
s.Spec.ContainerPort = util.NewIntOrStringFromInt(12345)
s.Spec.TargetPort = util.NewIntOrStringFromInt(12345)
},
numErrs: 0,
},
{
name: "valid 3",
makeSvc: func(s *api.Service) {
s.Spec.ContainerPort = util.NewIntOrStringFromString("http")
s.Spec.TargetPort = util.NewIntOrStringFromString("http")
},
numErrs: 0,
},

View File

@ -35,7 +35,8 @@ func (ServiceGenerator) ParamNames() []GeneratorParam {
{"public-ip", false},
{"create-external-load-balancer", false},
{"protocol", false},
{"container-port", false},
{"container-port", false}, // alias of target-port
{"target-port", false},
}
}
@ -75,15 +76,18 @@ func (ServiceGenerator) Generate(params map[string]string) (runtime.Object, erro
Selector: selector,
},
}
containerPort, found := params["container-port"]
if found && len(containerPort) > 0 {
if cPort, err := strconv.Atoi(containerPort); err != nil {
service.Spec.ContainerPort = util.NewIntOrStringFromString(containerPort)
targetPort, found := params["target-port"]
if !found {
targetPort, found = params["container-port"]
}
if found && len(targetPort) > 0 {
if portNum, err := strconv.Atoi(targetPort); err != nil {
service.Spec.TargetPort = util.NewIntOrStringFromString(targetPort)
} else {
service.Spec.ContainerPort = util.NewIntOrStringFromInt(cPort)
service.Spec.TargetPort = util.NewIntOrStringFromInt(portNum)
}
} else {
service.Spec.ContainerPort = util.NewIntOrStringFromInt(port)
service.Spec.TargetPort = util.NewIntOrStringFromInt(port)
}
if params["create-external-load-balancer"] == "true" {
service.Spec.CreateExternalLoadBalancer = true

View File

@ -46,9 +46,9 @@ func TestGenerateService(t *testing.T) {
"foo": "bar",
"baz": "blah",
},
Port: 80,
Protocol: "TCP",
ContainerPort: util.NewIntOrStringFromInt(1234),
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
},
},
},
@ -69,9 +69,9 @@ func TestGenerateService(t *testing.T) {
"foo": "bar",
"baz": "blah",
},
Port: 80,
Protocol: "UDP",
ContainerPort: util.NewIntOrStringFromString("foobar"),
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
},
},
},
@ -97,9 +97,9 @@ func TestGenerateService(t *testing.T) {
"foo": "bar",
"baz": "blah",
},
Port: 80,
Protocol: "TCP",
ContainerPort: util.NewIntOrStringFromInt(1234),
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
},
},
},
@ -121,10 +121,10 @@ func TestGenerateService(t *testing.T) {
"foo": "bar",
"baz": "blah",
},
Port: 80,
Protocol: "UDP",
PublicIPs: []string{"1.2.3.4"},
ContainerPort: util.NewIntOrStringFromString("foobar"),
Port: 80,
Protocol: "UDP",
PublicIPs: []string{"1.2.3.4"},
TargetPort: util.NewIntOrStringFromString("foobar"),
},
},
},
@ -150,7 +150,7 @@ func TestGenerateService(t *testing.T) {
Port: 80,
Protocol: "UDP",
PublicIPs: []string{"1.2.3.4"},
ContainerPort: util.NewIntOrStringFromString("foobar"),
TargetPort: util.NewIntOrStringFromString("foobar"),
CreateExternalLoadBalancer: true,
},
},

View File

@ -68,7 +68,7 @@ func (e *EndpointController) SyncServiceEndpoints() error {
for _, pod := range pods.Items {
// TODO: Once v1beta1 and v1beta2 are EOL'ed, this can
// assume that service.Spec.ContainerPort is populated.
// assume that service.Spec.TargetPort is populated.
_ = v1beta1.Dependency
_ = v1beta2.Dependency
port, err := findPort(&pod, &service)
@ -196,7 +196,7 @@ func findDefaultPort(pod *api.Pod, servicePort int) (int, bool) {
// findPort locates the container port for the given manifest and portName.
func findPort(pod *api.Pod, service *api.Service) (int, error) {
portName := service.Spec.ContainerPort
portName := service.Spec.TargetPort
switch portName.Kind {
case util.IntstrString:
if len(portName.StrVal) == 0 {

View File

@ -213,7 +213,7 @@ func TestFindPort(t *testing.T) {
},
}
for _, test := range tests {
port, err := findPort(&test.pod, &api.Service{Spec: api.ServiceSpec{Port: servicePort, ContainerPort: test.portName}})
port, err := findPort(&test.pod, &api.Service{Spec: api.ServiceSpec{Port: servicePort, TargetPort: test.portName}})
if port != test.wport {
t.Errorf("Expected port %d, Got %d", test.wport, port)
}

View File

@ -77,8 +77,8 @@ var _ = Describe("Networking", func() {
},
},
Spec: api.ServiceSpec{
Port: 8080,
ContainerPort: util.NewIntOrStringFromInt(8080),
Port: 8080,
TargetPort: util.NewIntOrStringFromInt(8080),
Selector: map[string]string{
"name": name,
},

View File

@ -307,8 +307,8 @@ var _ = Describe("Pods", func() {
},
},
Spec: api.ServiceSpec{
Port: 8765,
ContainerPort: util.NewIntOrStringFromInt(8080),
Port: 8765,
TargetPort: util.NewIntOrStringFromInt(8080),
Selector: map[string]string{
"name": serverName,
},

View File

@ -197,9 +197,9 @@ var _ = Describe("Services", func() {
Name: serviceName,
},
Spec: api.ServiceSpec{
Port: 80,
Selector: labels,
ContainerPort: util.NewIntOrStringFromInt(80),
Port: 80,
Selector: labels,
TargetPort: util.NewIntOrStringFromInt(80),
},
}
_, err := c.Services(ns).Create(service)
@ -257,7 +257,7 @@ var _ = Describe("Services", func() {
Spec: api.ServiceSpec{
Port: 80,
Selector: labels,
ContainerPort: util.NewIntOrStringFromInt(80),
TargetPort: util.NewIntOrStringFromInt(80),
CreateExternalLoadBalancer: true,
},
}