add header-value annotation
add new annotation (header-value) parse it and propogate to lua script alter balancer rule to include it into the canary routing logic add e2e test to validate fallback for canary-by-header-value add description of canary-by-header-value to documentation
This commit is contained in:
parent
e7e8d1a0f2
commit
de2a1ece6d
7 changed files with 155 additions and 13 deletions
|
|
@ -30,10 +30,11 @@ type canary struct {
|
|||
|
||||
// Config returns the configuration rules for setting up the Canary
|
||||
type Config struct {
|
||||
Enabled bool
|
||||
Weight int
|
||||
Header string
|
||||
Cookie string
|
||||
Enabled bool
|
||||
Weight int
|
||||
Header string
|
||||
HeaderValue string
|
||||
Cookie string
|
||||
}
|
||||
|
||||
// NewParser parses the ingress for canary related annotations
|
||||
|
|
@ -62,12 +63,17 @@ func (c canary) Parse(ing *extensions.Ingress) (interface{}, error) {
|
|||
config.Header = ""
|
||||
}
|
||||
|
||||
config.HeaderValue, err = parser.GetStringAnnotation("canary-by-header-value", ing)
|
||||
if err != nil {
|
||||
config.HeaderValue = ""
|
||||
}
|
||||
|
||||
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.Cookie) > 0) {
|
||||
if !config.Enabled && (config.Weight > 0 || len(config.Header) > 0 || len(config.HeaderValue) > 0 || len(config.Cookie) > 0) {
|
||||
return nil, errors.NewInvalidAnnotationConfiguration("canary", "configured but not enabled")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -690,9 +690,10 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
if anns.Canary.Enabled {
|
||||
upstreams[defBackend].NoServer = true
|
||||
upstreams[defBackend].TrafficShapingPolicy = ingress.TrafficShapingPolicy{
|
||||
Weight: anns.Canary.Weight,
|
||||
Header: anns.Canary.Header,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
Weight: anns.Canary.Weight,
|
||||
Header: anns.Canary.Header,
|
||||
HeaderValue: anns.Canary.HeaderValue,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -757,9 +758,10 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
if anns.Canary.Enabled {
|
||||
upstreams[name].NoServer = true
|
||||
upstreams[name].TrafficShapingPolicy = ingress.TrafficShapingPolicy{
|
||||
Weight: anns.Canary.Weight,
|
||||
Header: anns.Canary.Header,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
Weight: anns.Canary.Weight,
|
||||
Header: anns.Canary.Header,
|
||||
HeaderValue: anns.Canary.HeaderValue,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,6 +118,8 @@ type TrafficShapingPolicy struct {
|
|||
Weight int `json:"weight"`
|
||||
// Header on which to redirect requests to this backend
|
||||
Header string `json:"header"`
|
||||
// HeaderValue on which to redirect requests to this backend
|
||||
HeaderValue string `json:"headerValue"`
|
||||
// Cookie on which to redirect requests to this backend
|
||||
Cookie string `json:"cookie"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,6 +293,9 @@ func (tsp1 TrafficShapingPolicy) Equal(tsp2 TrafficShapingPolicy) bool {
|
|||
if tsp1.Header != tsp2.Header {
|
||||
return false
|
||||
}
|
||||
if tsp1.HeaderValue != tsp2.HeaderValue {
|
||||
return false
|
||||
}
|
||||
if tsp1.Cookie != tsp2.Cookie {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue