Skip to content

Commit

Permalink
Merge pull request kubernetes#5729 from thockin/plural_endpoints_30_r…
Browse files Browse the repository at this point in the history
…estart

Rename Service.ContainerPort to TargetPort in v1b3
  • Loading branch information
dchen1107 committed Mar 20, 2015
2 parents 0206115 + 4375376 commit 7a6490f
Show file tree
Hide file tree
Showing 28 changed files with 77 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
kubernetes.io/cluster-service: "true"
name: monitoring-grafana
spec:
containerPort: 80
targetPort: 80
port: 80
selector:
name: influxGrafana
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
kubernetes.io/cluster-service: "true"
name: monitoring-heapster
spec:
containerPort: 8082
targetPort: 8082
port: 80
selector:
name: heapster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: influxGrafana
name: monitoring-influxdb
spec:
containerPort: 8086
targetPort: 8086
port: 80
selector:
name: influxGrafana
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: influxGrafana
name: monitoring-influxdb-ui
spec:
containerPort: 8083
targetPort: 8083
port: 80
selector:
name: influxGrafana
Expand Down
2 changes: 1 addition & 1 deletion examples/cassandra/v1beta3/cassandra-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: cassandra
name: cassandra
spec:
containerPort: 9042
targetPort: 9042
port: 9042
selector:
name: cassandra
2 changes: 1 addition & 1 deletion examples/hazelcast/v1beta3/hazelcast-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: hazelcast
name: hazelcast
spec:
containerPort: 5701
targetPort: 5701
port: 5701
selector:
name: hazelcast
2 changes: 1 addition & 1 deletion examples/mysql-wordpress-pd/v1beta3/mysql-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: mysql
name: mysql
spec:
containerPort: 3306
targetPort: 3306
port: 3306
selector:
name: mysql
Expand Down
2 changes: 1 addition & 1 deletion examples/mysql-wordpress-pd/v1beta3/wordpress-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: wpfrontend
name: wpfrontend
spec:
containerPort: 80
targetPort: 80
port: 80
selector:
name: wpfrontend
Expand Down
2 changes: 1 addition & 1 deletion examples/redis/v1beta3/redis-sentinel-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
role: service
name: redis-sentinel
spec:
containerPort: 26379
targetPort: 26379
port: 26379
selector:
redis-sentinel: "true"
2 changes: 1 addition & 1 deletion examples/rethinkdb/v1beta3/admin-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: rethinkdb-admin
namespace: rethinkdb
spec:
containerPort: 8080
targetPort: 8080
port: 8080
selector:
db: rethinkdb
Expand Down
2 changes: 1 addition & 1 deletion examples/rethinkdb/v1beta3/driver-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: rethinkdb-driver
namespace: rethinkdb
spec:
containerPort: 28015
targetPort: 28015
port: 28015
selector:
db: rethinkdb
2 changes: 1 addition & 1 deletion examples/walkthrough/v1beta3/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
},
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1beta3/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/v1beta3/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand Down
18 changes: 11 additions & 7 deletions pkg/kubectl/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
}

Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions pkg/kubectl/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand All @@ -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"),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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"),
},
},
},
Expand All @@ -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,
},
},
Expand Down
Loading

0 comments on commit 7a6490f

Please sign in to comment.