mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #5729 from thockin/plural_endpoints_30_restart
Rename Service.ContainerPort to TargetPort in v1b3
This commit is contained in:
commit
7a6490f572
@ -6,7 +6,7 @@ metadata:
|
|||||||
kubernetes.io/cluster-service: "true"
|
kubernetes.io/cluster-service: "true"
|
||||||
name: monitoring-grafana
|
name: monitoring-grafana
|
||||||
spec:
|
spec:
|
||||||
containerPort: 80
|
targetPort: 80
|
||||||
port: 80
|
port: 80
|
||||||
selector:
|
selector:
|
||||||
name: influxGrafana
|
name: influxGrafana
|
||||||
|
@ -6,7 +6,7 @@ metadata:
|
|||||||
kubernetes.io/cluster-service: "true"
|
kubernetes.io/cluster-service: "true"
|
||||||
name: monitoring-heapster
|
name: monitoring-heapster
|
||||||
spec:
|
spec:
|
||||||
containerPort: 8082
|
targetPort: 8082
|
||||||
port: 80
|
port: 80
|
||||||
selector:
|
selector:
|
||||||
name: heapster
|
name: heapster
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
name: influxGrafana
|
name: influxGrafana
|
||||||
name: monitoring-influxdb
|
name: monitoring-influxdb
|
||||||
spec:
|
spec:
|
||||||
containerPort: 8086
|
targetPort: 8086
|
||||||
port: 80
|
port: 80
|
||||||
selector:
|
selector:
|
||||||
name: influxGrafana
|
name: influxGrafana
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
name: influxGrafana
|
name: influxGrafana
|
||||||
name: monitoring-influxdb-ui
|
name: monitoring-influxdb-ui
|
||||||
spec:
|
spec:
|
||||||
containerPort: 8083
|
targetPort: 8083
|
||||||
port: 80
|
port: 80
|
||||||
selector:
|
selector:
|
||||||
name: influxGrafana
|
name: influxGrafana
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
name: cassandra
|
name: cassandra
|
||||||
name: cassandra
|
name: cassandra
|
||||||
spec:
|
spec:
|
||||||
containerPort: 9042
|
targetPort: 9042
|
||||||
port: 9042
|
port: 9042
|
||||||
selector:
|
selector:
|
||||||
name: cassandra
|
name: cassandra
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
name: hazelcast
|
name: hazelcast
|
||||||
name: hazelcast
|
name: hazelcast
|
||||||
spec:
|
spec:
|
||||||
containerPort: 5701
|
targetPort: 5701
|
||||||
port: 5701
|
port: 5701
|
||||||
selector:
|
selector:
|
||||||
name: hazelcast
|
name: hazelcast
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
name: mysql
|
name: mysql
|
||||||
name: mysql
|
name: mysql
|
||||||
spec:
|
spec:
|
||||||
containerPort: 3306
|
targetPort: 3306
|
||||||
port: 3306
|
port: 3306
|
||||||
selector:
|
selector:
|
||||||
name: mysql
|
name: mysql
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
name: wpfrontend
|
name: wpfrontend
|
||||||
name: wpfrontend
|
name: wpfrontend
|
||||||
spec:
|
spec:
|
||||||
containerPort: 80
|
targetPort: 80
|
||||||
port: 80
|
port: 80
|
||||||
selector:
|
selector:
|
||||||
name: wpfrontend
|
name: wpfrontend
|
||||||
|
@ -6,7 +6,7 @@ metadata:
|
|||||||
role: service
|
role: service
|
||||||
name: redis-sentinel
|
name: redis-sentinel
|
||||||
spec:
|
spec:
|
||||||
containerPort: 26379
|
targetPort: 26379
|
||||||
port: 26379
|
port: 26379
|
||||||
selector:
|
selector:
|
||||||
redis-sentinel: "true"
|
redis-sentinel: "true"
|
||||||
|
@ -6,7 +6,7 @@ metadata:
|
|||||||
name: rethinkdb-admin
|
name: rethinkdb-admin
|
||||||
namespace: rethinkdb
|
namespace: rethinkdb
|
||||||
spec:
|
spec:
|
||||||
containerPort: 8080
|
targetPort: 8080
|
||||||
port: 8080
|
port: 8080
|
||||||
selector:
|
selector:
|
||||||
db: rethinkdb
|
db: rethinkdb
|
||||||
|
@ -6,7 +6,7 @@ metadata:
|
|||||||
name: rethinkdb-driver
|
name: rethinkdb-driver
|
||||||
namespace: rethinkdb
|
namespace: rethinkdb
|
||||||
spec:
|
spec:
|
||||||
containerPort: 28015
|
targetPort: 28015
|
||||||
port: 28015
|
port: 28015
|
||||||
selector:
|
selector:
|
||||||
db: rethinkdb
|
db: rethinkdb
|
||||||
|
@ -5,7 +5,7 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
# the container on each pod to connect to, can be a name
|
# the container on each pod to connect to, can be a name
|
||||||
# (e.g. 'www') or a number (e.g. 80)
|
# (e.g. 'www') or a number (e.g. 80)
|
||||||
containerPort: 80
|
targetPort: 80
|
||||||
# the port that this service should serve on
|
# the port that this service should serve on
|
||||||
port: 8000
|
port: 8000
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
|
@ -27,9 +27,9 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
"github.com/google/gofuzz"
|
"github.com/google/gofuzz"
|
||||||
|
|
||||||
"speter.net/go/exp/math/dec/inf"
|
"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) {
|
func(ss *api.ServiceSpec, c fuzz.Continue) {
|
||||||
c.FuzzNoCustom(ss) // fuzz self without calling this function again
|
c.FuzzNoCustom(ss) // fuzz self without calling this function again
|
||||||
switch ss.ContainerPort.Kind {
|
switch ss.TargetPort.Kind {
|
||||||
case util.IntstrInt:
|
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:
|
case util.IntstrString:
|
||||||
ss.ContainerPort.StrVal = "x" + ss.ContainerPort.StrVal // non-empty
|
ss.TargetPort.StrVal = "x" + ss.TargetPort.StrVal // non-empty
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -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)
|
// For hostnames, the user will use a CNAME record (instead of using an A record with the IP)
|
||||||
PublicIPs []string `json:"publicIPs,omitempty"`
|
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.
|
// 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.
|
// Optional: If unspecified, the first port on the container will be used.
|
||||||
// As of v1beta3 this field will become required in the internal API,
|
// As of v1beta3 this field will become required in the internal API,
|
||||||
// and the versioned APIs must provide a default value.
|
// 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.
|
// Required: Supports "ClientIP" and "None". Used to maintain session affinity.
|
||||||
SessionAffinity AffinityType `json:"sessionAffinity,omitempty"`
|
SessionAffinity AffinityType `json:"sessionAffinity,omitempty"`
|
||||||
|
@ -636,7 +636,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
out.CreateExternalLoadBalancer = in.Spec.CreateExternalLoadBalancer
|
out.CreateExternalLoadBalancer = in.Spec.CreateExternalLoadBalancer
|
||||||
out.PublicIPs = in.Spec.PublicIPs
|
out.PublicIPs = in.Spec.PublicIPs
|
||||||
out.ContainerPort = in.Spec.ContainerPort
|
out.ContainerPort = in.Spec.TargetPort
|
||||||
out.PortalIP = in.Spec.PortalIP
|
out.PortalIP = in.Spec.PortalIP
|
||||||
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
|
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -662,7 +662,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
out.Spec.CreateExternalLoadBalancer = in.CreateExternalLoadBalancer
|
out.Spec.CreateExternalLoadBalancer = in.CreateExternalLoadBalancer
|
||||||
out.Spec.PublicIPs = in.PublicIPs
|
out.Spec.PublicIPs = in.PublicIPs
|
||||||
out.Spec.ContainerPort = in.ContainerPort
|
out.Spec.TargetPort = in.ContainerPort
|
||||||
out.Spec.PortalIP = in.PortalIP
|
out.Spec.PortalIP = in.PortalIP
|
||||||
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
|
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -568,7 +568,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
out.CreateExternalLoadBalancer = in.Spec.CreateExternalLoadBalancer
|
out.CreateExternalLoadBalancer = in.Spec.CreateExternalLoadBalancer
|
||||||
out.PublicIPs = in.Spec.PublicIPs
|
out.PublicIPs = in.Spec.PublicIPs
|
||||||
out.ContainerPort = in.Spec.ContainerPort
|
out.ContainerPort = in.Spec.TargetPort
|
||||||
out.PortalIP = in.Spec.PortalIP
|
out.PortalIP = in.Spec.PortalIP
|
||||||
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
|
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -594,7 +594,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
out.Spec.CreateExternalLoadBalancer = in.CreateExternalLoadBalancer
|
out.Spec.CreateExternalLoadBalancer = in.CreateExternalLoadBalancer
|
||||||
out.Spec.PublicIPs = in.PublicIPs
|
out.Spec.PublicIPs = in.PublicIPs
|
||||||
out.Spec.ContainerPort = in.ContainerPort
|
out.Spec.TargetPort = in.ContainerPort
|
||||||
out.Spec.PortalIP = in.PortalIP
|
out.Spec.PortalIP = in.PortalIP
|
||||||
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
|
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -89,9 +89,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(obj *ServiceSpec) {
|
func(obj *ServiceSpec) {
|
||||||
if obj.ContainerPort.Kind == util.IntstrInt && obj.ContainerPort.IntVal == 0 ||
|
if obj.TargetPort.Kind == util.IntstrInt && obj.TargetPort.IntVal == 0 ||
|
||||||
obj.ContainerPort.Kind == util.IntstrString && obj.ContainerPort.StrVal == "" {
|
obj.TargetPort.Kind == util.IntstrString && obj.TargetPort.StrVal == "" {
|
||||||
obj.ContainerPort = util.NewIntOrStringFromInt(obj.Port)
|
obj.TargetPort = util.NewIntOrStringFromInt(obj.Port)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(obj *NamespaceStatus) {
|
func(obj *NamespaceStatus) {
|
||||||
|
@ -72,19 +72,19 @@ func TestSetDefaulEndpointsProtocol(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaulServiceDestinationPort(t *testing.T) {
|
func TestSetDefaulServiceTargetPort(t *testing.T) {
|
||||||
in := ¤t.Service{Spec: current.ServiceSpec{Port: 1234}}
|
in := ¤t.Service{Spec: current.ServiceSpec{Port: 1234}}
|
||||||
obj := roundTrip(t, runtime.Object(in))
|
obj := roundTrip(t, runtime.Object(in))
|
||||||
out := obj.(*current.Service)
|
out := obj.(*current.Service)
|
||||||
if out.Spec.ContainerPort.Kind != util.IntstrInt || out.Spec.ContainerPort.IntVal != 1234 {
|
if out.Spec.TargetPort.Kind != util.IntstrInt || out.Spec.TargetPort.IntVal != 1234 {
|
||||||
t.Errorf("Expected ContainerPort to be defaulted, got %s", out.Spec.ContainerPort)
|
t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.TargetPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
in = ¤t.Service{Spec: current.ServiceSpec{Port: 1234, ContainerPort: util.NewIntOrStringFromInt(5678)}}
|
in = ¤t.Service{Spec: current.ServiceSpec{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}
|
||||||
obj = roundTrip(t, runtime.Object(in))
|
obj = roundTrip(t, runtime.Object(in))
|
||||||
out = obj.(*current.Service)
|
out = obj.(*current.Service)
|
||||||
if out.Spec.ContainerPort.Kind != util.IntstrInt || out.Spec.ContainerPort.IntVal != 5678 {
|
if out.Spec.TargetPort.Kind != util.IntstrInt || out.Spec.TargetPort.IntVal != 5678 {
|
||||||
t.Errorf("Expected ContainerPort to be unchanged, got %s", out.Spec.ContainerPort)
|
t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.TargetPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,10 +754,10 @@ type ServiceSpec struct {
|
|||||||
// users to handle external traffic that arrives at a node.
|
// 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"`
|
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.
|
// 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).
|
// 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.
|
// 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"`
|
SessionAffinity AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||||
|
@ -736,9 +736,9 @@ func ValidateService(service *api.Service) errs.ValidationErrorList {
|
|||||||
} else if !supportedPortProtocols.Has(strings.ToUpper(string(service.Spec.Protocol))) {
|
} else if !supportedPortProtocols.Has(strings.ToUpper(string(service.Spec.Protocol))) {
|
||||||
allErrs = append(allErrs, errs.NewFieldNotSupported("spec.protocol", 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))
|
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"))
|
allErrs = append(allErrs, errs.NewFieldRequired("spec.containerPort"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1156,16 +1156,16 @@ func TestValidateService(t *testing.T) {
|
|||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing destinationPort string",
|
name: "missing targetPort string",
|
||||||
makeSvc: func(s *api.Service) {
|
makeSvc: func(s *api.Service) {
|
||||||
s.Spec.ContainerPort = util.NewIntOrStringFromString("")
|
s.Spec.TargetPort = util.NewIntOrStringFromString("")
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid destinationPort int",
|
name: "invalid targetPort int",
|
||||||
makeSvc: func(s *api.Service) {
|
makeSvc: func(s *api.Service) {
|
||||||
s.Spec.ContainerPort = util.NewIntOrStringFromInt(65536)
|
s.Spec.TargetPort = util.NewIntOrStringFromInt(65536)
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -1187,14 +1187,14 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "valid 2",
|
name: "valid 2",
|
||||||
makeSvc: func(s *api.Service) {
|
makeSvc: func(s *api.Service) {
|
||||||
s.Spec.Protocol = "UDP"
|
s.Spec.Protocol = "UDP"
|
||||||
s.Spec.ContainerPort = util.NewIntOrStringFromInt(12345)
|
s.Spec.TargetPort = util.NewIntOrStringFromInt(12345)
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid 3",
|
name: "valid 3",
|
||||||
makeSvc: func(s *api.Service) {
|
makeSvc: func(s *api.Service) {
|
||||||
s.Spec.ContainerPort = util.NewIntOrStringFromString("http")
|
s.Spec.TargetPort = util.NewIntOrStringFromString("http")
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
|
@ -35,7 +35,8 @@ func (ServiceGenerator) ParamNames() []GeneratorParam {
|
|||||||
{"public-ip", false},
|
{"public-ip", false},
|
||||||
{"create-external-load-balancer", false},
|
{"create-external-load-balancer", false},
|
||||||
{"protocol", 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,
|
Selector: selector,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
containerPort, found := params["container-port"]
|
targetPort, found := params["target-port"]
|
||||||
if found && len(containerPort) > 0 {
|
if !found {
|
||||||
if cPort, err := strconv.Atoi(containerPort); err != nil {
|
targetPort, found = params["container-port"]
|
||||||
service.Spec.ContainerPort = util.NewIntOrStringFromString(containerPort)
|
}
|
||||||
|
if found && len(targetPort) > 0 {
|
||||||
|
if portNum, err := strconv.Atoi(targetPort); err != nil {
|
||||||
|
service.Spec.TargetPort = util.NewIntOrStringFromString(targetPort)
|
||||||
} else {
|
} else {
|
||||||
service.Spec.ContainerPort = util.NewIntOrStringFromInt(cPort)
|
service.Spec.TargetPort = util.NewIntOrStringFromInt(portNum)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
service.Spec.ContainerPort = util.NewIntOrStringFromInt(port)
|
service.Spec.TargetPort = util.NewIntOrStringFromInt(port)
|
||||||
}
|
}
|
||||||
if params["create-external-load-balancer"] == "true" {
|
if params["create-external-load-balancer"] == "true" {
|
||||||
service.Spec.CreateExternalLoadBalancer = true
|
service.Spec.CreateExternalLoadBalancer = true
|
||||||
|
@ -46,9 +46,9 @@ func TestGenerateService(t *testing.T) {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
},
|
},
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Protocol: "TCP",
|
Protocol: "TCP",
|
||||||
ContainerPort: util.NewIntOrStringFromInt(1234),
|
TargetPort: util.NewIntOrStringFromInt(1234),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -69,9 +69,9 @@ func TestGenerateService(t *testing.T) {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
},
|
},
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Protocol: "UDP",
|
Protocol: "UDP",
|
||||||
ContainerPort: util.NewIntOrStringFromString("foobar"),
|
TargetPort: util.NewIntOrStringFromString("foobar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -97,9 +97,9 @@ func TestGenerateService(t *testing.T) {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
},
|
},
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Protocol: "TCP",
|
Protocol: "TCP",
|
||||||
ContainerPort: util.NewIntOrStringFromInt(1234),
|
TargetPort: util.NewIntOrStringFromInt(1234),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -121,10 +121,10 @@ func TestGenerateService(t *testing.T) {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
},
|
},
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Protocol: "UDP",
|
Protocol: "UDP",
|
||||||
PublicIPs: []string{"1.2.3.4"},
|
PublicIPs: []string{"1.2.3.4"},
|
||||||
ContainerPort: util.NewIntOrStringFromString("foobar"),
|
TargetPort: util.NewIntOrStringFromString("foobar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -150,7 +150,7 @@ func TestGenerateService(t *testing.T) {
|
|||||||
Port: 80,
|
Port: 80,
|
||||||
Protocol: "UDP",
|
Protocol: "UDP",
|
||||||
PublicIPs: []string{"1.2.3.4"},
|
PublicIPs: []string{"1.2.3.4"},
|
||||||
ContainerPort: util.NewIntOrStringFromString("foobar"),
|
TargetPort: util.NewIntOrStringFromString("foobar"),
|
||||||
CreateExternalLoadBalancer: true,
|
CreateExternalLoadBalancer: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -68,7 +68,7 @@ func (e *EndpointController) SyncServiceEndpoints() error {
|
|||||||
|
|
||||||
for _, pod := range pods.Items {
|
for _, pod := range pods.Items {
|
||||||
// TODO: Once v1beta1 and v1beta2 are EOL'ed, this can
|
// 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
|
_ = v1beta1.Dependency
|
||||||
_ = v1beta2.Dependency
|
_ = v1beta2.Dependency
|
||||||
port, err := findPort(&pod, &service)
|
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.
|
// findPort locates the container port for the given manifest and portName.
|
||||||
func findPort(pod *api.Pod, service *api.Service) (int, error) {
|
func findPort(pod *api.Pod, service *api.Service) (int, error) {
|
||||||
portName := service.Spec.ContainerPort
|
portName := service.Spec.TargetPort
|
||||||
switch portName.Kind {
|
switch portName.Kind {
|
||||||
case util.IntstrString:
|
case util.IntstrString:
|
||||||
if len(portName.StrVal) == 0 {
|
if len(portName.StrVal) == 0 {
|
||||||
|
@ -213,7 +213,7 @@ func TestFindPort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
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 {
|
if port != test.wport {
|
||||||
t.Errorf("Expected port %d, Got %d", test.wport, port)
|
t.Errorf("Expected port %d, Got %d", test.wport, port)
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,8 @@ var _ = Describe("Networking", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(8080),
|
TargetPort: util.NewIntOrStringFromInt(8080),
|
||||||
Selector: map[string]string{
|
Selector: map[string]string{
|
||||||
"name": name,
|
"name": name,
|
||||||
},
|
},
|
||||||
|
@ -307,8 +307,8 @@ var _ = Describe("Pods", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Port: 8765,
|
Port: 8765,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(8080),
|
TargetPort: util.NewIntOrStringFromInt(8080),
|
||||||
Selector: map[string]string{
|
Selector: map[string]string{
|
||||||
"name": serverName,
|
"name": serverName,
|
||||||
},
|
},
|
||||||
|
@ -197,9 +197,9 @@ var _ = Describe("Services", func() {
|
|||||||
Name: serviceName,
|
Name: serviceName,
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Selector: labels,
|
Selector: labels,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(80),
|
TargetPort: util.NewIntOrStringFromInt(80),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := c.Services(ns).Create(service)
|
_, err := c.Services(ns).Create(service)
|
||||||
@ -257,7 +257,7 @@ var _ = Describe("Services", func() {
|
|||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Selector: labels,
|
Selector: labels,
|
||||||
ContainerPort: util.NewIntOrStringFromInt(80),
|
TargetPort: util.NewIntOrStringFromInt(80),
|
||||||
CreateExternalLoadBalancer: true,
|
CreateExternalLoadBalancer: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user