mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 04:37:31 +08:00
feat: add more precedence rules for route matching (#214)
Signed-off-by: charlie <qianglin98@qq.com>
This commit is contained in:
@@ -26,9 +26,9 @@ const (
|
||||
exact = "exact"
|
||||
regex = "regex"
|
||||
prefix = "prefix"
|
||||
matchMethod = "match-method"
|
||||
matchQuery = "match-query"
|
||||
matchHeader = "match-header"
|
||||
MatchMethod = "match-method"
|
||||
MatchQuery = "match-query"
|
||||
MatchHeader = "match-header"
|
||||
sep = " "
|
||||
)
|
||||
|
||||
@@ -52,11 +52,11 @@ func (m match) Parse(annotations Annotations, config *Ingress, _ *GlobalContext)
|
||||
IngressLog.Errorf("parse methods error %v within ingress %s/%s", err, config.Namespace, config.Name)
|
||||
}
|
||||
|
||||
if config.Match.Headers, err = m.matchByHeaderOrQueryParma(annotations, matchHeader, config.Match.Headers); err != nil {
|
||||
if config.Match.Headers, err = m.matchByHeaderOrQueryParma(annotations, MatchHeader, config.Match.Headers); err != nil {
|
||||
IngressLog.Errorf("parse headers error %v within ingress %s/%s", err, config.Namespace, config.Name)
|
||||
}
|
||||
|
||||
if config.Match.QueryParams, err = m.matchByHeaderOrQueryParma(annotations, matchQuery, config.Match.QueryParams); err != nil {
|
||||
if config.Match.QueryParams, err = m.matchByHeaderOrQueryParma(annotations, MatchQuery, config.Match.QueryParams); err != nil {
|
||||
IngressLog.Errorf("parse query params error %v within ingress %s/%s", err, config.Namespace, config.Name)
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ func (m match) ApplyRoute(route *networking.HTTPRoute, ingressCfg *Ingress) {
|
||||
}
|
||||
|
||||
func (m match) matchByMethod(annotations Annotations, ingress *Ingress) error {
|
||||
if !annotations.HasHigress(matchMethod) {
|
||||
if !annotations.HasHigress(MatchMethod) {
|
||||
return nil
|
||||
}
|
||||
|
||||
config := ingress.Match
|
||||
str, err := annotations.ParseStringForHigress(matchMethod)
|
||||
str, err := annotations.ParseStringForHigress(MatchMethod)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (m match) matchByMethod(annotations Annotations, ingress *Ingress) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// matchByHeader to parse annotations to find matchHeader config
|
||||
// matchByHeader to parse annotations to find MatchHeader config
|
||||
func (m match) matchByHeaderOrQueryParma(annotations Annotations, key string, mmap map[string]map[string]string) (map[string]map[string]string, error) {
|
||||
for k, v := range annotations {
|
||||
if idx := strings.Index(k, key); idx != -1 {
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestMatch_ParseMethods(t *testing.T) {
|
||||
},
|
||||
{
|
||||
input: Annotations{
|
||||
buildHigressAnnotationKey(matchMethod): "PUT POST PATCH",
|
||||
buildHigressAnnotationKey(MatchMethod): "PUT POST PATCH",
|
||||
},
|
||||
expect: &MatchConfig{
|
||||
Methods: []string{"PUT", "POST", "PATCH"},
|
||||
@@ -41,7 +41,7 @@ func TestMatch_ParseMethods(t *testing.T) {
|
||||
},
|
||||
{
|
||||
input: Annotations{
|
||||
buildHigressAnnotationKey(matchMethod): "PUT PUT",
|
||||
buildHigressAnnotationKey(MatchMethod): "PUT PUT",
|
||||
},
|
||||
expect: &MatchConfig{
|
||||
Methods: []string{"PUT"},
|
||||
@@ -49,7 +49,7 @@ func TestMatch_ParseMethods(t *testing.T) {
|
||||
},
|
||||
{
|
||||
input: Annotations{
|
||||
buildHigressAnnotationKey(matchMethod): "put post patch",
|
||||
buildHigressAnnotationKey(MatchMethod): "put post patch",
|
||||
},
|
||||
expect: &MatchConfig{
|
||||
Methods: []string{"PUT", "POST", "PATCH"},
|
||||
@@ -57,7 +57,7 @@ func TestMatch_ParseMethods(t *testing.T) {
|
||||
},
|
||||
{
|
||||
input: Annotations{
|
||||
buildHigressAnnotationKey(matchMethod): "geet",
|
||||
buildHigressAnnotationKey(MatchMethod): "geet",
|
||||
},
|
||||
expect: &MatchConfig{},
|
||||
},
|
||||
@@ -116,7 +116,7 @@ func TestMatch_ParseHeaders(t *testing.T) {
|
||||
|
||||
for _, tt := range testCases {
|
||||
t.Run("", func(t *testing.T) {
|
||||
key := buildHigressAnnotationKey(tt.typ + "-" + matchHeader + "-" + tt.key)
|
||||
key := buildHigressAnnotationKey(tt.typ + "-" + MatchHeader + "-" + tt.key)
|
||||
input := Annotations{key: tt.value}
|
||||
config := &Ingress{}
|
||||
_ = parser.Parse(input, config, nil)
|
||||
@@ -169,7 +169,7 @@ func TestMatch_ParseQueryParams(t *testing.T) {
|
||||
|
||||
for _, tt := range testCases {
|
||||
t.Run("", func(t *testing.T) {
|
||||
key := buildHigressAnnotationKey(tt.typ + "-" + matchQuery + "-" + tt.key)
|
||||
key := buildHigressAnnotationKey(tt.typ + "-" + MatchQuery + "-" + tt.key)
|
||||
input := Annotations{key: tt.value}
|
||||
config := &Ingress{}
|
||||
_ = parser.Parse(input, config, nil)
|
||||
|
||||
Reference in New Issue
Block a user