Feat: canary supports using specific match strategy to match header value.

This commit is contained in:
Lisheng Zheng 2020-02-19 12:21:08 +08:00
parent 7d52174b51
commit 0b33650bb8
7 changed files with 157 additions and 18 deletions

View file

@ -30,11 +30,12 @@ type canary struct {
// Config returns the configuration rules for setting up the Canary
type Config struct {
Enabled bool
Weight int
Header string
HeaderValue string
Cookie string
Enabled bool
Weight int
Header string
HeaderValue string
HeaderPattern string
Cookie string
}
// NewParser parses the ingress for canary related annotations
@ -68,12 +69,18 @@ func (c canary) Parse(ing *networking.Ingress) (interface{}, error) {
config.HeaderValue = ""
}
config.HeaderPattern, err = parser.GetStringAnnotation("canary-by-header-pattern", ing)
if err != nil {
config.HeaderPattern = ""
}
config.Cookie, err = parser.GetStringAnnotation("canary-by-cookie", ing)
if err != nil {
config.Cookie = ""
}
if !config.Enabled && (config.Weight > 0 || len(config.Header) > 0 || len(config.HeaderValue) > 0 || len(config.Cookie) > 0) {
if !config.Enabled && (config.Weight > 0 || len(config.Header) > 0 || len(config.HeaderValue) > 0 || len(config.Cookie) > 0 ||
len(config.HeaderPattern) > 0) {
return nil, errors.NewInvalidAnnotationConfiguration("canary", "configured but not enabled")
}