External IPs support.
This commit is contained in:
@@ -1949,13 +1949,13 @@ func deepCopy_api_ServiceSpec(in ServiceSpec, out *ServiceSpec, c *conversion.Cl
|
||||
}
|
||||
out.ClusterIP = in.ClusterIP
|
||||
out.Type = in.Type
|
||||
if in.DeprecatedPublicIPs != nil {
|
||||
out.DeprecatedPublicIPs = make([]string, len(in.DeprecatedPublicIPs))
|
||||
for i := range in.DeprecatedPublicIPs {
|
||||
out.DeprecatedPublicIPs[i] = in.DeprecatedPublicIPs[i]
|
||||
if in.ExternalIPs != nil {
|
||||
out.ExternalIPs = make([]string, len(in.ExternalIPs))
|
||||
for i := range in.ExternalIPs {
|
||||
out.ExternalIPs[i] = in.ExternalIPs[i]
|
||||
}
|
||||
} else {
|
||||
out.DeprecatedPublicIPs = nil
|
||||
out.ExternalIPs = nil
|
||||
}
|
||||
out.SessionAffinity = in.SessionAffinity
|
||||
return nil
|
||||
|
@@ -1190,10 +1190,9 @@ type ServiceSpec struct {
|
||||
// Type determines how the service will be exposed. Valid options: ClusterIP, NodePort, LoadBalancer
|
||||
Type ServiceType `json:"type,omitempty"`
|
||||
|
||||
// DeprecatedPublicIPs are deprecated and silently ignored.
|
||||
// Old behaviour: PublicIPs are used by external load balancers, or can be set by
|
||||
// ExternalIPs are used by external load balancers, or can be set by
|
||||
// users to handle external traffic that arrives at a node.
|
||||
DeprecatedPublicIPs []string `json:"deprecatedPublicIPs,omitempty"`
|
||||
ExternalIPs []string `json:"externalIPs,omitempty"`
|
||||
|
||||
// Required: Supports "ClientIP" and "None". Used to maintain session affinity.
|
||||
SessionAffinity ServiceAffinity `json:"sessionAffinity,omitempty"`
|
||||
|
@@ -2166,13 +2166,13 @@ func convert_api_ServiceSpec_To_v1_ServiceSpec(in *api.ServiceSpec, out *Service
|
||||
}
|
||||
out.ClusterIP = in.ClusterIP
|
||||
out.Type = ServiceType(in.Type)
|
||||
if in.DeprecatedPublicIPs != nil {
|
||||
out.DeprecatedPublicIPs = make([]string, len(in.DeprecatedPublicIPs))
|
||||
for i := range in.DeprecatedPublicIPs {
|
||||
out.DeprecatedPublicIPs[i] = in.DeprecatedPublicIPs[i]
|
||||
if in.ExternalIPs != nil {
|
||||
out.ExternalIPs = make([]string, len(in.ExternalIPs))
|
||||
for i := range in.ExternalIPs {
|
||||
out.ExternalIPs[i] = in.ExternalIPs[i]
|
||||
}
|
||||
} else {
|
||||
out.DeprecatedPublicIPs = nil
|
||||
out.ExternalIPs = nil
|
||||
}
|
||||
out.SessionAffinity = ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
@@ -4581,13 +4581,13 @@ func convert_v1_ServiceSpec_To_api_ServiceSpec(in *ServiceSpec, out *api.Service
|
||||
}
|
||||
out.ClusterIP = in.ClusterIP
|
||||
out.Type = api.ServiceType(in.Type)
|
||||
if in.DeprecatedPublicIPs != nil {
|
||||
out.DeprecatedPublicIPs = make([]string, len(in.DeprecatedPublicIPs))
|
||||
for i := range in.DeprecatedPublicIPs {
|
||||
out.DeprecatedPublicIPs[i] = in.DeprecatedPublicIPs[i]
|
||||
if in.ExternalIPs != nil {
|
||||
out.ExternalIPs = make([]string, len(in.ExternalIPs))
|
||||
for i := range in.ExternalIPs {
|
||||
out.ExternalIPs[i] = in.ExternalIPs[i]
|
||||
}
|
||||
} else {
|
||||
out.DeprecatedPublicIPs = nil
|
||||
out.ExternalIPs = nil
|
||||
}
|
||||
out.SessionAffinity = api.ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
|
@@ -1954,13 +1954,13 @@ func deepCopy_v1_ServiceSpec(in ServiceSpec, out *ServiceSpec, c *conversion.Clo
|
||||
}
|
||||
out.ClusterIP = in.ClusterIP
|
||||
out.Type = in.Type
|
||||
if in.DeprecatedPublicIPs != nil {
|
||||
out.DeprecatedPublicIPs = make([]string, len(in.DeprecatedPublicIPs))
|
||||
for i := range in.DeprecatedPublicIPs {
|
||||
out.DeprecatedPublicIPs[i] = in.DeprecatedPublicIPs[i]
|
||||
if in.ExternalIPs != nil {
|
||||
out.ExternalIPs = make([]string, len(in.ExternalIPs))
|
||||
for i := range in.ExternalIPs {
|
||||
out.ExternalIPs[i] = in.ExternalIPs[i]
|
||||
}
|
||||
} else {
|
||||
out.DeprecatedPublicIPs = nil
|
||||
out.ExternalIPs = nil
|
||||
}
|
||||
out.SessionAffinity = in.SessionAffinity
|
||||
return nil
|
||||
|
@@ -1150,7 +1150,7 @@ type ServiceSpec struct {
|
||||
|
||||
// Deprecated. PublicIPs are used by external load balancers, or can be set by
|
||||
// users to handle external traffic that arrives at a node.
|
||||
DeprecatedPublicIPs []string `json:"deprecatedPublicIPs,omitempty" description:"deprecated. externally visible IPs (e.g. load balancers) that should be proxied to this service"`
|
||||
ExternalIPs []string `json:"externalIPs,omitempty" description:"externally visible IPs (e.g. load balancers) that should be proxied to this service"`
|
||||
|
||||
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity.
|
||||
SessionAffinity ServiceAffinity `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None; see http://releases.k8s.io/HEAD/docs/user-guide/services.md#virtual-ips-and-service-proxies"`
|
||||
|
@@ -1090,12 +1090,11 @@ func ValidateService(service *api.Service) errs.ValidationErrorList {
|
||||
}
|
||||
}
|
||||
|
||||
for _, ip := range service.Spec.DeprecatedPublicIPs {
|
||||
for _, ip := range service.Spec.ExternalIPs {
|
||||
if ip == "0.0.0.0" {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.publicIPs", ip, "is not an IP address"))
|
||||
} else if util.IsValidIPv4(ip) && net.ParseIP(ip).IsLoopback() {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.publicIPs", ip, "publicIP cannot be a loopback"))
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.externalIPs", ip, "is not an IP address"))
|
||||
}
|
||||
allErrs = append(allErrs, validateIpIsNotLinkLocalOrLoopback(ip, "spec.externalIPs")...)
|
||||
}
|
||||
|
||||
if service.Spec.Type == "" {
|
||||
@@ -1740,18 +1739,26 @@ func validateEndpointAddress(address *api.EndpointAddress) errs.ValidationErrorL
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("ip", address.IP, "invalid IPv4 address"))
|
||||
return allErrs
|
||||
}
|
||||
// We disallow some IPs as endpoints. Specifically, loopback addresses are
|
||||
// nonsensical and link-local addresses tend to be used for node-centric
|
||||
// purposes (e.g. metadata service).
|
||||
ip := net.ParseIP(address.IP)
|
||||
return validateIpIsNotLinkLocalOrLoopback(address.IP, "ip")
|
||||
}
|
||||
|
||||
func validateIpIsNotLinkLocalOrLoopback(ipAddress, fieldName string) errs.ValidationErrorList {
|
||||
// We disallow some IPs as endpoints or external-ips. Specifically, loopback addresses are
|
||||
// nonsensical and link-local addresses tend to be used for node-centric purposes (e.g. metadata service).
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
ip := net.ParseIP(ipAddress)
|
||||
if ip == nil {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, ipAddress, "not a valid IP address"))
|
||||
return allErrs
|
||||
}
|
||||
if ip.IsLoopback() {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("ip", address.IP, "may not be in the loopback range (127.0.0.0/8)"))
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, ipAddress, "may not be in the loopback range (127.0.0.0/8)"))
|
||||
}
|
||||
if ip.IsLinkLocalUnicast() {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("ip", address.IP, "may not be in the link-local range (169.254.0.0/16)"))
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, ipAddress, "may not be in the link-local range (169.254.0.0/16)"))
|
||||
}
|
||||
if ip.IsLinkLocalMulticast() {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("ip", address.IP, "may not be in the link-local multicast range (224.0.0.0/24)"))
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, ipAddress, "may not be in the link-local multicast range (224.0.0.0/24)"))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
@@ -1721,23 +1721,23 @@ func TestValidateService(t *testing.T) {
|
||||
{
|
||||
name: "invalid publicIPs localhost",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.DeprecatedPublicIPs = []string{"127.0.0.1"}
|
||||
s.Spec.ExternalIPs = []string{"127.0.0.1"}
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
{
|
||||
name: "invalid publicIPs",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.DeprecatedPublicIPs = []string{"0.0.0.0"}
|
||||
s.Spec.ExternalIPs = []string{"0.0.0.0"}
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
{
|
||||
name: "valid publicIPs host",
|
||||
name: "invalid publicIPs host",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.DeprecatedPublicIPs = []string{"myhost.mydomain"}
|
||||
s.Spec.ExternalIPs = []string{"myhost.mydomain"}
|
||||
},
|
||||
numErrs: 0,
|
||||
numErrs: 1,
|
||||
},
|
||||
{
|
||||
name: "dup port name",
|
||||
|
Reference in New Issue
Block a user