From ca27fb259c5dfaeb5ee402923486d388fcaeaf8d Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 29 Dec 2014 14:39:09 -0800 Subject: [PATCH] Don't use pointers for session affinity --- pkg/api/types.go | 2 +- pkg/api/v1beta1/types.go | 2 +- pkg/api/v1beta2/types.go | 2 +- pkg/api/v1beta3/types.go | 2 +- pkg/api/validation/validation.go | 8 ++++---- pkg/proxy/proxier.go | 9 +++------ pkg/registry/service/rest.go | 7 ++++--- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 89855d46a44..d62e90157e2 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -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 diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 4d768ad27fb..c99832dd549 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -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: diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index b8438ec8b82..c4ea3804256 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -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: diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 12d1cc31751..8e90164400a 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -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 diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 99d8227b29a..c27c1713887 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -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 diff --git a/pkg/proxy/proxier.go b/pkg/proxy/proxier.go index cf15116f064..22d9cae83e7 100644 --- a/pkg/proxy/proxier.go +++ b/pkg/proxy/proxier.go @@ -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) diff --git a/pkg/registry/service/rest.go b/pkg/registry/service/rest.go index a541adbbd1d..1165aeeb01e 100644 --- a/pkg/registry/service/rest.go +++ b/pkg/registry/service/rest.go @@ -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 {