Skip to content

Commit

Permalink
pkg/webhook: bind MCS validation functions
Browse files Browse the repository at this point in the history
In this commit, we bind the validation functions of `MultiClusterIngress`
webhook i.e `validateMCIUpdate` and `validateMCI` functions to `ValidatingAdmission`
struct using pointer receivers.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
  • Loading branch information
mohamedawnallah committed Sep 11, 2024
1 parent 32c2ef7 commit 8cab55c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/webhook/multiclusteringress/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a
if err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
if errs := validateMCIUpdate(oldMci, mci); len(errs) != 0 {
if errs := v.validateMCIUpdate(oldMci, mci); len(errs) != 0 {
klog.Errorf("%v", errs)
return admission.Denied(errs.ToAggregate().Error())
}
} else {
if errs := validateMCI(mci); len(errs) != 0 {
if errs := v.validateMCI(mci); len(errs) != 0 {
klog.Errorf("%v", errs)
return admission.Denied(errs.ToAggregate().Error())
}
}
return admission.Allowed("")
}

func validateMCIUpdate(oldMci, newMci *networkingv1alpha1.MultiClusterIngress) field.ErrorList {
func (v *ValidatingAdmission) validateMCIUpdate(oldMci, newMci *networkingv1alpha1.MultiClusterIngress) field.ErrorList {
allErrs := apimachineryvalidation.ValidateObjectMetaUpdate(&newMci.ObjectMeta, &oldMci.ObjectMeta, field.NewPath("metadata"))
allErrs = append(allErrs, validateMCI(newMci)...)
allErrs = append(allErrs, v.validateMCI(newMci)...)
allErrs = append(allErrs, lifted.ValidateIngressLoadBalancerStatus(&newMci.Status.LoadBalancer, field.NewPath("status", "loadBalancer"))...)
return allErrs
}

func validateMCI(mci *networkingv1alpha1.MultiClusterIngress) field.ErrorList {
func (v *ValidatingAdmission) validateMCI(mci *networkingv1alpha1.MultiClusterIngress) field.ErrorList {
allErrs := apimachineryvalidation.ValidateObjectMeta(&mci.ObjectMeta, true,
apimachineryvalidation.NameIsDNSSubdomain, field.NewPath("metadata"))
opts := lifted.IngressValidationOptions{
Expand Down

0 comments on commit 8cab55c

Please sign in to comment.