Improve in documentation and naming case
This commit is contained in:
parent
a158e5fc5a
commit
0161ae43d9
5 changed files with 25 additions and 24 deletions
|
@ -31,7 +31,7 @@ const (
|
||||||
// If a cookie with this name exists,
|
// If a cookie with this name exists,
|
||||||
// its value is used as an index into the list of available backends.
|
// its value is used as an index into the list of available backends.
|
||||||
annotationAffinityCookieName = "ingress.kubernetes.io/session-cookie-name"
|
annotationAffinityCookieName = "ingress.kubernetes.io/session-cookie-name"
|
||||||
defaultAffinityCookieName = "route"
|
defaultAffinityCookieName = "INGRESSCOOKIE"
|
||||||
// This is the algorithm used by nginx to generate a value for the session cookie, if
|
// This is the algorithm used by nginx to generate a value for the session cookie, if
|
||||||
// one isn't supplied and affintiy is set to "cookie".
|
// one isn't supplied and affintiy is set to "cookie".
|
||||||
annotationAffinityCookieHash = "ingress.kubernetes.io/session-cookie-hash"
|
annotationAffinityCookieHash = "ingress.kubernetes.io/session-cookie-hash"
|
||||||
|
@ -45,24 +45,21 @@ var (
|
||||||
// AffinityConfig describes the per ingress session affinity config
|
// AffinityConfig describes the per ingress session affinity config
|
||||||
type AffinityConfig struct {
|
type AffinityConfig struct {
|
||||||
// The type of affinity that will be used
|
// The type of affinity that will be used
|
||||||
AffinityType string `json:"type"`
|
AffinityType string `json:"type"`
|
||||||
CookieAffinityConfig CookieAffinityConfig `json:"cookieconfig"`
|
CookieConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// CookieAffinityConfig describes the Config of cookie type affinity
|
// CookieConfig describes the Config of cookie type affinity
|
||||||
type CookieAffinityConfig struct {
|
type CookieConfig struct {
|
||||||
// The name of the cookie that will be used in case of cookie affinity type.
|
// The name of the cookie that will be used in case of cookie affinity type.
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
// The hash that will be used to encode the cookie in case of cookie affinity type
|
// The hash that will be used to encode the cookie in case of cookie affinity type
|
||||||
Hash string `json:"hash"`
|
Hash string `json:"hash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type affinity struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// CookieAffinityParse gets the annotation values related to Cookie Affinity
|
// CookieAffinityParse gets the annotation values related to Cookie Affinity
|
||||||
// It also sets default values when no value or incorrect value is found
|
// It also sets default values when no value or incorrect value is found
|
||||||
func CookieAffinityParse(ing *extensions.Ingress) *CookieAffinityConfig {
|
func CookieAffinityParse(ing *extensions.Ingress) *CookieConfig {
|
||||||
|
|
||||||
sn, err := parser.GetStringAnnotation(annotationAffinityCookieName, ing)
|
sn, err := parser.GetStringAnnotation(annotationAffinityCookieName, ing)
|
||||||
|
|
||||||
|
@ -78,7 +75,7 @@ func CookieAffinityParse(ing *extensions.Ingress) *CookieAffinityConfig {
|
||||||
sh = defaultAffinityCookieHash
|
sh = defaultAffinityCookieHash
|
||||||
}
|
}
|
||||||
|
|
||||||
return &CookieAffinityConfig{
|
return &CookieConfig{
|
||||||
Name: sn,
|
Name: sn,
|
||||||
Hash: sh,
|
Hash: sh,
|
||||||
}
|
}
|
||||||
|
@ -89,19 +86,22 @@ func NewParser() parser.IngressAnnotation {
|
||||||
return affinity{}
|
return affinity{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type affinity struct {
|
||||||
|
}
|
||||||
|
|
||||||
// ParseAnnotations parses the annotations contained in the ingress
|
// ParseAnnotations parses the annotations contained in the ingress
|
||||||
// rule used to configure the affinity directives
|
// rule used to configure the affinity directives
|
||||||
func (a affinity) Parse(ing *extensions.Ingress) (interface{}, error) {
|
func (a affinity) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
|
|
||||||
var cookieAffinityConfig *CookieAffinityConfig
|
var cookieAffinityConfig *CookieConfig
|
||||||
cookieAffinityConfig = &CookieAffinityConfig{}
|
cookieAffinityConfig = &CookieConfig{}
|
||||||
|
|
||||||
// Check the type of affinity that will be used
|
// Check the type of affinity that will be used
|
||||||
at, err := parser.GetStringAnnotation(annotationAffinityType, ing)
|
at, err := parser.GetStringAnnotation(annotationAffinityType, ing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
at = ""
|
at = ""
|
||||||
}
|
}
|
||||||
//cookieAffinityConfig = CookieAffinityParse(ing)
|
|
||||||
switch at {
|
switch at {
|
||||||
case "cookie":
|
case "cookie":
|
||||||
cookieAffinityConfig = CookieAffinityParse(ing)
|
cookieAffinityConfig = CookieAffinityParse(ing)
|
||||||
|
@ -111,8 +111,8 @@ func (a affinity) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
return &AffinityConfig{
|
return &AffinityConfig{
|
||||||
AffinityType: at,
|
AffinityType: at,
|
||||||
CookieAffinityConfig: *cookieAffinityConfig,
|
CookieConfig: *cookieAffinityConfig,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func TestIngressAffinityCookieConfig(t *testing.T) {
|
||||||
data := map[string]string{}
|
data := map[string]string{}
|
||||||
data[annotationAffinityType] = "cookie"
|
data[annotationAffinityType] = "cookie"
|
||||||
data[annotationAffinityCookieHash] = "sha123"
|
data[annotationAffinityCookieHash] = "sha123"
|
||||||
data[annotationAffinityCookieName] = "route"
|
data[annotationAffinityCookieName] = "INGRESSCOOKIE"
|
||||||
ing.SetAnnotations(data)
|
ing.SetAnnotations(data)
|
||||||
|
|
||||||
affin, _ := NewParser().Parse(ing)
|
affin, _ := NewParser().Parse(ing)
|
||||||
|
@ -82,7 +82,7 @@ func TestIngressAffinityCookieConfig(t *testing.T) {
|
||||||
t.Errorf("expected md5 as sticky-hash but returned %v", nginxAffinity.CookieAffinityConfig.Hash)
|
t.Errorf("expected md5 as sticky-hash but returned %v", nginxAffinity.CookieAffinityConfig.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nginxAffinity.CookieAffinityConfig.Name != "route" {
|
if nginxAffinity.CookieAffinityConfig.Name != "INGRESSCOOKIE" {
|
||||||
t.Errorf("expected route as sticky-name but returned %v", nginxAffinity.CookieAffinityConfig.Name)
|
t.Errorf("expected route as sticky-name but returned %v", nginxAffinity.CookieAffinityConfig.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ func TestAffinitySession(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{map[string]string{annotationAffinityType: "cookie", annotationAffinityCookieHash: "md5", annotationAffinityCookieName: "route"}, "cookie", "md5", "route"},
|
{map[string]string{annotationAffinityType: "cookie", annotationAffinityCookieHash: "md5", annotationAffinityCookieName: "route"}, "cookie", "md5", "route"},
|
||||||
{map[string]string{annotationAffinityType: "cookie", annotationAffinityCookieHash: "xpto", annotationAffinityCookieName: "route1"}, "cookie", "md5", "route1"},
|
{map[string]string{annotationAffinityType: "cookie", annotationAffinityCookieHash: "xpto", annotationAffinityCookieName: "route1"}, "cookie", "md5", "route1"},
|
||||||
{map[string]string{annotationAffinityType: "cookie", annotationAffinityCookieHash: "", annotationAffinityCookieName: ""}, "cookie", "md5", "route"},
|
{map[string]string{annotationAffinityType: "cookie", annotationAffinityCookieHash: "", annotationAffinityCookieName: ""}, "cookie", "md5", "INGRESSCOOKIE"},
|
||||||
{map[string]string{}, "", "", ""},
|
{map[string]string{}, "", "", ""},
|
||||||
{nil, "", "", ""},
|
{nil, "", "", ""},
|
||||||
}
|
}
|
||||||
|
@ -209,12 +209,12 @@ func TestAffinitySession(t *testing.T) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.CookieAffinityConfig.Hash != foo.hash {
|
if r.CookieConfig.Hash != foo.hash {
|
||||||
t.Errorf("Returned %v but expected %v for Hash", r.CookieAffinityConfig.Hash, foo.hash)
|
t.Errorf("Returned %v but expected %v for Hash", r.CookieConfig.Hash, foo.hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.CookieAffinityConfig.Name != foo.name {
|
if r.CookieConfig.Name != foo.name {
|
||||||
t.Errorf("Returned %v but expected %v for Name", r.CookieAffinityConfig.Name, foo.name)
|
t.Errorf("Returned %v but expected %v for Name", r.CookieConfig.Name, foo.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -743,8 +743,8 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing
|
||||||
if upstreams[name].SessionAffinity.AffinityType == "" {
|
if upstreams[name].SessionAffinity.AffinityType == "" {
|
||||||
upstreams[name].SessionAffinity.AffinityType = affinity.AffinityType
|
upstreams[name].SessionAffinity.AffinityType = affinity.AffinityType
|
||||||
if affinity.AffinityType == "cookie" {
|
if affinity.AffinityType == "cookie" {
|
||||||
upstreams[name].SessionAffinity.CookieSessionAffinity.Name = affinity.CookieAffinityConfig.Name
|
upstreams[name].SessionAffinity.CookieSessionAffinity.Name = affinity.CookieConfig.Name
|
||||||
upstreams[name].SessionAffinity.CookieSessionAffinity.Hash = affinity.CookieAffinityConfig.Hash
|
upstreams[name].SessionAffinity.CookieSessionAffinity.Hash = affinity.CookieConfig.Hash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ Using a deployment with only one replica doesn't set the 'sticky' cookie.
|
||||||
Session stickyness is achieved through 3 annotations on the Ingress, as shown in the [example](sticky-ingress.yaml).
|
Session stickyness is achieved through 3 annotations on the Ingress, as shown in the [example](sticky-ingress.yaml).
|
||||||
|
|
||||||
|Name|Description|Values|
|
|Name|Description|Values|
|
||||||
|
| --- | --- | --- |
|
||||||
|ingress.kubernetes.io/affinity|Sets the affinity type|string (in NGINX only ``cookie`` is possible|
|
|ingress.kubernetes.io/affinity|Sets the affinity type|string (in NGINX only ``cookie`` is possible|
|
||||||
|ingress.kubernetes.io/session-cookie-name|Name of the cookie that will be used|string (default to route)|
|
|ingress.kubernetes.io/session-cookie-name|Name of the cookie that will be used|string (default to route)|
|
||||||
|ingress.kubernetes.io/session-cookie-hash|Type of hash that will be used in cookie value|sha1/md5/index|
|
|ingress.kubernetes.io/session-cookie-hash|Type of hash that will be used in cookie value|sha1/md5/index|
|
||||||
|
|
Loading…
Reference in a new issue