Skip to content

Commit

Permalink
Don't use pointers for session affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Dec 29, 2014
1 parent 7dec65f commit ca27fb2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions pkg/proxy/proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions pkg/registry/service/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ca27fb2

Please sign in to comment.