Don't use pointers for session affinity

This commit is contained in:
Tim Hockin 2014-12-29 14:39:09 -08:00
parent 7dec65f535
commit ca27fb259c
7 changed files with 15 additions and 17 deletions

View File

@ -645,7 +645,7 @@ type ServiceSpec struct {
ContainerPort util.IntOrString `json:"containerPort,omitempty"` ContainerPort util.IntOrString `json:"containerPort,omitempty"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity. // 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 // Service is a named abstraction of software service (for example, mysql) consisting of local port

View File

@ -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"` 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. // 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: // Endpoints is a collection of endpoints that implement the actual service, for example:

View File

@ -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"` 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. // 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: // Endpoints is a collection of endpoints that implement the actual service, for example:

View File

@ -672,7 +672,7 @@ type ServiceSpec struct {
ContainerPort util.IntOrString `json:"containerPort,omitempty"` ContainerPort util.IntOrString `json:"containerPort,omitempty"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity. // 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 // Service is a named abstraction of software service (for example, mysql) consisting of local port

View File

@ -474,10 +474,10 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
} }
} }
} }
if service.Spec.SessionAffinity != nil { if service.Spec.SessionAffinity == "" {
if !supportedSessionAffinityType.Has(string(*service.Spec.SessionAffinity)) { service.Spec.SessionAffinity = api.AffinityTypeNone
allErrs = append(allErrs, errs.NewFieldNotSupported("spec.sessionAffinity", service.Spec.SessionAffinity)) } else if !supportedSessionAffinityType.Has(string(service.Spec.SessionAffinity)) {
} allErrs = append(allErrs, errs.NewFieldNotSupported("spec.sessionAffinity", service.Spec.SessionAffinity))
} }
return allErrs return allErrs

View File

@ -485,12 +485,9 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
info.portalIP = serviceIP info.portalIP = serviceIP
info.portalPort = service.Spec.Port info.portalPort = service.Spec.Port
info.publicIP = service.Spec.PublicIPs info.publicIP = service.Spec.PublicIPs
info.sessionAffinityType = service.Spec.SessionAffinity
if service.Spec.SessionAffinity != nil { // TODO: paramaterize this in the types api file as an attribute of sticky session. For now it's hardcoded to 3 hours.
info.sessionAffinityType = *service.Spec.SessionAffinity info.stickyMaxAgeMinutes = 180
// 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) glog.V(4).Infof("info: %+v", info)
err = proxier.openPortal(service.Name, info) err = proxier.openPortal(service.Name, info)

View File

@ -134,9 +134,10 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if err != nil { if err != nil {
return nil, err return nil, err
} }
var affinityType api.AffinityType = api.AffinityTypeNone // TODO: We should be able to rely on valid input, and not do defaulting here.
if service.Spec.SessionAffinity != nil { var affinityType api.AffinityType = service.Spec.SessionAffinity
affinityType = *service.Spec.SessionAffinity if affinityType == "" {
affinityType = api.AffinityTypeNone
} }
if len(service.Spec.PublicIPs) > 0 { if len(service.Spec.PublicIPs) > 0 {
for _, publicIP := range service.Spec.PublicIPs { for _, publicIP := range service.Spec.PublicIPs {