From ecf9af65e38a7d24b7e59ef2a3fdfff9679f82d3 Mon Sep 17 00:00:00 2001 From: Mustafa Abdelrahman Date: Tue, 8 Aug 2023 11:49:32 +0200 Subject: [PATCH] Use pointer receivers and remove default variable for ingress not needed for backward comptiability Signed-off-by: Mustafa Abdelrahman --- cmd/webhook/admission/ingressadmission.go | 6 ++-- .../definitions/ingressvalidator.go | 33 ++++--------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/cmd/webhook/admission/ingressadmission.go b/cmd/webhook/admission/ingressadmission.go index f25c3c4ec5..a67145a9f9 100644 --- a/cmd/webhook/admission/ingressadmission.go +++ b/cmd/webhook/admission/ingressadmission.go @@ -8,8 +8,7 @@ import ( "github.com/zalando/skipper/dataclients/kubernetes/definitions" ) -type IngressAdmitter struct { -} +type IngressAdmitter struct{} func (IngressAdmitter) name() string { return "ingress" @@ -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) diff --git a/dataclients/kubernetes/definitions/ingressvalidator.go b/dataclients/kubernetes/definitions/ingressvalidator.go index 65c00d2357..8c74bf7f8f 100644 --- a/dataclients/kubernetes/definitions/ingressvalidator.go +++ b/dataclients/kubernetes/definitions/ingressvalidator.go @@ -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 { @@ -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 { @@ -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 {