修改方法调用meta参数

This commit is contained in:
lijinhui 2021-09-08 20:24:40 +08:00
parent 1fac74f30f
commit b0f13f14dc
4 changed files with 27 additions and 27 deletions

View File

@ -21,7 +21,7 @@ package header
import ( import (
"github.com/goodrain/rainbond/gateway/annotations/parser" "github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver" "github.com/goodrain/rainbond/gateway/annotations/resolver"
networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings" "strings"
) )
@ -39,8 +39,8 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return header{r} return header{r}
} }
func (h header) Parse(ing *networkingv1.Ingress) (interface{}, error) { func (h header) Parse(meta *metav1.ObjectMeta) (interface{}, error) {
hr, err := parser.GetStringAnnotation("header", ing) hr, err := parser.GetStringAnnotation("header", meta)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -18,6 +18,7 @@ package proxy
import ( import (
"fmt" "fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"regexp" "regexp"
"strings" "strings"
@ -26,7 +27,6 @@ import (
"github.com/goodrain/rainbond/gateway/controller/config" "github.com/goodrain/rainbond/gateway/controller/config"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/net/http/httpguts" "golang.org/x/net/http/httpguts"
networkingv1 "k8s.io/api/networking/v1"
) )
// Config returns the proxy timeout to use in the upstream server/s // Config returns the proxy timeout to use in the upstream server/s
@ -191,83 +191,83 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// ParseAnnotations parses the annotations contained in the ingress // ParseAnnotations parses the annotations contained in the ingress
// rule used to configure upstream check parameters // rule used to configure upstream check parameters
func (a proxy) Parse(ing *networkingv1.Ingress) (interface{}, error) { func (a proxy) Parse(meta *metav1.ObjectMeta) (interface{}, error) {
defBackend := a.r.GetDefaultBackend() defBackend := a.r.GetDefaultBackend()
config := &Config{} config := &Config{}
var err error var err error
config.ConnectTimeout, err = parser.GetIntAnnotation("proxy-connect-timeout", ing) config.ConnectTimeout, err = parser.GetIntAnnotation("proxy-connect-timeout", meta)
if err != nil { if err != nil {
config.ConnectTimeout = defBackend.ProxyConnectTimeout config.ConnectTimeout = defBackend.ProxyConnectTimeout
} }
config.SendTimeout, err = parser.GetIntAnnotation("proxy-send-timeout", ing) config.SendTimeout, err = parser.GetIntAnnotation("proxy-send-timeout", meta)
if err != nil { if err != nil {
config.SendTimeout = defBackend.ProxySendTimeout config.SendTimeout = defBackend.ProxySendTimeout
} }
config.ReadTimeout, err = parser.GetIntAnnotation("proxy-read-timeout", ing) config.ReadTimeout, err = parser.GetIntAnnotation("proxy-read-timeout", meta)
if err != nil { if err != nil {
config.ReadTimeout = defBackend.ProxyReadTimeout config.ReadTimeout = defBackend.ProxyReadTimeout
} }
config.BuffersNumber, err = parser.GetIntAnnotation("proxy-buffers-number", ing) config.BuffersNumber, err = parser.GetIntAnnotation("proxy-buffers-number", meta)
if err != nil { if err != nil {
config.BuffersNumber = defBackend.ProxyBuffersNumber config.BuffersNumber = defBackend.ProxyBuffersNumber
} }
config.BufferSize, err = parser.GetStringAnnotation("proxy-buffer-size", ing) config.BufferSize, err = parser.GetStringAnnotation("proxy-buffer-size", meta)
if err != nil { if err != nil {
config.BufferSize = defBackend.ProxyBufferSize config.BufferSize = defBackend.ProxyBufferSize
} }
config.CookiePath, err = parser.GetStringAnnotation("proxy-cookie-path", ing) config.CookiePath, err = parser.GetStringAnnotation("proxy-cookie-path", meta)
if err != nil { if err != nil {
config.CookiePath = defBackend.ProxyCookiePath config.CookiePath = defBackend.ProxyCookiePath
} }
config.CookieDomain, err = parser.GetStringAnnotation("proxy-cookie-domain", ing) config.CookieDomain, err = parser.GetStringAnnotation("proxy-cookie-domain", meta)
if err != nil { if err != nil {
config.CookieDomain = defBackend.ProxyCookieDomain config.CookieDomain = defBackend.ProxyCookieDomain
} }
config.BodySize, err = parser.GetIntAnnotation("proxy-body-size", ing) config.BodySize, err = parser.GetIntAnnotation("proxy-body-size", meta)
if err != nil { if err != nil {
config.BodySize = defBackend.ProxyBodySize config.BodySize = defBackend.ProxyBodySize
} }
config.NextUpstream, err = parser.GetStringAnnotation("proxy-next-upstream", ing) config.NextUpstream, err = parser.GetStringAnnotation("proxy-next-upstream", meta)
if err != nil { if err != nil {
config.NextUpstream = defBackend.ProxyNextUpstream config.NextUpstream = defBackend.ProxyNextUpstream
} }
config.NextUpstreamTries, err = parser.GetIntAnnotation("proxy-next-upstream-tries", ing) config.NextUpstreamTries, err = parser.GetIntAnnotation("proxy-next-upstream-tries", meta)
if err != nil { if err != nil {
config.NextUpstreamTries = defBackend.ProxyNextUpstreamTries config.NextUpstreamTries = defBackend.ProxyNextUpstreamTries
} }
config.NextUpstreamTimeout, err = parser.GetIntAnnotation("proxy-next-upstream-timeout", ing) config.NextUpstreamTimeout, err = parser.GetIntAnnotation("proxy-next-upstream-timeout", meta)
if err != nil { if err != nil {
config.NextUpstreamTimeout = defBackend.ProxyNextUpstreamTimeout config.NextUpstreamTimeout = defBackend.ProxyNextUpstreamTimeout
} }
config.RequestBuffering, err = parser.GetStringAnnotation("proxy-request-buffering", ing) config.RequestBuffering, err = parser.GetStringAnnotation("proxy-request-buffering", meta)
if err != nil { if err != nil {
config.RequestBuffering = defBackend.ProxyRequestBuffering config.RequestBuffering = defBackend.ProxyRequestBuffering
} }
config.ProxyRedirectFrom, err = parser.GetStringAnnotation("proxy-redirect-from", ing) config.ProxyRedirectFrom, err = parser.GetStringAnnotation("proxy-redirect-from", meta)
if err != nil { if err != nil {
config.ProxyRedirectFrom = defBackend.ProxyRedirectFrom config.ProxyRedirectFrom = defBackend.ProxyRedirectFrom
} }
config.ProxyRedirectTo, err = parser.GetStringAnnotation("proxy-redirect-to", ing) config.ProxyRedirectTo, err = parser.GetStringAnnotation("proxy-redirect-to", meta)
if err != nil { if err != nil {
config.ProxyRedirectTo = defBackend.ProxyRedirectTo config.ProxyRedirectTo = defBackend.ProxyRedirectTo
} }
config.ProxyBuffering, err = parser.GetStringAnnotation("proxy-buffering", ing) config.ProxyBuffering, err = parser.GetStringAnnotation("proxy-buffering", meta)
if err != nil { if err != nil {
config.ProxyBuffering = defBackend.ProxyBuffering config.ProxyBuffering = defBackend.ProxyBuffering
} }
@ -277,7 +277,7 @@ func (a proxy) Parse(ing *networkingv1.Ingress) (interface{}, error) {
for k, v := range defBackend.ProxySetHeaders { for k, v := range defBackend.ProxySetHeaders {
config.SetHeaders[k] = v config.SetHeaders[k] = v
} }
setHeaders, err := parser.GetStringAnnotationWithPrefix("set-header-", ing) setHeaders, err := parser.GetStringAnnotationWithPrefix("set-header-", meta)
if err != nil && !strings.Contains(err.Error(), "ingress rule without annotations") { if err != nil && !strings.Contains(err.Error(), "ingress rule without annotations") {
logrus.Debugf("get header annotation failure %s", err.Error()) logrus.Debugf("get header annotation failure %s", err.Error())
} }

View File

@ -19,7 +19,7 @@ package upstreamhashby
import ( import (
"github.com/goodrain/rainbond/gateway/annotations/parser" "github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver" "github.com/goodrain/rainbond/gateway/annotations/resolver"
networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
type upstreamhashby struct { type upstreamhashby struct {
@ -34,6 +34,6 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// Parse parses the annotations contained in the ingress rule // Parse parses the annotations contained in the ingress rule
// used to indicate if the location/s contains a fragment of // used to indicate if the location/s contains a fragment of
// configuration to be included inside the paths of the rules // configuration to be included inside the paths of the rules
func (a upstreamhashby) Parse(ing *networkingv1.Ingress) (interface{}, error) { func (a upstreamhashby) Parse(meta *metav1.ObjectMeta ) (interface{}, error) {
return parser.GetStringAnnotation("upstream-hash-by", ing) return parser.GetStringAnnotation("upstream-hash-by", meta)
} }

View File

@ -22,7 +22,7 @@ import (
"github.com/goodrain/rainbond/gateway/annotations/parser" "github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver" "github.com/goodrain/rainbond/gateway/annotations/resolver"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strconv" "strconv"
) )
@ -40,8 +40,8 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return weight{r} return weight{r}
} }
func (c weight) Parse(ing *networkingv1.Ingress) (interface{}, error) { func (c weight) Parse(meta *metav1.ObjectMeta) (interface{}, error) {
wstr, err := parser.GetStringAnnotation("weight", ing) wstr, err := parser.GetStringAnnotation("weight", meta)
var w int var w int
if err != nil || wstr == "" { if err != nil || wstr == "" {
w = 1 w = 1