Rename AffinityType to ServiceAffinity
This commit is contained in:
parent
1e1092ddbc
commit
a548d542db
@ -182,8 +182,8 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
|
||||
protocols := []api.Protocol{api.ProtocolTCP, api.ProtocolUDP}
|
||||
*p = protocols[c.Rand.Intn(len(protocols))]
|
||||
},
|
||||
func(p *api.AffinityType, c fuzz.Continue) {
|
||||
types := []api.AffinityType{api.AffinityTypeClientIP, api.AffinityTypeNone}
|
||||
func(p *api.ServiceAffinity, c fuzz.Continue) {
|
||||
types := []api.ServiceAffinity{api.ServiceAffinityClientIP, api.ServiceAffinityNone}
|
||||
*p = types[c.Rand.Intn(len(types))]
|
||||
},
|
||||
func(ct *api.Container, c fuzz.Continue) {
|
||||
|
@ -969,14 +969,14 @@ type ServiceList struct {
|
||||
}
|
||||
|
||||
// Session Affinity Type string
|
||||
type AffinityType string
|
||||
type ServiceAffinity string
|
||||
|
||||
const (
|
||||
// AffinityTypeClientIP is the Client IP based.
|
||||
AffinityTypeClientIP AffinityType = "ClientIP"
|
||||
// ServiceAffinityClientIP is the Client IP based.
|
||||
ServiceAffinityClientIP ServiceAffinity = "ClientIP"
|
||||
|
||||
// AffinityTypeNone - no session affinity.
|
||||
AffinityTypeNone AffinityType = "None"
|
||||
// ServiceAffinityNone - no session affinity.
|
||||
ServiceAffinityNone ServiceAffinity = "None"
|
||||
)
|
||||
|
||||
// ServiceStatus represents the current status of a service
|
||||
@ -1009,7 +1009,7 @@ type ServiceSpec struct {
|
||||
PublicIPs []string `json:"publicIPs,omitempty"`
|
||||
|
||||
// Required: Supports "ClientIP" and "None". Used to maintain session affinity.
|
||||
SessionAffinity AffinityType `json:"sessionAffinity,omitempty"`
|
||||
SessionAffinity ServiceAffinity `json:"sessionAffinity,omitempty"`
|
||||
}
|
||||
|
||||
type ServicePort struct {
|
||||
|
@ -4057,7 +4057,7 @@ func convert_v1_ServiceSpec_To_api_ServiceSpec(in *ServiceSpec, out *newer.Servi
|
||||
} else {
|
||||
out.PublicIPs = nil
|
||||
}
|
||||
out.SessionAffinity = newer.AffinityType(in.SessionAffinity)
|
||||
out.SessionAffinity = newer.ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -4093,7 +4093,7 @@ func convert_api_ServiceSpec_To_v1_ServiceSpec(in *newer.ServiceSpec, out *Servi
|
||||
} else {
|
||||
out.PublicIPs = nil
|
||||
}
|
||||
out.SessionAffinity = AffinityType(in.SessionAffinity)
|
||||
out.SessionAffinity = ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func addDefaultingFuncs() {
|
||||
},
|
||||
func(obj *ServiceSpec) {
|
||||
if obj.SessionAffinity == "" {
|
||||
obj.SessionAffinity = AffinityTypeNone
|
||||
obj.SessionAffinity = ServiceAffinityNone
|
||||
}
|
||||
for i := range obj.Ports {
|
||||
sp := &obj.Ports[i]
|
||||
|
@ -159,8 +159,8 @@ func TestSetDefaultService(t *testing.T) {
|
||||
svc := ¤t.Service{}
|
||||
obj2 := roundTrip(t, runtime.Object(svc))
|
||||
svc2 := obj2.(*current.Service)
|
||||
if svc2.Spec.SessionAffinity != current.AffinityTypeNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.AffinityTypeNone, svc2.Spec.SessionAffinity)
|
||||
if svc2.Spec.SessionAffinity != current.ServiceAffinityNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.Spec.SessionAffinity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -951,14 +951,14 @@ type ReplicationControllerList struct {
|
||||
}
|
||||
|
||||
// Session Affinity Type string
|
||||
type AffinityType string
|
||||
type ServiceAffinity string
|
||||
|
||||
const (
|
||||
// AffinityTypeClientIP is the Client IP based.
|
||||
AffinityTypeClientIP AffinityType = "ClientIP"
|
||||
// ServiceAffinityClientIP is the Client IP based.
|
||||
ServiceAffinityClientIP ServiceAffinity = "ClientIP"
|
||||
|
||||
// AffinityTypeNone - no session affinity.
|
||||
AffinityTypeNone AffinityType = "None"
|
||||
// ServiceAffinityNone - no session affinity.
|
||||
ServiceAffinityNone ServiceAffinity = "None"
|
||||
)
|
||||
|
||||
// ServiceStatus represents the current status of a service
|
||||
@ -987,7 +987,7 @@ type ServiceSpec struct {
|
||||
PublicIPs []string `json:"publicIPs,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 AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||
SessionAffinity ServiceAffinity `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||
}
|
||||
|
||||
type ServicePort struct {
|
||||
|
@ -74,7 +74,7 @@ func addDefaultingFuncs() {
|
||||
obj.Protocol = ProtocolTCP
|
||||
}
|
||||
if obj.SessionAffinity == "" {
|
||||
obj.SessionAffinity = AffinityTypeNone
|
||||
obj.SessionAffinity = ServiceAffinityNone
|
||||
}
|
||||
for i := range obj.Ports {
|
||||
sp := &obj.Ports[i]
|
||||
|
@ -149,8 +149,8 @@ func TestSetDefaultService(t *testing.T) {
|
||||
if svc2.Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected default protocol :%s, got: %s", current.ProtocolTCP, svc2.Protocol)
|
||||
}
|
||||
if svc2.SessionAffinity != current.AffinityTypeNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.AffinityTypeNone, svc2.SessionAffinity)
|
||||
if svc2.SessionAffinity != current.ServiceAffinityNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.SessionAffinity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -793,14 +793,14 @@ type PodTemplate struct {
|
||||
}
|
||||
|
||||
// Session Affinity Type string
|
||||
type AffinityType string
|
||||
type ServiceAffinity string
|
||||
|
||||
const (
|
||||
// AffinityTypeClientIP is the Client IP based.
|
||||
AffinityTypeClientIP AffinityType = "ClientIP"
|
||||
// ServiceAffinityClientIP is the Client IP based.
|
||||
ServiceAffinityClientIP ServiceAffinity = "ClientIP"
|
||||
|
||||
// AffinityTypeNone - no session affinity.
|
||||
AffinityTypeNone AffinityType = "None"
|
||||
// ServiceAffinityNone - no session affinity.
|
||||
ServiceAffinityNone ServiceAffinity = "None"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -856,7 +856,7 @@ type Service struct {
|
||||
ProxyPort int `json:"proxyPort,omitempty" description:"if non-zero, a pre-allocated host port used for this service by the proxy on each node; assigned by the master and ignored on input"`
|
||||
|
||||
// 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 ServiceAffinity `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||
|
||||
// Optional: Ports to expose on the service. If this field is
|
||||
// specified, the legacy fields (Port, PortName, Protocol, and
|
||||
|
@ -75,7 +75,7 @@ func addDefaultingFuncs() {
|
||||
obj.Protocol = ProtocolTCP
|
||||
}
|
||||
if obj.SessionAffinity == "" {
|
||||
obj.SessionAffinity = AffinityTypeNone
|
||||
obj.SessionAffinity = ServiceAffinityNone
|
||||
}
|
||||
for i := range obj.Ports {
|
||||
sp := &obj.Ports[i]
|
||||
|
@ -149,8 +149,8 @@ func TestSetDefaultService(t *testing.T) {
|
||||
if svc2.Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected default protocol :%s, got: %s", current.ProtocolTCP, svc2.Protocol)
|
||||
}
|
||||
if svc2.SessionAffinity != current.AffinityTypeNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.AffinityTypeNone, svc2.SessionAffinity)
|
||||
if svc2.SessionAffinity != current.ServiceAffinityNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.SessionAffinity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -799,14 +799,14 @@ type PodTemplate struct {
|
||||
}
|
||||
|
||||
// Session Affinity Type string
|
||||
type AffinityType string
|
||||
type ServiceAffinity string
|
||||
|
||||
const (
|
||||
// AffinityTypeClientIP is the Client IP based.
|
||||
AffinityTypeClientIP AffinityType = "ClientIP"
|
||||
// ServiceAffinityClientIP is the Client IP based.
|
||||
ServiceAffinityClientIP ServiceAffinity = "ClientIP"
|
||||
|
||||
// AffinityTypeNone - no session affinity.
|
||||
AffinityTypeNone AffinityType = "None"
|
||||
// ServiceAffinityNone - no session affinity.
|
||||
ServiceAffinityNone ServiceAffinity = "None"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -864,7 +864,7 @@ type Service struct {
|
||||
ProxyPort int `json:"proxyPort,omitempty" description:"if non-zero, a pre-allocated host port used for this service by the proxy on each node; assigned by the master and ignored on input"`
|
||||
|
||||
// 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 ServiceAffinity `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||
|
||||
// Optional: Ports to expose on the service. If this field is
|
||||
// specified, the legacy fields (Port, PortName, Protocol, and
|
||||
|
@ -3871,7 +3871,7 @@ func convert_v1beta3_ServiceSpec_To_api_ServiceSpec(in *ServiceSpec, out *newer.
|
||||
} else {
|
||||
out.PublicIPs = nil
|
||||
}
|
||||
out.SessionAffinity = newer.AffinityType(in.SessionAffinity)
|
||||
out.SessionAffinity = newer.ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -3907,7 +3907,7 @@ func convert_api_ServiceSpec_To_v1beta3_ServiceSpec(in *newer.ServiceSpec, out *
|
||||
} else {
|
||||
out.PublicIPs = nil
|
||||
}
|
||||
out.SessionAffinity = AffinityType(in.SessionAffinity)
|
||||
out.SessionAffinity = ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ func addDefaultingFuncs() {
|
||||
},
|
||||
func(obj *ServiceSpec) {
|
||||
if obj.SessionAffinity == "" {
|
||||
obj.SessionAffinity = AffinityTypeNone
|
||||
obj.SessionAffinity = ServiceAffinityNone
|
||||
}
|
||||
for i := range obj.Ports {
|
||||
sp := &obj.Ports[i]
|
||||
|
@ -159,8 +159,8 @@ func TestSetDefaultService(t *testing.T) {
|
||||
svc := ¤t.Service{}
|
||||
obj2 := roundTrip(t, runtime.Object(svc))
|
||||
svc2 := obj2.(*current.Service)
|
||||
if svc2.Spec.SessionAffinity != current.AffinityTypeNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.AffinityTypeNone, svc2.Spec.SessionAffinity)
|
||||
if svc2.Spec.SessionAffinity != current.ServiceAffinityNone {
|
||||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.ServiceAffinityNone, svc2.Spec.SessionAffinity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -955,14 +955,14 @@ type ReplicationControllerList struct {
|
||||
}
|
||||
|
||||
// Session Affinity Type string
|
||||
type AffinityType string
|
||||
type ServiceAffinity string
|
||||
|
||||
const (
|
||||
// AffinityTypeClientIP is the Client IP based.
|
||||
AffinityTypeClientIP AffinityType = "ClientIP"
|
||||
// ServiceAffinityClientIP is the Client IP based.
|
||||
ServiceAffinityClientIP ServiceAffinity = "ClientIP"
|
||||
|
||||
// AffinityTypeNone - no session affinity.
|
||||
AffinityTypeNone AffinityType = "None"
|
||||
// ServiceAffinityNone - no session affinity.
|
||||
ServiceAffinityNone ServiceAffinity = "None"
|
||||
)
|
||||
|
||||
// ServiceStatus represents the current status of a service
|
||||
@ -991,7 +991,7 @@ type ServiceSpec struct {
|
||||
PublicIPs []string `json:"publicIPs,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 AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||
SessionAffinity ServiceAffinity `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
|
||||
}
|
||||
|
||||
type ServicePort struct {
|
||||
|
@ -985,7 +985,7 @@ func ValidatePodTemplateUpdate(newPod, oldPod *api.PodTemplate) errs.ValidationE
|
||||
return allErrs
|
||||
}
|
||||
|
||||
var supportedSessionAffinityType = util.NewStringSet(string(api.AffinityTypeClientIP), string(api.AffinityTypeNone))
|
||||
var supportedSessionAffinityType = util.NewStringSet(string(api.ServiceAffinityClientIP), string(api.ServiceAffinityNone))
|
||||
|
||||
// ValidateService tests if required fields in the service are set.
|
||||
func ValidateService(service *api.Service) errs.ValidationErrorList {
|
||||
|
@ -63,7 +63,7 @@ type TCPLoadBalancer interface {
|
||||
// if so, what its IP address or hostname is.
|
||||
GetTCPLoadBalancer(name, region string) (endpoint string, exists bool, err error)
|
||||
// CreateTCPLoadBalancer creates a new tcp load balancer. Returns the IP address or hostname of the balancer
|
||||
CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.AffinityType) (string, error)
|
||||
CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.ServiceAffinity) (string, error)
|
||||
// UpdateTCPLoadBalancer updates hosts under the specified load balancer.
|
||||
UpdateTCPLoadBalancer(name, region string, hosts []string) error
|
||||
// DeleteTCPLoadBalancer deletes a specified load balancer.
|
||||
|
@ -101,7 +101,7 @@ func (f *FakeCloud) GetTCPLoadBalancer(name, region string) (endpoint string, ex
|
||||
|
||||
// CreateTCPLoadBalancer is a test-spy implementation of TCPLoadBalancer.CreateTCPLoadBalancer.
|
||||
// It adds an entry "create" into the internal method call record.
|
||||
func (f *FakeCloud) CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.AffinityType) (string, error) {
|
||||
func (f *FakeCloud) CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.ServiceAffinity) (string, error) {
|
||||
f.addCall("create")
|
||||
f.Balancers = append(f.Balancers, FakeBalancer{name, region, externalIP, ports, hosts})
|
||||
return f.ExternalIP.String(), f.Err
|
||||
|
@ -294,11 +294,11 @@ func isHTTPErrorCode(err error, code int) bool {
|
||||
}
|
||||
|
||||
// translate from what K8s supports to what the cloud provider supports for session affinity.
|
||||
func translateAffinityType(affinityType api.AffinityType) GCEAffinityType {
|
||||
func translateAffinityType(affinityType api.ServiceAffinity) GCEAffinityType {
|
||||
switch affinityType {
|
||||
case api.AffinityTypeClientIP:
|
||||
case api.ServiceAffinityClientIP:
|
||||
return GCEAffinityTypeClientIP
|
||||
case api.AffinityTypeNone:
|
||||
case api.ServiceAffinityNone:
|
||||
return GCEAffinityTypeNone
|
||||
default:
|
||||
glog.Errorf("unexpected affinity type: %v", affinityType)
|
||||
@ -309,7 +309,7 @@ func translateAffinityType(affinityType api.AffinityType) GCEAffinityType {
|
||||
// CreateTCPLoadBalancer is an implementation of TCPLoadBalancer.CreateTCPLoadBalancer.
|
||||
// TODO(a-robinson): Don't just ignore specified IP addresses. Check if they're
|
||||
// owned by the project and available to be used, and use them if they are.
|
||||
func (gce *GCECloud) CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.AffinityType) (string, error) {
|
||||
func (gce *GCECloud) CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.ServiceAffinity) (string, error) {
|
||||
err := gce.makeTargetPool(name, region, hosts, translateAffinityType(affinityType))
|
||||
if err != nil {
|
||||
if !isHTTPErrorCode(err, http.StatusConflict) {
|
||||
|
@ -480,7 +480,7 @@ func (lb *LoadBalancer) GetTCPLoadBalancer(name, region string) (endpoint string
|
||||
// a list of regions (from config) and query/create loadbalancers in
|
||||
// each region.
|
||||
|
||||
func (lb *LoadBalancer) CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinity api.AffinityType) (string, error) {
|
||||
func (lb *LoadBalancer) CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinity api.ServiceAffinity) (string, error) {
|
||||
glog.V(4).Infof("CreateTCPLoadBalancer(%v, %v, %v, %v, %v, %v)", name, region, externalIP, ports, hosts, affinity)
|
||||
|
||||
if len(ports) > 1 {
|
||||
@ -489,9 +489,9 @@ func (lb *LoadBalancer) CreateTCPLoadBalancer(name, region string, externalIP ne
|
||||
|
||||
var persistence *vips.SessionPersistence
|
||||
switch affinity {
|
||||
case api.AffinityTypeNone:
|
||||
case api.ServiceAffinityNone:
|
||||
persistence = nil
|
||||
case api.AffinityTypeClientIP:
|
||||
case api.ServiceAffinityClientIP:
|
||||
persistence = &vips.SessionPersistence{Type: "SOURCE_IP"}
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported load balancer affinity: %v", affinity)
|
||||
|
@ -181,7 +181,7 @@ func (c *Controller) CreateMasterServiceIfNeeded(serviceName string, serviceIP n
|
||||
// maintained by this code, not by the pod selector
|
||||
Selector: nil,
|
||||
PortalIP: serviceIP.String(),
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
},
|
||||
}
|
||||
_, err := c.ServiceRegistry.CreateService(ctx, svc)
|
||||
|
@ -29,7 +29,7 @@ type LoadBalancer interface {
|
||||
// NextEndpoint returns the endpoint to handle a request for the given
|
||||
// service-port and source address.
|
||||
NextEndpoint(service ServicePortName, srcAddr net.Addr) (string, error)
|
||||
NewService(service ServicePortName, sessionAffinityType api.AffinityType, stickyMaxAgeMinutes int) error
|
||||
NewService(service ServicePortName, sessionAffinityType api.ServiceAffinity, stickyMaxAgeMinutes int) error
|
||||
CleanupStaleStickySessions(service ServicePortName)
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ type serviceInfo struct {
|
||||
socket proxySocket
|
||||
timeout time.Duration
|
||||
publicIPs []string // TODO: make this net.IP
|
||||
sessionAffinityType api.AffinityType
|
||||
sessionAffinityType api.ServiceAffinity
|
||||
stickyMaxAgeMinutes int
|
||||
}
|
||||
|
||||
@ -208,8 +208,8 @@ func (proxier *Proxier) addServiceOnPort(service ServicePortName, protocol api.P
|
||||
protocol: protocol,
|
||||
socket: sock,
|
||||
timeout: timeout,
|
||||
sessionAffinityType: api.AffinityTypeNone, // default
|
||||
stickyMaxAgeMinutes: 180, // TODO: paramaterize this in the API.
|
||||
sessionAffinityType: api.ServiceAffinityNone, // default
|
||||
stickyMaxAgeMinutes: 180, // TODO: paramaterize this in the API.
|
||||
}
|
||||
proxier.setServiceInfo(service, si)
|
||||
|
||||
|
@ -45,7 +45,7 @@ type affinityState struct {
|
||||
}
|
||||
|
||||
type affinityPolicy struct {
|
||||
affinityType api.AffinityType
|
||||
affinityType api.ServiceAffinity
|
||||
affinityMap map[string]*affinityState // map client IP -> affinity info
|
||||
ttlMinutes int
|
||||
}
|
||||
@ -65,7 +65,7 @@ type balancerState struct {
|
||||
affinity affinityPolicy
|
||||
}
|
||||
|
||||
func newAffinityPolicy(affinityType api.AffinityType, ttlMinutes int) *affinityPolicy {
|
||||
func newAffinityPolicy(affinityType api.ServiceAffinity, ttlMinutes int) *affinityPolicy {
|
||||
return &affinityPolicy{
|
||||
affinityType: affinityType,
|
||||
affinityMap: make(map[string]*affinityState),
|
||||
@ -80,7 +80,7 @@ func NewLoadBalancerRR() *LoadBalancerRR {
|
||||
}
|
||||
}
|
||||
|
||||
func (lb *LoadBalancerRR) NewService(svcPort ServicePortName, affinityType api.AffinityType, ttlMinutes int) error {
|
||||
func (lb *LoadBalancerRR) NewService(svcPort ServicePortName, affinityType api.ServiceAffinity, ttlMinutes int) error {
|
||||
lb.lock.Lock()
|
||||
defer lb.lock.Unlock()
|
||||
lb.newServiceInternal(svcPort, affinityType, ttlMinutes)
|
||||
@ -88,7 +88,7 @@ func (lb *LoadBalancerRR) NewService(svcPort ServicePortName, affinityType api.A
|
||||
}
|
||||
|
||||
// This assumes that lb.lock is already held.
|
||||
func (lb *LoadBalancerRR) newServiceInternal(svcPort ServicePortName, affinityType api.AffinityType, ttlMinutes int) *balancerState {
|
||||
func (lb *LoadBalancerRR) newServiceInternal(svcPort ServicePortName, affinityType api.ServiceAffinity, ttlMinutes int) *balancerState {
|
||||
if ttlMinutes == 0 {
|
||||
ttlMinutes = 180 //default to 3 hours if not specified. Should 0 be unlimeted instead????
|
||||
}
|
||||
@ -103,7 +103,7 @@ func (lb *LoadBalancerRR) newServiceInternal(svcPort ServicePortName, affinityTy
|
||||
// return true if this service is using some form of session affinity.
|
||||
func isSessionAffinity(affinity *affinityPolicy) bool {
|
||||
// Should never be empty string, but checking for it to be safe.
|
||||
if affinity.affinityType == "" || affinity.affinityType == api.AffinityTypeNone {
|
||||
if affinity.affinityType == "" || affinity.affinityType == api.ServiceAffinityNone {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -262,7 +262,7 @@ func (lb *LoadBalancerRR) OnUpdate(allEndpoints []api.Endpoints) {
|
||||
// OnUpdate can be called without NewService being called externally.
|
||||
// To be safe we will call it here. A new service will only be created
|
||||
// if one does not already exist.
|
||||
state = lb.newServiceInternal(svcPort, api.AffinityTypeNone, 0)
|
||||
state = lb.newServiceInternal(svcPort, api.ServiceAffinityNone, 0)
|
||||
state.endpoints = slice.ShuffleStrings(newEndpoints)
|
||||
|
||||
// Reset the round-robin index.
|
||||
|
@ -351,7 +351,7 @@ func TestStickyLoadBalanceWorksWithSingleEndpoint(t *testing.T) {
|
||||
if err == nil || len(endpoint) != 0 {
|
||||
t.Errorf("Didn't fail with non-existent service")
|
||||
}
|
||||
loadBalancer.NewService(service, api.AffinityTypeClientIP, 0)
|
||||
loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
|
||||
endpoints := make([]api.Endpoints, 1)
|
||||
endpoints[0] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
|
||||
@ -375,7 +375,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpoints(t *testing.T) {
|
||||
t.Errorf("Didn't fail with non-existent service")
|
||||
}
|
||||
|
||||
loadBalancer.NewService(service, api.AffinityTypeClientIP, 0)
|
||||
loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
|
||||
endpoints := make([]api.Endpoints, 1)
|
||||
endpoints[0] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
|
||||
@ -409,7 +409,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsStickyNone(t *testing.T) {
|
||||
t.Errorf("Didn't fail with non-existent service")
|
||||
}
|
||||
|
||||
loadBalancer.NewService(service, api.AffinityTypeNone, 0)
|
||||
loadBalancer.NewService(service, api.ServiceAffinityNone, 0)
|
||||
endpoints := make([]api.Endpoints, 1)
|
||||
endpoints[0] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
|
||||
@ -447,7 +447,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
|
||||
t.Errorf("Didn't fail with non-existent service")
|
||||
}
|
||||
|
||||
loadBalancer.NewService(service, api.AffinityTypeClientIP, 0)
|
||||
loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
|
||||
endpoints := make([]api.Endpoints, 1)
|
||||
endpoints[0] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
|
||||
@ -521,7 +521,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
|
||||
t.Errorf("Didn't fail with non-existent service")
|
||||
}
|
||||
|
||||
loadBalancer.NewService(service, api.AffinityTypeClientIP, 0)
|
||||
loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
|
||||
endpoints := make([]api.Endpoints, 1)
|
||||
endpoints[0] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
|
||||
@ -581,7 +581,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
|
||||
if err == nil || len(endpoint) != 0 {
|
||||
t.Errorf("Didn't fail with non-existent service")
|
||||
}
|
||||
loadBalancer.NewService(fooService, api.AffinityTypeClientIP, 0)
|
||||
loadBalancer.NewService(fooService, api.ServiceAffinityClientIP, 0)
|
||||
endpoints := make([]api.Endpoints, 2)
|
||||
endpoints[0] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: fooService.Name, Namespace: fooService.Namespace},
|
||||
@ -593,7 +593,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
|
||||
},
|
||||
}
|
||||
barService := ServicePortName{types.NamespacedName{"testnamespace", "bar"}, ""}
|
||||
loadBalancer.NewService(barService, api.AffinityTypeClientIP, 0)
|
||||
loadBalancer.NewService(barService, api.ServiceAffinityClientIP, 0)
|
||||
endpoints[1] = api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{Name: barService.Name, Namespace: barService.Namespace},
|
||||
Subsets: []api.EndpointSubset{
|
||||
|
@ -67,7 +67,7 @@ func TestServiceRegistryCreate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -108,7 +108,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -119,7 +119,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Protocol: api.ProtocolTCP,
|
||||
}},
|
||||
@ -161,7 +161,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
|
||||
ResourceVersion: svc.ResourceVersion},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz2"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -204,7 +204,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -215,7 +215,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"ThisSelectorFailsValidation": "ok"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -242,7 +242,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -269,7 +269,7 @@ func TestServiceRegistryDelete(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -291,7 +291,7 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -315,7 +315,7 @@ func TestServiceRegistryUpdateExternalService(t *testing.T) {
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: false,
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -351,7 +351,7 @@ func TestServiceRegistryUpdateMultiPortExternalService(t *testing.T) {
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Name: "p",
|
||||
Port: 6502,
|
||||
@ -490,7 +490,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -511,7 +511,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -540,7 +540,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
PortalIP: testIP,
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -565,7 +565,7 @@ func TestServiceRegistryIPReallocation(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -588,7 +588,7 @@ func TestServiceRegistryIPReallocation(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -613,7 +613,7 @@ func TestServiceRegistryIPUpdate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
@ -657,7 +657,7 @@ func TestServiceRegistryIPExternalLoadBalancer(t *testing.T) {
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
SessionAffinity: api.AffinityTypeNone,
|
||||
SessionAffinity: api.ServiceAffinityNone,
|
||||
Ports: []api.ServicePort{{
|
||||
Port: 6502,
|
||||
Protocol: api.ProtocolTCP,
|
||||
|
Loading…
Reference in New Issue
Block a user