mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Rename Service.ContainerPort to TargetPort in v1b3
Fix all callers and examples. Part of multi-port service cleanup.
This commit is contained in:
@@ -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
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -759,12 +759,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"`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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}}
|
||||
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 = ¤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))
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -751,10 +751,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"`
|
||||
|
||||
@@ -735,9 +735,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"))
|
||||
}
|
||||
|
||||
|
||||
@@ -1149,16 +1149,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,
|
||||
},
|
||||
@@ -1180,14 +1180,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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user