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}}
|
{{range $name, $upstream := $backends}}
|
||||||
upstream {{$upstream.Name}} {
|
upstream {{$upstream.Name}} {
|
||||||
{{ if $cfg.EnableStickySessions }}
|
{{ if $upstream.StickySession.Enabled }}
|
||||||
sticky hash=sha1 httponly;
|
sticky hash={{$upstream.StickySession.Hash}} route={{$upstream.StickySession.Hash}} httponly;
|
||||||
{{ else }}
|
{{ else }}
|
||||||
least_conn;
|
least_conn;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -59,34 +59,27 @@ func NewParser() parser.IngressAnnotation {
|
||||||
// rule used to configure the sticky directives
|
// rule used to configure the sticky directives
|
||||||
func (a sticky) Parse(ing *extensions.Ingress) (interface{}, error) {
|
func (a sticky) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
// Check if the sticky is enabled
|
// Check if the sticky is enabled
|
||||||
se, err := parser.GetBoolAnnotation(stickyEnabled, ing)
|
se, _ := parser.GetBoolAnnotation(stickyEnabled, ing)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the Sticky Cookie Name
|
// Get the Sticky Cookie Name
|
||||||
sn, err := parser.GetStringAnnotation(stickyName, ing)
|
sn, _ := parser.GetStringAnnotation(stickyName, ing)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if sn == "" {
|
if sn == "" {
|
||||||
sn = defaultStickyName
|
sn = defaultStickyName
|
||||||
}
|
}
|
||||||
|
|
||||||
sh, err := parser.GetStringAnnotation(stickyHash, ing)
|
sh, _ := parser.GetStringAnnotation(stickyHash, ing)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if sh == "" {
|
if sh == "" {
|
||||||
sh = defaultStickyHash
|
sh = defaultStickyHash
|
||||||
}
|
}
|
||||||
|
|
||||||
if !stickyHashRegex.MatchString(sh) {
|
if !stickyHashRegex.MatchString(sh) {
|
||||||
return nil, ing_errors.NewInvalidAnnotationContent(stickyHash, sh)
|
return &StickyConfig{
|
||||||
}
|
Name: "",
|
||||||
|
Enabled: false,
|
||||||
|
Hash: "",
|
||||||
|
}, ing_errors.NewInvalidAnnotationContent(stickyHash, sh)
|
||||||
|
|
||||||
return &StickyConfig{
|
return &StickyConfig{
|
||||||
Name: sn,
|
Name: sn,
|
||||||
|
|
|
@ -59,7 +59,7 @@ func buildIngress() *extensions.Ingress {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIngressHealthCheck(t *testing.T) {
|
func TestIngressStickySession(t *testing.T) {
|
||||||
ing := buildIngress()
|
ing := buildIngress()
|
||||||
|
|
||||||
data := map[string]string{}
|
data := map[string]string{}
|
||||||
|
|
Loading…
Reference in a new issue