Skip to content

Commit

Permalink
annotations: more consistent error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
euank committed Jan 5, 2017
1 parent 8b80616 commit 6523372
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 17 additions & 2 deletions core/pkg/ingress/annotations/ratelimit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 1 addition & 3 deletions core/pkg/ingress/annotations/rewrite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6523372

Please sign in to comment.