Commit 53a9d106 authored by Daniel Smith's avatar Daniel Smith

Merge pull request #3167 from thockin/affinity

Don't use pointers for session affinity
parents 9c2cd555 ca27fb25
......@@ -645,7 +645,7 @@ type ServiceSpec struct {
ContainerPort util.IntOrString `json:"containerPort,omitempty"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity.
SessionAffinity *AffinityType `json:"sessionAffinity,omitempty"`
SessionAffinity AffinityType `json:"sessionAffinity,omitempty"`
}
// Service is a named abstraction of software service (for example, mysql) consisting of local port
......
......@@ -506,7 +506,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; Disabled if unspecified"`
SessionAffinity AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
}
// Endpoints is a collection of endpoints that implement the actual service, for example:
......
......@@ -469,7 +469,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; Disabled if unspecified"`
SessionAffinity AffinityType `json:"sessionAffinity,omitempty" description:"enable client IP based session affinity; must be ClientIP or None; defaults to None"`
}
// Endpoints is a collection of endpoints that implement the actual service, for example:
......
......@@ -672,7 +672,7 @@ type ServiceSpec struct {
ContainerPort util.IntOrString `json:"containerPort,omitempty"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity.
SessionAffinity *AffinityType `json:"sessionAffinity,omitempty"`
SessionAffinity AffinityType `json:"sessionAffinity,omitempty"`
}
// Service is a named abstraction of software service (for example, mysql) consisting of local port
......
......@@ -474,10 +474,10 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
}
}
}
if service.Spec.SessionAffinity != nil {
if !supportedSessionAffinityType.Has(string(*service.Spec.SessionAffinity)) {
allErrs = append(allErrs, errs.NewFieldNotSupported("spec.sessionAffinity", service.Spec.SessionAffinity))
}
if service.Spec.SessionAffinity == "" {
service.Spec.SessionAffinity = api.AffinityTypeNone
} else if !supportedSessionAffinityType.Has(string(service.Spec.SessionAffinity)) {
allErrs = append(allErrs, errs.NewFieldNotSupported("spec.sessionAffinity", service.Spec.SessionAffinity))
}
return allErrs
......
......@@ -485,12 +485,9 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
info.portalIP = serviceIP
info.portalPort = service.Spec.Port
info.publicIP = service.Spec.PublicIPs
if service.Spec.SessionAffinity != nil {
info.sessionAffinityType = *service.Spec.SessionAffinity
// TODO: paramaterize this in the types api file as an attribute of sticky session. For now it's hardcoded to 3 hours.
info.stickyMaxAgeMinutes = 180
}
info.sessionAffinityType = service.Spec.SessionAffinity
// TODO: paramaterize this in the types api file as an attribute of sticky session. For now it's hardcoded to 3 hours.
info.stickyMaxAgeMinutes = 180
glog.V(4).Infof("info: %+v", info)
err = proxier.openPortal(service.Name, info)
......
......@@ -134,9 +134,10 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if err != nil {
return nil, err
}
var affinityType api.AffinityType = api.AffinityTypeNone
if service.Spec.SessionAffinity != nil {
affinityType = *service.Spec.SessionAffinity
// TODO: We should be able to rely on valid input, and not do defaulting here.
var affinityType api.AffinityType = service.Spec.SessionAffinity
if affinityType == "" {
affinityType = api.AffinityTypeNone
}
if len(service.Spec.PublicIPs) > 0 {
for _, publicIP := range service.Spec.PublicIPs {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment