Session Affinity ChangeOnFailure should be boolean

This commit is contained in:
Elvin Efendi 2019-06-06 11:02:51 -04:00
parent c6c6f51006
commit 83f2acbe38
5 changed files with 15 additions and 16 deletions

View file

@ -50,8 +50,7 @@ const (
)
var (
affinityCookieExpiresRegex = regexp.MustCompile(`(^0|-?[1-9]\d*$)`)
affinityCookieChangeOnFailureRegex = regexp.MustCompile(`^(true|false)$`)
affinityCookieExpiresRegex = regexp.MustCompile(`(^0|-?[1-9]\d*$)`)
)
// Config describes the per ingress session affinity config
@ -72,7 +71,7 @@ type Cookie struct {
// The path that a cookie will be set on
Path string `json:"path"`
// Flag that allows cookie regeneration on request failure
ChangeOnFailure string `json:"changeonfailure"`
ChangeOnFailure bool `json:"changeonfailure"`
}
// cookieAffinityParse gets the annotation values related to Cookie Affinity
@ -105,8 +104,8 @@ func (a affinity) cookieAffinityParse(ing *extensions.Ingress) *Cookie {
klog.V(3).Infof("Invalid or no annotation value found in Ingress %v: %v. Ignoring it", ing.Name, annotationAffinityCookieMaxAge)
}
cookie.ChangeOnFailure, err = parser.GetStringAnnotation(annotationAffinityCookieChangeOnFailure, ing)
if err != nil || !affinityCookieChangeOnFailureRegex.MatchString(cookie.ChangeOnFailure) {
cookie.ChangeOnFailure, err = parser.GetBoolAnnotation(annotationAffinityCookieChangeOnFailure, ing)
if err != nil {
klog.V(3).Infof("Invalid or no annotation value found in Ingress %v: %v. Ignoring it", ing.Name, annotationAffinityCookieChangeOnFailure)
}

View file

@ -100,7 +100,7 @@ func TestIngressAffinityCookieConfig(t *testing.T) {
t.Errorf("expected /foo as session-cookie-path but returned %v", nginxAffinity.Cookie.Path)
}
if nginxAffinity.Cookie.ChangeOnFailure != "true" {
if !nginxAffinity.Cookie.ChangeOnFailure {
t.Errorf("expected change of failure parameter set to true but returned %v", nginxAffinity.Cookie.ChangeOnFailure)
}
}

View file

@ -149,7 +149,7 @@ type CookieSessionAffinity struct {
MaxAge string `json:"maxage,omitempty"`
Locations map[string][]string `json:"locations,omitempty"`
Path string `json:"path,omitempty"`
ChangeOnFailure string `json:"changeonfailure"`
ChangeOnFailure bool `json:"change_on_failure,omitempty"`
}
// UpstreamHashByConfig described setting from the upstream-hash-by* annotations.