Change:
// IsNotAcceptable determines if err is an error which indicates that the request failed due to an invalid Accept header // It supports wrapped errors. func IsNotAcceptable(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonNotAcceptable </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonNotAcceptable { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusNotAcceptable { return true } return false </ins> } // IsUnsupportedMediaType determines if err is an error which indicates that the request failed due to an invalid Content-Type header // It supports wrapped errors. func IsUnsupportedMediaType(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonUnsupportedMediaType </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonUnsupportedMediaType { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusUnsupportedMediaType { return true } return false </ins> } // IsMethodNotSupported determines if the err is an error which indicates the provided action could not // be performed because it is not supported by the server. // It supports wrapped errors. func IsMethodNotSupported(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonMethodNotAllowed </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonMethodNotAllowed { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusMethodNotAllowed { return true } return false </ins> } // IsServiceUnavailable is true if the error indicates the underlying service is no longer available. // It supports wrapped errors. func IsServiceUnavailable(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonServiceUnavailable </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonServiceUnavailable { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusServiceUnavailable { return true } return false </ins> } // IsBadRequest determines if err is an error which indicates that the request is invalid. // It supports wrapped errors. func IsBadRequest(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonBadRequest </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonBadRequest { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusBadRequest { return true } return false </ins> } // IsUnauthorized determines if err is an error which indicates that the request is unauthorized and // requires authentication by the user. // It supports wrapped errors. func IsUnauthorized(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonUnauthorized </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonUnauthorized { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusUnauthorized { return true } return false </ins> } // IsForbidden determines if err is an error which indicates that the request is forbidden and cannot // be completed as requested. // It supports wrapped errors. func IsForbidden(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonForbidden </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonForbidden { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusForbidden { return true } return false </ins> } // IsTimeout determines if err is an error which indicates that request times out due to long // processing. // It supports wrapped errors. func IsTimeout(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonTimeout </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonTimeout { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusGatewayTimeout { return true } return false </ins> } // IsServerTimeout determines if err is an error which indicates that the request needs to be retried // by the client. // It supports wrapped errors. func IsServerTimeout(err error) bool { <ins> // do not check the status code, because no https status code exists that can // be scoped to retryable timeouts. </ins> return ReasonForError(err) == metav1.StatusReasonServerTimeout } // IsInternalError determines if err is an error which indicates an internal server error. // It supports wrapped errors. func IsInternalError(err error) bool { <del> return ReasonForError(err) == metav1.StatusReasonInternalError </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonInternalError { return true } if _, ok := knownReasons[reason]; !ok && code == http.StatusInternalServerError { return true } return false </ins> } // IsTooManyRequests determines if err is an error which indicates that there are too many requests // that the server cannot handle. // It supports wrapped errors. func IsTooManyRequests(err error) bool { <del> if ReasonForError(err) == metav1.StatusReasonTooManyRequests { </del> <ins> reason, code := reasonAndCodeForError(err) if reason == metav1.StatusReasonTooManyRequests { </ins> return true } <del> if status := APIStatus(nil); errors.As(err, &status) { return status.Status().Code == http.StatusTooManyRequests </del> <ins> // IsTooManyRequests' checking of code predates the checking of the code in // the other Is* functions. In order to maintain backward compatibility, this // does not check that the reason is unknown. if code == http.StatusTooManyRequests { return true </ins> } return false }

Discussion:
Checked a method error using when the error was caused by a validating webhook that returns a 403 response. In this particular case, the error was generated from a validating webhook implemented with controller-runtime that returns controller-runtime's response. to return true. returned false Many (but not all) of the other family of functions in suffer the same kind of problem. I have changes ready to submit in a PR if we can get agreement that this is a problem and that it should be fixed in the functions that ought to check the of an erorr value that is or wraps an Kubernetes version (use ): 19.3 for the server
/sig api-machinery
are you going to send a PR for this? The issue description looks reasonable. /triage accepted
Thanks, PR is submitted.
/assign