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

return Forbidden is appropriate #1826

Merged
merged 2 commits into from
Dec 7, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (webhook *NodePoolHandler) ValidateUpdate(ctx context.Context, oldObj, newO
}

if allErrs := validateNodePoolSpecUpdate(&newNp.Spec, &oldNp.Spec); len(allErrs) > 0 {
return apierrors.NewInvalid(appsv1beta1.GroupVersion.WithKind("NodePool").GroupKind(), newNp.Name, allErrs)
return apierrors.NewForbidden(appsv1beta1.GroupVersion.WithResource("nodepools").GroupResource(), newNp.Name, allErrs[0])
}

return nil
Expand All @@ -71,7 +71,7 @@ func (webhook *NodePoolHandler) ValidateDelete(_ context.Context, obj runtime.Ob
return apierrors.NewBadRequest(fmt.Sprintf("expected a NodePool but got a %T", obj))
}
if allErrs := validateNodePoolDeletion(webhook.Client, np); len(allErrs) > 0 {
return apierrors.NewInvalid(appsv1beta1.GroupVersion.WithKind("NodePool").GroupKind(), np.Name, allErrs)
return apierrors.NewForbidden(appsv1beta1.GroupVersion.WithResource("nodepools").GroupResource(), np.Name, allErrs[0])
}

return nil
Expand Down Expand Up @@ -121,12 +121,12 @@ func validateNodePoolSpecUpdate(spec, oldSpec *appsv1beta1.NodePoolSpec) field.E

if spec.Type != oldSpec.Type {
return field.ErrorList([]*field.Error{
field.Invalid(field.NewPath("spec").Child("type"), spec.Type, "pool type can't be changed")})
field.Forbidden(field.NewPath("spec").Child("type"), "pool type can't be changed")})
}

if spec.HostNetwork != oldSpec.HostNetwork {
return field.ErrorList([]*field.Error{
field.Invalid(field.NewPath("spec").Child("hostNetwork"), spec.HostNetwork, "pool hostNetwork can't be changed"),
field.Forbidden(field.NewPath("spec").Child("hostNetwork"), "pool hostNetwork can't be changed"),
})
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestValidateUpdate(t *testing.T) {
Type: "invalid type",
},
},
errcode: http.StatusUnprocessableEntity,
errcode: http.StatusForbidden,
},
"type is changed": {
oldPool: &appsv1beta1.NodePool{
Expand All @@ -144,7 +144,7 @@ func TestValidateUpdate(t *testing.T) {
Type: appsv1beta1.Cloud,
},
},
errcode: http.StatusUnprocessableEntity,
errcode: http.StatusForbidden,
},
"host network is changed": {
oldPool: &appsv1beta1.NodePool{
Expand All @@ -159,7 +159,7 @@ func TestValidateUpdate(t *testing.T) {
HostNetwork: true,
},
},
errcode: http.StatusUnprocessableEntity,
errcode: http.StatusForbidden,
},
}

Expand Down Expand Up @@ -258,7 +258,7 @@ func TestValidateDelete(t *testing.T) {
Name: "hangzhou",
},
},
errcode: http.StatusUnprocessableEntity,
errcode: http.StatusForbidden,
},
"it is not a nodepool": {
pool: &corev1.Node{},
Expand Down
Loading