修改方法调用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 (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)
@ -39,8 +39,8 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return header{r}
}
func (h header) Parse(ing *networkingv1.Ingress) (interface{}, error) {
hr, err := parser.GetStringAnnotation("header", ing)
func (h header) Parse(meta *metav1.ObjectMeta) (interface{}, error) {
hr, err := parser.GetStringAnnotation("header", meta)
if err != nil {
return nil, err
}

View File

@ -18,6 +18,7 @@ package proxy
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"regexp"
"strings"
@ -26,7 +27,6 @@ import (
"github.com/goodrain/rainbond/gateway/controller/config"
"github.com/sirupsen/logrus"
"golang.org/x/net/http/httpguts"
networkingv1 "k8s.io/api/networking/v1"
)
// 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
// 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()
config := &Config{}
var err error
config.ConnectTimeout, err = parser.GetIntAnnotation("proxy-connect-timeout", ing)
config.ConnectTimeout, err = parser.GetIntAnnotation("proxy-connect-timeout", meta)
if err != nil {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
config.ProxyRedirectTo = defBackend.ProxyRedirectTo
}
config.ProxyBuffering, err = parser.GetStringAnnotation("proxy-buffering", ing)
config.ProxyBuffering, err = parser.GetStringAnnotation("proxy-buffering", meta)
if err != nil {
config.ProxyBuffering = defBackend.ProxyBuffering
}
@ -277,7 +277,7 @@ func (a proxy) Parse(ing *networkingv1.Ingress) (interface{}, error) {
for k, v := range defBackend.ProxySetHeaders {
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") {
logrus.Debugf("get header annotation failure %s", err.Error())
}

View File

@ -19,7 +19,7 @@ package upstreamhashby
import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type upstreamhashby struct {
@ -34,6 +34,6 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// Parse parses the annotations contained in the ingress rule
// used to indicate if the location/s contains a fragment of
// configuration to be included inside the paths of the rules
func (a upstreamhashby) Parse(ing *networkingv1.Ingress) (interface{}, error) {
return parser.GetStringAnnotation("upstream-hash-by", ing)
func (a upstreamhashby) Parse(meta *metav1.ObjectMeta ) (interface{}, error) {
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/resolver"
"github.com/sirupsen/logrus"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strconv"
)
@ -40,8 +40,8 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return weight{r}
}
func (c weight) Parse(ing *networkingv1.Ingress) (interface{}, error) {
wstr, err := parser.GetStringAnnotation("weight", ing)
func (c weight) Parse(meta *metav1.ObjectMeta) (interface{}, error) {
wstr, err := parser.GetStringAnnotation("weight", meta)
var w int
if err != nil || wstr == "" {
w = 1