Updated types API to include session affinity. …

- changed CLIENT-IP and NONE to be ClientIP and None respectively
 - updated conversions to support translating between api versions.
 - updated validations to validate session affinity type if specified.
This commit is contained in:
Mike Foley 2014-12-17 07:52:11 -05:00
parent ff305003f0
commit 569ce87f0e
7 changed files with 78 additions and 0 deletions

View File

@ -572,6 +572,17 @@ type ServiceList struct {
Items []Service `json:"items"`
}
// Session Affinity Type string
type AffinityType string
const (
// AffinityTypeClientIP is the Client IP based.
AffinityTypeClientIP AffinityType = "ClientIP"
// AffinityTypeNone - no session affinity.
AffinityTypeNone AffinityType = "None"
)
// ServiceStatus represents the current status of a service
type ServiceStatus struct{}
@ -606,6 +617,9 @@ type ServiceSpec struct {
// ContainerPort is the name of the port on the container to direct traffic to.
// Optional, if unspecified use the first port on the container.
ContainerPort util.IntOrString `json:"containerPort,omitempty"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity.
SessionAffinity *AffinityType `json:"sessionAffinity,omitempty"`
}
// Service is a named abstraction of software service (for example, mysql) consisting of local port

View File

@ -436,6 +436,10 @@ func init() {
out.ContainerPort = in.Spec.ContainerPort
out.PortalIP = in.Spec.PortalIP
out.ProxyPort = in.Spec.ProxyPort
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
return err
}
return nil
},
func(in *Service, out *newer.Service, s conversion.Scope) error {
@ -459,6 +463,10 @@ func init() {
out.Spec.ContainerPort = in.ContainerPort
out.Spec.PortalIP = in.PortalIP
out.Spec.ProxyPort = in.ProxyPort
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
return err
}
return nil
},

View File

@ -448,6 +448,17 @@ type PodTemplate struct {
Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize the pods created from the template; must match the selector of the replication controller to which the template belongs; may match selectors of services"`
}
// Session Affinity Type string
type AffinityType string
const (
// AffinityTypeClientIP is the Client IP based.
AffinityTypeClientIP AffinityType = "ClientIP"
// AffinityTypeNone - no session affinity.
AffinityTypeNone AffinityType = "None"
)
// ServiceList holds a list of services.
type ServiceList struct {
TypeMeta `json:",inline"`
@ -487,6 +498,9 @@ type Service struct {
// ProxyPort is assigned by the master. If specified by the user it will be ignored.
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"`
}
// Endpoints is a collection of endpoints that implement the actual service, for example:

View File

@ -352,6 +352,9 @@ func init() {
out.ContainerPort = in.Spec.ContainerPort
out.PortalIP = in.Spec.PortalIP
out.ProxyPort = in.Spec.ProxyPort
if err := s.Convert(&in.Spec.SessionAffinity, &out.SessionAffinity, 0); err != nil {
return err
}
return nil
},
@ -376,6 +379,9 @@ func init() {
out.Spec.ContainerPort = in.ContainerPort
out.Spec.PortalIP = in.PortalIP
out.Spec.ProxyPort = in.ProxyPort
if err := s.Convert(&in.SessionAffinity, &out.Spec.SessionAffinity, 0); err != nil {
return err
}
return nil
},

View File

@ -413,6 +413,17 @@ type PodTemplate struct {
Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize the pods created from the template; must match the selector of the replication controller to which the template belongs; may match selectors of services"`
}
// Session Affinity Type string
type AffinityType string
const (
// AffinityTypeClientIP is the Client IP based.
AffinityTypeClientIP AffinityType = "ClientIP"
// AffinityTypeNone - no session affinity.
AffinityTypeNone AffinityType = "None"
)
// ServiceList holds a list of services.
type ServiceList struct {
TypeMeta `json:",inline"`
@ -452,6 +463,9 @@ type Service struct {
// ProxyPort is assigned by the master. If specified by the user it will be ignored.
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"`
}
// Endpoints is a collection of endpoints that implement the actual service, for example:

View File

@ -604,6 +604,17 @@ type ReplicationControllerList struct {
Items []ReplicationController `json:"items"`
}
// Session Affinity Type string
type AffinityType string
const (
// AffinityTypeClientIP is the Client IP based.
AffinityTypeClientIP AffinityType = "ClientIP"
// AffinityTypeNone - no session affinity.
AffinityTypeNone AffinityType = "None"
)
// ServiceStatus represents the current status of a service
type ServiceStatus struct{}
@ -635,6 +646,9 @@ type ServiceSpec struct {
// ContainerPort is the name of the port on the container to direct traffic to.
// Optional, if unspecified use the first port on the container.
ContainerPort util.IntOrString `json:"containerPort,omitempty"`
// Optional: Supports "ClientIP" and "None". Used to maintain session affinity.
SessionAffinity *AffinityType `json:"sessionAffinity,omitempty"`
}
// Service is a named abstraction of software service (for example, mysql) consisting of local port

View File

@ -414,6 +414,8 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList {
return allErrs
}
var supportedSessionAffinityType = util.NewStringSet(string(api.AffinityTypeClientIP), string(api.AffinityTypeNone))
// ValidateService tests if required fields in the service are set.
func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
@ -454,6 +456,12 @@ 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))
}
}
return allErrs
}