From 79e186cb77f240d352e87938d99d29d87b9e1610 Mon Sep 17 00:00:00 2001 From: Ricardo Pchevuzinske Katz Date: Fri, 10 Feb 2017 01:33:23 -0200 Subject: [PATCH] New sticky session configuration --- .../rootfs/etc/nginx/template/nginx.tmpl | 4 ++-- .../ingress/annotations/stickysession/main.go | 23 +++++++------------ .../annotations/stickysession/main_test.go | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl index d018d4ebb..bb3b04506 100644 --- a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl +++ b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl @@ -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 }} diff --git a/core/pkg/ingress/annotations/stickysession/main.go b/core/pkg/ingress/annotations/stickysession/main.go index be4dd2f0f..ce9609896 100644 --- a/core/pkg/ingress/annotations/stickysession/main.go +++ b/core/pkg/ingress/annotations/stickysession/main.go @@ -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, diff --git a/core/pkg/ingress/annotations/stickysession/main_test.go b/core/pkg/ingress/annotations/stickysession/main_test.go index a8a98f3c4..71384fad1 100644 --- a/core/pkg/ingress/annotations/stickysession/main_test.go +++ b/core/pkg/ingress/annotations/stickysession/main_test.go @@ -59,7 +59,7 @@ func buildIngress() *extensions.Ingress { } } -func TestIngressHealthCheck(t *testing.T) { +func TestIngressStickySession(t *testing.T) { ing := buildIngress() data := map[string]string{}