This commit is contained in:
Euan Kemp 2017-01-12 16:04:08 +00:00 committed by GitHub
commit f79d1f1109
3 changed files with 40 additions and 19 deletions

View file

@ -70,8 +70,23 @@ func ParseAnnotations(ing *extensions.Ingress) (*RateLimit, error) {
return &RateLimit{}, parser.ErrMissingAnnotations return &RateLimit{}, parser.ErrMissingAnnotations
} }
rps, _ := parser.GetIntAnnotation(limitRPS, ing) rpsMissing := false
conn, _ := parser.GetIntAnnotation(limitIP, ing) rps, err := parser.GetIntAnnotation(limitRPS, ing)
if err != nil && err != parser.ErrMissingAnnotations {
return &RateLimit{}, err
}
if err == parser.ErrMissingAnnotations {
rpsMissing = true
}
conn, errip := parser.GetIntAnnotation(limitIP, ing)
if errip != nil && errip != parser.ErrMissingAnnotations {
return &RateLimit{}, errip
}
if rpsMissing && errip == parser.ErrMissingAnnotations {
// Both annotations missing, that's not an 'InvalidRateLimit', return the
// right error
return &RateLimit{}, parser.ErrMissingAnnotations
}
if rps == 0 && conn == 0 { if rps == 0 && conn == 0 {
return &RateLimit{ return &RateLimit{

View file

@ -17,8 +17,6 @@ limitations under the License.
package rewrite package rewrite
import ( import (
"errors"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/ingress/core/pkg/ingress/annotations/parser" "k8s.io/ingress/core/pkg/ingress/annotations/parser"
@ -46,7 +44,7 @@ type Redirect struct {
// rule used to rewrite the defined paths // rule used to rewrite the defined paths
func ParseAnnotations(cfg defaults.Backend, ing *extensions.Ingress) (*Redirect, error) { func ParseAnnotations(cfg defaults.Backend, ing *extensions.Ingress) (*Redirect, error) {
if ing.GetAnnotations() == nil { if ing.GetAnnotations() == nil {
return &Redirect{}, errors.New("no annotations present") return &Redirect{}, parser.ErrMissingAnnotations
} }
sslRe, err := parser.GetBoolAnnotation(sslRedirect, ing) sslRe, err := parser.GetBoolAnnotation(sslRedirect, ing)

View file

@ -45,6 +45,7 @@ import (
"k8s.io/ingress/core/pkg/ingress/annotations/cors" "k8s.io/ingress/core/pkg/ingress/annotations/cors"
"k8s.io/ingress/core/pkg/ingress/annotations/healthcheck" "k8s.io/ingress/core/pkg/ingress/annotations/healthcheck"
"k8s.io/ingress/core/pkg/ingress/annotations/ipwhitelist" "k8s.io/ingress/core/pkg/ingress/annotations/ipwhitelist"
"k8s.io/ingress/core/pkg/ingress/annotations/parser"
"k8s.io/ingress/core/pkg/ingress/annotations/proxy" "k8s.io/ingress/core/pkg/ingress/annotations/proxy"
"k8s.io/ingress/core/pkg/ingress/annotations/ratelimit" "k8s.io/ingress/core/pkg/ingress/annotations/ratelimit"
"k8s.io/ingress/core/pkg/ingress/annotations/rewrite" "k8s.io/ingress/core/pkg/ingress/annotations/rewrite"
@ -558,36 +559,42 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
nginxAuth, err := auth.ParseAnnotations(ing, auth.DefAuthDirectory, ic.getSecret) nginxAuth, err := auth.ParseAnnotations(ing, auth.DefAuthDirectory, ic.getSecret)
glog.V(5).Infof("auth annotation: %v", nginxAuth) glog.V(5).Infof("auth annotation: %v", nginxAuth)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error reading authentication in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error reading authentication in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
rl, err := ratelimit.ParseAnnotations(ing) rl, err := ratelimit.ParseAnnotations(ing)
glog.V(5).Infof("rate limit annotation: %v", rl) glog.V(5).Infof("rate limit annotation: %v", rl)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error reading rate limit annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error reading rate limit annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
locRew, err := rewrite.ParseAnnotations(upsDefaults, ing) locRew, err := rewrite.ParseAnnotations(upsDefaults, ing)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error parsing rewrite annotations for Ingress rule %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error parsing rewrite annotations for Ingress rule %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
wl, err := ipwhitelist.ParseAnnotations(upsDefaults, ing) wl, err := ipwhitelist.ParseAnnotations(upsDefaults, ing)
glog.V(5).Infof("white list annotation: %v", wl) glog.V(5).Infof("white list annotation: %v", wl)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error reading white list annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error reading white list annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
eCORS, err := cors.ParseAnnotations(ing) eCORS, err := cors.ParseAnnotations(ing)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error reading CORS annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error reading CORS annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
ra, err := authreq.ParseAnnotations(ing) ra, err := authreq.ParseAnnotations(ing)
glog.V(5).Infof("auth request annotation: %v", ra) glog.V(5).Infof("auth request annotation: %v", ra)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error reading auth request annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error reading auth request annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
prx := proxy.ParseAnnotations(upsDefaults, ing) prx := proxy.ParseAnnotations(upsDefaults, ing)
@ -595,8 +602,9 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
certAuth, err := authtls.ParseAnnotations(ing, ic.getAuthCertificate) certAuth, err := authtls.ParseAnnotations(ing, ic.getAuthCertificate)
glog.V(5).Infof("auth request annotation: %v", certAuth) glog.V(5).Infof("auth request annotation: %v", certAuth)
if err != nil { if err != nil && err != parser.ErrMissingAnnotations {
glog.V(5).Infof("error reading certificate auth annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err) glog.Errorf("error reading certificate auth annotation in Ingress %v/%v: %v", ing.GetNamespace(), ing.GetName(), err)
continue
} }
for _, rule := range ing.Spec.Rules { for _, rule := range ing.Spec.Rules {