vendor: bump k8s to v0.25.4

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-03-14 18:20:37 +01:00
parent 4a73abfd64
commit cfa6b4f7c8
889 changed files with 96934 additions and 11708 deletions

View File

@ -1,20 +1,17 @@
# See the OWNERS docs at https://go.k8s.io/owners
reviewers:
- thockin
- lavalamp
- smarterclayton
- wojtek-t
- deads2k
- brendandburns
- derekwaynecarr
- caesarxuchao
- mikedanese
- liggitt
- saad-ali
- janetkuo
- tallclair
- dims
- hongchaodeng
- krousey
- cjcullen
- thockin
- lavalamp
- smarterclayton
- wojtek-t
- deads2k
- derekwaynecarr
- caesarxuchao
- mikedanese
- liggitt
- saad-ali
- janetkuo
- tallclair
- dims
- cjcullen

View File

@ -44,6 +44,28 @@ type APIStatus interface {
var _ error = &StatusError{}
var knownReasons = map[metav1.StatusReason]struct{}{
// metav1.StatusReasonUnknown : {}
metav1.StatusReasonUnauthorized: {},
metav1.StatusReasonForbidden: {},
metav1.StatusReasonNotFound: {},
metav1.StatusReasonAlreadyExists: {},
metav1.StatusReasonConflict: {},
metav1.StatusReasonGone: {},
metav1.StatusReasonInvalid: {},
metav1.StatusReasonServerTimeout: {},
metav1.StatusReasonTimeout: {},
metav1.StatusReasonTooManyRequests: {},
metav1.StatusReasonBadRequest: {},
metav1.StatusReasonMethodNotAllowed: {},
metav1.StatusReasonNotAcceptable: {},
metav1.StatusReasonRequestEntityTooLarge: {},
metav1.StatusReasonUnsupportedMediaType: {},
metav1.StatusReasonInternalError: {},
metav1.StatusReasonExpired: {},
metav1.StatusReasonServiceUnavailable: {},
}
// Error implements the Error interface.
func (e *StatusError) Error() string {
return e.ErrStatus.Message
@ -65,21 +87,21 @@ func (e *StatusError) DebugError() (string, []interface{}) {
// HasStatusCause returns true if the provided error has a details cause
// with the provided type name.
// It supports wrapped errors and returns false when the error is nil.
func HasStatusCause(err error, name metav1.CauseType) bool {
_, ok := StatusCause(err, name)
return ok
}
// StatusCause returns the named cause from the provided error if it exists and
// the error is of the type APIStatus. Otherwise it returns false.
// the error unwraps to the type APIStatus. Otherwise it returns false.
func StatusCause(err error, name metav1.CauseType) (metav1.StatusCause, bool) {
apierr, ok := err.(APIStatus)
if !ok || apierr == nil || apierr.Status().Details == nil {
return metav1.StatusCause{}, false
}
for _, cause := range apierr.Status().Details.Causes {
if cause.Type == name {
return cause, true
status, ok := err.(APIStatus)
if (ok || errors.As(err, &status)) && status.Status().Details != nil {
for _, cause := range status.Status().Details.Causes {
if cause.Type == name {
return cause, true
}
}
}
return metav1.StatusCause{}, false
@ -148,6 +170,25 @@ func NewAlreadyExists(qualifiedResource schema.GroupResource, name string) *Stat
}}
}
// NewGenerateNameConflict returns an error indicating the server
// was not able to generate a valid name for a resource.
func NewGenerateNameConflict(qualifiedResource schema.GroupResource, name string, retryAfterSeconds int) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusConflict,
Reason: metav1.StatusReasonAlreadyExists,
Details: &metav1.StatusDetails{
Group: qualifiedResource.Group,
Kind: qualifiedResource.Resource,
Name: name,
RetryAfterSeconds: int32(retryAfterSeconds),
},
Message: fmt.Sprintf(
"%s %q already exists, the server was not able to generate a unique name for the object",
qualifiedResource.String(), name),
}}
}
// NewUnauthorized returns an error indicating the client is not authorized to perform the requested
// action.
func NewUnauthorized(reason string) *StatusError {
@ -248,7 +289,7 @@ func NewInvalid(qualifiedKind schema.GroupKind, name string, errs field.ErrorLis
Field: err.Field,
})
}
return &StatusError{metav1.Status{
err := &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusUnprocessableEntity,
Reason: metav1.StatusReasonInvalid,
@ -258,8 +299,14 @@ func NewInvalid(qualifiedKind schema.GroupKind, name string, errs field.ErrorLis
Name: name,
Causes: causes,
},
Message: fmt.Sprintf("%s %q is invalid: %v", qualifiedKind.String(), name, errs.ToAggregate()),
}}
aggregatedErrs := errs.ToAggregate()
if aggregatedErrs == nil {
err.ErrStatus.Message = fmt.Sprintf("%s %q is invalid", qualifiedKind.String(), name)
} else {
err.ErrStatus.Message = fmt.Sprintf("%s %q is invalid: %v", qualifiedKind.String(), name, aggregatedErrs)
}
return err
}
// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
@ -476,138 +523,242 @@ func NewGenericServerResponse(code int, verb string, qualifiedResource schema.Gr
}
// IsNotFound returns true if the specified error was created by NewNotFound.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsNotFound(err error) bool {
return ReasonForError(err) == metav1.StatusReasonNotFound
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonNotFound {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusNotFound {
return true
}
return false
}
// IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsAlreadyExists(err error) bool {
return ReasonForError(err) == metav1.StatusReasonAlreadyExists
}
// IsConflict determines if the err is an error which indicates the provided update conflicts.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsConflict(err error) bool {
return ReasonForError(err) == metav1.StatusReasonConflict
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonConflict {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusConflict {
return true
}
return false
}
// IsInvalid determines if the err is an error which indicates the provided resource is not valid.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsInvalid(err error) bool {
return ReasonForError(err) == metav1.StatusReasonInvalid
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonInvalid {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusUnprocessableEntity {
return true
}
return false
}
// IsGone is true if the error indicates the requested resource is no longer available.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsGone(err error) bool {
return ReasonForError(err) == metav1.StatusReasonGone
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonGone {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusGone {
return true
}
return false
}
// IsResourceExpired is true if the error indicates the resource has expired and the current action is
// no longer possible.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsResourceExpired(err error) bool {
return ReasonForError(err) == metav1.StatusReasonExpired
}
// IsNotAcceptable determines if err is an error which indicates that the request failed due to an invalid Accept header
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsNotAcceptable(err error) bool {
return ReasonForError(err) == metav1.StatusReasonNotAcceptable
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonNotAcceptable {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusNotAcceptable {
return true
}
return false
}
// IsUnsupportedMediaType determines if err is an error which indicates that the request failed due to an invalid Content-Type header
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsUnsupportedMediaType(err error) bool {
return ReasonForError(err) == metav1.StatusReasonUnsupportedMediaType
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonUnsupportedMediaType {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusUnsupportedMediaType {
return true
}
return false
}
// 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.
// It supports wrapped errors and returns false when the error is nil.
func IsMethodNotSupported(err error) bool {
return ReasonForError(err) == metav1.StatusReasonMethodNotAllowed
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonMethodNotAllowed {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusMethodNotAllowed {
return true
}
return false
}
// IsServiceUnavailable is true if the error indicates the underlying service is no longer available.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsServiceUnavailable(err error) bool {
return ReasonForError(err) == metav1.StatusReasonServiceUnavailable
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonServiceUnavailable {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusServiceUnavailable {
return true
}
return false
}
// IsBadRequest determines if err is an error which indicates that the request is invalid.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsBadRequest(err error) bool {
return ReasonForError(err) == metav1.StatusReasonBadRequest
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonBadRequest {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusBadRequest {
return true
}
return false
}
// IsUnauthorized determines if err is an error which indicates that the request is unauthorized and
// requires authentication by the user.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsUnauthorized(err error) bool {
return ReasonForError(err) == metav1.StatusReasonUnauthorized
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonUnauthorized {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusUnauthorized {
return true
}
return false
}
// IsForbidden determines if err is an error which indicates that the request is forbidden and cannot
// be completed as requested.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsForbidden(err error) bool {
return ReasonForError(err) == metav1.StatusReasonForbidden
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonForbidden {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusForbidden {
return true
}
return false
}
// IsTimeout determines if err is an error which indicates that request times out due to long
// processing.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsTimeout(err error) bool {
return ReasonForError(err) == metav1.StatusReasonTimeout
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonTimeout {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusGatewayTimeout {
return true
}
return false
}
// IsServerTimeout determines if err is an error which indicates that the request needs to be retried
// by the client.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsServerTimeout(err error) bool {
// do not check the status code, because no https status code exists that can
// be scoped to retryable timeouts.
return ReasonForError(err) == metav1.StatusReasonServerTimeout
}
// IsInternalError determines if err is an error which indicates an internal server error.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsInternalError(err error) bool {
return ReasonForError(err) == metav1.StatusReasonInternalError
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonInternalError {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusInternalServerError {
return true
}
return false
}
// IsTooManyRequests determines if err is an error which indicates that there are too many requests
// that the server cannot handle.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsTooManyRequests(err error) bool {
if ReasonForError(err) == metav1.StatusReasonTooManyRequests {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonTooManyRequests {
return true
}
if status := APIStatus(nil); errors.As(err, &status) {
return status.Status().Code == http.StatusTooManyRequests
// 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
}
return false
}
// IsRequestEntityTooLargeError determines if err is an error which indicates
// the request entity is too large.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsRequestEntityTooLargeError(err error) bool {
if ReasonForError(err) == metav1.StatusReasonRequestEntityTooLarge {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonRequestEntityTooLarge {
return true
}
if status := APIStatus(nil); errors.As(err, &status) {
return status.Status().Code == http.StatusRequestEntityTooLarge
// IsRequestEntityTooLargeError's 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.StatusRequestEntityTooLarge {
return true
}
return false
}
// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// and may be the result of another HTTP actor.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsUnexpectedServerError(err error) bool {
if status := APIStatus(nil); errors.As(err, &status) && status.Status().Details != nil {
status, ok := err.(APIStatus)
if (ok || errors.As(err, &status)) && status.Status().Details != nil {
for _, cause := range status.Status().Details.Causes {
if cause.Type == metav1.CauseTypeUnexpectedServerResponse {
return true
@ -618,19 +769,20 @@ func IsUnexpectedServerError(err error) bool {
}
// IsUnexpectedObjectError determines if err is due to an unexpected object from the master.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func IsUnexpectedObjectError(err error) bool {
uoe := &UnexpectedObjectError{}
return err != nil && errors.As(err, &uoe)
uoe, ok := err.(*UnexpectedObjectError)
return err != nil && (ok || errors.As(err, &uoe))
}
// SuggestsClientDelay returns true if this error suggests a client delay as well as the
// suggested seconds to wait, or false if the error does not imply a wait. It does not
// address whether the error *should* be retried, since some errors (like a 3xx) may
// request delay without retry.
// It supports wrapped errors.
// It supports wrapped errors and returns false when the error is nil.
func SuggestsClientDelay(err error) (int, bool) {
if t := APIStatus(nil); errors.As(err, &t) && t.Status().Details != nil {
t, ok := err.(APIStatus)
if (ok || errors.As(err, &t)) && t.Status().Details != nil {
switch t.Status().Reason {
// this StatusReason explicitly requests the caller to delay the action
case metav1.StatusReasonServerTimeout:
@ -645,14 +797,22 @@ func SuggestsClientDelay(err error) (int, bool) {
}
// ReasonForError returns the HTTP status for a particular error.
// It supports wrapped errors.
// It supports wrapped errors and returns StatusReasonUnknown when
// the error is nil or doesn't have a status.
func ReasonForError(err error) metav1.StatusReason {
if status := APIStatus(nil); errors.As(err, &status) {
if status, ok := err.(APIStatus); ok || errors.As(err, &status) {
return status.Status().Reason
}
return metav1.StatusReasonUnknown
}
func reasonAndCodeForError(err error) (metav1.StatusReason, int32) {
if status, ok := err.(APIStatus); ok || errors.As(err, &status) {
return status.Status().Reason, status.Status().Code
}
return metav1.StatusReasonUnknown, 0
}
// ErrorReporter converts generic errors into runtime.Object errors without
// requiring the caller to take a dependency on meta/v1 (where Status lives).
// This prevents circular dependencies in core watch code.