annotations: more consistent error handling
This commit is contained in:
parent
8b80616e4d
commit
6523372974
2 changed files with 18 additions and 5 deletions
|
@ -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{
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue