Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 400(StatusBadRequest) http code when the validation failed #3974

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/webhook/clusteroverridepolicy/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a

if errs := validation.ValidateOverrideSpec(&policy.Spec); len(errs) != 0 {
klog.Error(errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}

return admission.Allowed("")
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/clusterpropagationpolicy/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a
if policy.Spec.SchedulerName != oldPolicy.Spec.SchedulerName {
err = fmt.Errorf("the schedulerName should not be updated")
klog.Error(err)
return admission.Denied(err.Error())
return admission.Errored(http.StatusBadRequest, err)
}
}

errs := validation.ValidatePropagationSpec(policy.Spec)
if len(errs) != 0 {
klog.Error(errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
return admission.Allowed("")
}
2 changes: 1 addition & 1 deletion pkg/webhook/configuration/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a

if len(allErrors) != 0 {
klog.Error(allErrors.ToAggregate())
return admission.Denied(allErrors.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, allErrors.ToAggregate())
}

return admission.Allowed("")
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/cronfederatedhpa/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a
errs = append(errs, validateCronFederatedHPASpec(&cronFHPA.Spec, field.NewPath("spec"))...)

if len(errs) != 0 {
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
return admission.Allowed("")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/federatedhpa/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a

if errs := lifted.ValidateFederatedHPA(fhpa); len(errs) != 0 {
klog.Errorf("%v", errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}

return admission.Allowed("")
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/federatedresourcequota/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a

if errs := validateFederatedResourceQuota(quota); len(errs) != 0 {
klog.Errorf("%v", errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}

return admission.Allowed("")
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/multiclusteringress/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a
}
if errs := validateMCIUpdate(oldMci, mci); len(errs) != 0 {
klog.Errorf("%v", errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
} else {
if errs := validateMCI(mci); len(errs) != 0 {
klog.Errorf("%v", errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
}
return admission.Allowed("")
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/multiclusterservice/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func (v *ValidatingAdmission) Handle(ctx context.Context, req admission.Request)
}
if errs := v.validateMCSUpdate(oldMcs, mcs); len(errs) != 0 {
klog.Errorf("Validating MultiClusterServiceUpdate failed: %v", errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
} else {
if errs := v.validateMCS(mcs); len(errs) != 0 {
klog.Errorf("Validating MultiClusterService failed: %v", errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
}
return admission.Allowed("")
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/overridepolicy/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a

if errs := validation.ValidateOverrideSpec(&policy.Spec); len(errs) != 0 {
klog.Error(errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}

return admission.Allowed("")
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/propagationpolicy/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (v *ValidatingAdmission) Handle(_ context.Context, req admission.Request) a
if policy.Spec.SchedulerName != oldPolicy.Spec.SchedulerName {
err = fmt.Errorf("the schedulerName should not be updated")
klog.Error(err)
return admission.Denied(err.Error())
return admission.Errored(http.StatusBadRequest, err)
}
}

errs := validation.ValidatePropagationSpec(policy.Spec)
if len(errs) != 0 {
klog.Error(errs)
return admission.Denied(errs.ToAggregate().Error())
return admission.Errored(http.StatusBadRequest, errs.ToAggregate())
}
return admission.Allowed("")
}
2 changes: 1 addition & 1 deletion pkg/webhook/resourceinterpretercustomization/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (v *ValidatingAdmission) Handle(ctx context.Context, req admission.Request)
return admission.Errored(http.StatusInternalServerError, err)
}
if err = validateResourceInterpreterCustomizations(configuration, configs); err != nil {
return admission.Denied(err.Error())
return admission.Errored(http.StatusBadRequest, err)
}
return admission.Allowed("")
}
Loading