New sticky session configuration
This commit is contained in:
parent
1dbe65ecb6
commit
79e186cb77
3 changed files with 11 additions and 18 deletions
|
@ -185,8 +185,8 @@ http {
|
|||
|
||||
{{range $name, $upstream := $backends}}
|
||||
upstream {{$upstream.Name}} {
|
||||
{{ if $cfg.EnableStickySessions }}
|
||||
sticky hash=sha1 httponly;
|
||||
{{ if $upstream.StickySession.Enabled }}
|
||||
sticky hash={{$upstream.StickySession.Hash}} route={{$upstream.StickySession.Hash}} httponly;
|
||||
{{ else }}
|
||||
least_conn;
|
||||
{{ end }}
|
||||
|
|
|
@ -59,34 +59,27 @@ 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, err := parser.GetBoolAnnotation(stickyEnabled, ing)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
se, _ := parser.GetBoolAnnotation(stickyEnabled, ing)
|
||||
|
||||
// Get the Sticky Cookie Name
|
||||
sn, err := parser.GetStringAnnotation(stickyName, ing)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sn, _ := parser.GetStringAnnotation(stickyName, ing)
|
||||
|
||||
if sn == "" {
|
||||
sn = defaultStickyName
|
||||
}
|
||||
|
||||
sh, err := parser.GetStringAnnotation(stickyHash, ing)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sh, _ := parser.GetStringAnnotation(stickyHash, ing)
|
||||
|
||||
if sh == "" {
|
||||
sh = defaultStickyHash
|
||||
}
|
||||
|
||||
if !stickyHashRegex.MatchString(sh) {
|
||||
return nil, ing_errors.NewInvalidAnnotationContent(stickyHash, sh)
|
||||
}
|
||||
return &StickyConfig{
|
||||
Name: "",
|
||||
Enabled: false,
|
||||
Hash: "",
|
||||
}, ing_errors.NewInvalidAnnotationContent(stickyHash, sh)
|
||||
|
||||
return &StickyConfig{
|
||||
Name: sn,
|
||||
|
|
|
@ -59,7 +59,7 @@ func buildIngress() *extensions.Ingress {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIngressHealthCheck(t *testing.T) {
|
||||
func TestIngressStickySession(t *testing.T) {
|
||||
ing := buildIngress()
|
||||
|
||||
data := map[string]string{}
|
||||
|
|
Loading…
Reference in a new issue