annotations: more consistent error handling

This commit is contained in:
Euan Kemp 2017-01-05 00:04:18 -08:00
parent 8b80616e4d
commit 6523372974
2 changed files with 18 additions and 5 deletions

View file

@ -70,8 +70,23 @@ func ParseAnnotations(ing *extensions.Ingress) (*RateLimit, error) {
return &RateLimit{}, parser.ErrMissingAnnotations
}
rps, _ := parser.GetIntAnnotation(limitRPS, ing)
conn, _ := parser.GetIntAnnotation(limitIP, ing)
rpsMissing := false
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 {
return &RateLimit{

View file

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