Merge pull request #5114 from whalecold/match
Feat: add header-pattern annotation.
This commit is contained in:
commit
35264d6e8f
7 changed files with 157 additions and 18 deletions
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -738,10 +738,11 @@ 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,
|
||||
HeaderValue: anns.Canary.HeaderValue,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
Weight: anns.Canary.Weight,
|
||||
Header: anns.Canary.Header,
|
||||
HeaderValue: anns.Canary.HeaderValue,
|
||||
HeaderPattern: anns.Canary.HeaderPattern,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -801,10 +802,11 @@ 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,
|
||||
HeaderValue: anns.Canary.HeaderValue,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
Weight: anns.Canary.Weight,
|
||||
Header: anns.Canary.Header,
|
||||
HeaderValue: anns.Canary.HeaderValue,
|
||||
HeaderPattern: anns.Canary.HeaderPattern,
|
||||
Cookie: anns.Canary.Cookie,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ type TrafficShapingPolicy struct {
|
|||
Header string `json:"header"`
|
||||
// HeaderValue on which to redirect requests to this backend
|
||||
HeaderValue string `json:"headerValue"`
|
||||
// HeaderPattern the header value match pattern, support exact, regex.
|
||||
HeaderPattern string `json:"headerPattern"`
|
||||
// Cookie on which to redirect requests to this backend
|
||||
Cookie string `json:"cookie"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,6 +251,9 @@ func (tsp1 TrafficShapingPolicy) Equal(tsp2 TrafficShapingPolicy) bool {
|
|||
if tsp1.HeaderValue != tsp2.HeaderValue {
|
||||
return false
|
||||
}
|
||||
if tsp1.HeaderPattern != tsp2.HeaderPattern {
|
||||
return false
|
||||
}
|
||||
if tsp1.Cookie != tsp2.Cookie {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue