Skip to content

Commit

Permalink
Use pointer receivers and remove default variable for ingress not nee…
Browse files Browse the repository at this point in the history
…ded for backward comptiability

Signed-off-by: Mustafa Abdelrahman <[email protected]>
  • Loading branch information
MustafaSaber committed Aug 8, 2023
1 parent 6577f97 commit ecf9af6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
6 changes: 3 additions & 3 deletions cmd/webhook/admission/ingressadmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/zalando/skipper/dataclients/kubernetes/definitions"
)

type IngressAdmitter struct {
}
type IngressAdmitter struct{}

func (IngressAdmitter) name() string {
return "ingress"
Expand All @@ -30,7 +29,8 @@ func (IngressAdmitter) admit(req *admissionRequest) (*admissionResponse, error)
}, nil
}

err = definitions.ValidateIngressV1(&ingressItem)
ingressValidatore := definitions.IngressV1Validator{}
err = ingressValidatore.Validate(&ingressItem)
if err != nil {
emsg := fmt.Sprintf("Ingress validation failed: %v", err)
log.Error(emsg)
Expand Down
33 changes: 7 additions & 26 deletions dataclients/kubernetes/definitions/ingressvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,17 @@ const (

type IngressV1Validator struct{}

var defaultIngressV1Validator = IngressV1Validator{}

func ValidateIngressV1(item *IngressV1Item) error {
return defaultIngressV1Validator.validate(item)
}

func ValidateIngressesV1(ingressList IngressV1List) error {
var errs []error
for _, i := range ingressList.Items {
err := ValidateIngressV1(i)
if err != nil {
name := i.Metadata.Name
namespace := i.Metadata.Namespace
errs = append(errs, fmt.Errorf("%s/%s: %w", name, namespace, err))
}
}
return errorsJoin(errs...)
}

func (IngressV1Validator) validate(item *IngressV1Item) error {
func (igv *IngressV1Validator) Validate(item *IngressV1Item) error {
var errs []error

errs = append(errs, defaultIngressV1Validator.validateFilterAnnotation(item.Metadata.Annotations))
errs = append(errs, defaultIngressV1Validator.validatePredicateAnnotation(item.Metadata.Annotations))
errs = append(errs, defaultIngressV1Validator.validateRoutesAnnotation(item.Metadata.Annotations))
errs = append(errs, igv.validateFilterAnnotation(item.Metadata.Annotations))
errs = append(errs, igv.validatePredicateAnnotation(item.Metadata.Annotations))
errs = append(errs, igv.validateRoutesAnnotation(item.Metadata.Annotations))

return errorsJoin(errs...)
}

func (IngressV1Validator) validateFilterAnnotation(annotations map[string]string) error {
func (igv *IngressV1Validator) validateFilterAnnotation(annotations map[string]string) error {
if filters, ok := annotations[skipperfilterAnnotationKey]; ok {
_, err := eskip.ParseFilters(filters)
if err != nil {
Expand All @@ -54,7 +35,7 @@ func (IngressV1Validator) validateFilterAnnotation(annotations map[string]string
return nil
}

func (IngressV1Validator) validatePredicateAnnotation(annotations map[string]string) error {
func (igv *IngressV1Validator) validatePredicateAnnotation(annotations map[string]string) error {
if predicates, ok := annotations[skipperpredicateAnnotationKey]; ok {
_, err := eskip.ParsePredicates(predicates)
if err != nil {
Expand All @@ -65,7 +46,7 @@ func (IngressV1Validator) validatePredicateAnnotation(annotations map[string]str
return nil
}

func (IngressV1Validator) validateRoutesAnnotation(annotations map[string]string) error {
func (igv *IngressV1Validator) validateRoutesAnnotation(annotations map[string]string) error {
if routes, ok := annotations[skipperRoutesAnnotationKey]; ok {
_, err := eskip.Parse(routes)
if err != nil {
Expand Down

0 comments on commit ecf9af6

Please sign in to comment.