Adds support for configuring stickness per Ingress
This commit is contained in:
parent
79e186cb77
commit
6809319318
7 changed files with 112 additions and 15 deletions
|
|
@ -19,10 +19,11 @@ package stickysession
|
|||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
|
||||
"k8s.io/ingress/core/pkg/ingress/annotations/parser"
|
||||
ing_errors "k8s.io/ingress/core/pkg/ingress/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -59,28 +60,28 @@ func NewParser() parser.IngressAnnotation {
|
|||
// rule used to configure the sticky directives
|
||||
func (a sticky) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||
// Check if the sticky is enabled
|
||||
se, _ := parser.GetBoolAnnotation(stickyEnabled, ing)
|
||||
se, err := parser.GetBoolAnnotation(stickyEnabled, ing)
|
||||
if err != nil {
|
||||
se = false
|
||||
}
|
||||
|
||||
glog.V(3).Infof("Ingress %v: Setting stickness to %v", ing.Name, se)
|
||||
|
||||
// Get the Sticky Cookie Name
|
||||
sn, _ := parser.GetStringAnnotation(stickyName, ing)
|
||||
sn, err := parser.GetStringAnnotation(stickyName, ing)
|
||||
|
||||
if sn == "" {
|
||||
if err != nil || sn == "" {
|
||||
glog.V(3).Infof("Ingress %v: No value found in annotation %v. Using the default %v", ing.Name, stickyName, defaultStickyName)
|
||||
sn = defaultStickyName
|
||||
}
|
||||
|
||||
sh, _ := parser.GetStringAnnotation(stickyHash, ing)
|
||||
sh, err := parser.GetStringAnnotation(stickyHash, ing)
|
||||
|
||||
if sh == "" {
|
||||
if err != nil || !stickyHashRegex.MatchString(sh) {
|
||||
glog.V(3).Infof("Invalid or no annotation value found in Ingress %v: %v: %v. Setting it to default %v", ing.Name, stickyHash, sh, defaultStickyHash)
|
||||
sh = defaultStickyHash
|
||||
}
|
||||
|
||||
if !stickyHashRegex.MatchString(sh) {
|
||||
return &StickyConfig{
|
||||
Name: "",
|
||||
Enabled: false,
|
||||
Hash: "",
|
||||
}, ing_errors.NewInvalidAnnotationContent(stickyHash, sh)
|
||||
|
||||
return &StickyConfig{
|
||||
Name: sn,
|
||||
Enabled: se,
|
||||
|
|
|
|||
|
|
@ -196,6 +196,8 @@ func TestStickySession(t *testing.T) {
|
|||
{map[string]string{annotationStickyEnabled: "true", annotationStickyHash: "md5", annotationStickyName: "route"}, true, "md5", "route"},
|
||||
{map[string]string{annotationStickyEnabled: "true", annotationStickyHash: "", annotationStickyName: "xpto"}, true, "md5", "xpto"},
|
||||
{map[string]string{annotationStickyEnabled: "true", annotationStickyHash: "", annotationStickyName: ""}, true, "md5", "route"},
|
||||
{map[string]string{}, false, "md5", "route"},
|
||||
{nil, false, "md5", "route"},
|
||||
}
|
||||
|
||||
for _, foo := range fooAnns {
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ type Backend struct {
|
|||
// Endpoints contains the list of endpoints currently running
|
||||
Endpoints []Endpoint `json:"endpoints"`
|
||||
// StickySession contains the StickyConfig object with stickness configuration
|
||||
StickySession *stickysession.StickyConfig `json:"stickysession"`
|
||||
StickySession stickysession.StickyConfig `json:"stickysession,omitempty"`
|
||||
}
|
||||
|
||||
// Endpoint describes a kubernetes endpoint in an backend
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue