code
stringlengths 12
335k
| docstring
stringlengths 20
20.8k
| func_name
stringlengths 1
105
| language
stringclasses 1
value | repo
stringclasses 498
values | path
stringlengths 5
172
| url
stringlengths 43
235
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func NewApplyConflict(causes []metav1.StatusCause, message string) *StatusError {
return &StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusConflict,
Reason: metav1.StatusReasonConflict,
Details: &metav1.StatusDetails{
// TODO: Get obj details here?
Causes: causes,
},
Message: message,
}}
} | NewApplyConflict returns an error including details on the requests apply conflicts | NewApplyConflict | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewGone(message string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusGone,
Reason: metav1.StatusReasonGone,
Message: message,
}}
} | NewGone returns an error indicating the item no longer available at the server and no forwarding address is known.
DEPRECATED: Please use NewResourceExpired instead. | NewGone | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewResourceExpired(message string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusGone,
Reason: metav1.StatusReasonExpired,
Message: message,
}}
} | NewResourceExpired creates an error that indicates that the requested resource content has expired from
the server (usually due to a resourceVersion that is too old). | NewResourceExpired | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewInvalid(qualifiedKind schema.GroupKind, name string, errs field.ErrorList) *StatusError {
causes := make([]metav1.StatusCause, 0, len(errs))
for i := range errs {
err := errs[i]
causes = append(causes, metav1.StatusCause{
Type: metav1.CauseType(err.Type),
Message: err.ErrorBody(),
Field: err.Field,
})
}
err := &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusUnprocessableEntity,
Reason: metav1.StatusReasonInvalid,
Details: &metav1.StatusDetails{
Group: qualifiedKind.Group,
Kind: qualifiedKind.Kind,
Name: name,
Causes: causes,
},
}}
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
} | NewInvalid returns an error indicating the item is invalid and cannot be processed. | NewInvalid | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewBadRequest(reason string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusBadRequest,
Reason: metav1.StatusReasonBadRequest,
Message: reason,
}}
} | NewBadRequest creates an error that indicates that the request is invalid and can not be processed. | NewBadRequest | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewTooManyRequests(message string, retryAfterSeconds int) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusTooManyRequests,
Reason: metav1.StatusReasonTooManyRequests,
Message: message,
Details: &metav1.StatusDetails{
RetryAfterSeconds: int32(retryAfterSeconds),
},
}}
} | NewTooManyRequests creates an error that indicates that the client must try again later because
the specified endpoint is not accepting requests. More specific details should be provided
if client should know why the failure was limited. | NewTooManyRequests | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewServiceUnavailable(reason string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusServiceUnavailable,
Reason: metav1.StatusReasonServiceUnavailable,
Message: reason,
}}
} | NewServiceUnavailable creates an error that indicates that the requested service is unavailable. | NewServiceUnavailable | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewMethodNotSupported(qualifiedResource schema.GroupResource, action string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusMethodNotAllowed,
Reason: metav1.StatusReasonMethodNotAllowed,
Details: &metav1.StatusDetails{
Group: qualifiedResource.Group,
Kind: qualifiedResource.Resource,
},
Message: fmt.Sprintf("%s is not supported on resources of kind %q", action, qualifiedResource.String()),
}}
} | NewMethodNotSupported returns an error indicating the requested action is not supported on this kind. | NewMethodNotSupported | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewServerTimeout(qualifiedResource schema.GroupResource, operation string, retryAfterSeconds int) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Reason: metav1.StatusReasonServerTimeout,
Details: &metav1.StatusDetails{
Group: qualifiedResource.Group,
Kind: qualifiedResource.Resource,
Name: operation,
RetryAfterSeconds: int32(retryAfterSeconds),
},
Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, qualifiedResource.String()),
}}
} | NewServerTimeout returns an error indicating the requested action could not be completed due to a
transient error, and the client should try again. | NewServerTimeout | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewServerTimeoutForKind(qualifiedKind schema.GroupKind, operation string, retryAfterSeconds int) *StatusError {
return NewServerTimeout(schema.GroupResource{Group: qualifiedKind.Group, Resource: qualifiedKind.Kind}, operation, retryAfterSeconds)
} | NewServerTimeoutForKind should not exist. Server timeouts happen when accessing resources, the Kind is just what we
happened to be looking at when the request failed. This delegates to keep code sane, but we should work towards removing this. | NewServerTimeoutForKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewInternalError(err error) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Reason: metav1.StatusReasonInternalError,
Details: &metav1.StatusDetails{
Causes: []metav1.StatusCause{{Message: err.Error()}},
},
Message: fmt.Sprintf("Internal error occurred: %v", err),
}}
} | NewInternalError returns an error indicating the item is invalid and cannot be processed. | NewInternalError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewTimeoutError(message string, retryAfterSeconds int) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusGatewayTimeout,
Reason: metav1.StatusReasonTimeout,
Message: fmt.Sprintf("Timeout: %s", message),
Details: &metav1.StatusDetails{
RetryAfterSeconds: int32(retryAfterSeconds),
},
}}
} | NewTimeoutError returns an error indicating that a timeout occurred before the request
could be completed. Clients may retry, but the operation may still complete. | NewTimeoutError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewTooManyRequestsError(message string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusTooManyRequests,
Reason: metav1.StatusReasonTooManyRequests,
Message: fmt.Sprintf("Too many requests: %s", message),
}}
} | NewTooManyRequestsError returns an error indicating that the request was rejected because
the server has received too many requests. Client should wait and retry. But if the request
is perishable, then the client should not retry the request. | NewTooManyRequestsError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewRequestEntityTooLargeError(message string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusRequestEntityTooLarge,
Reason: metav1.StatusReasonRequestEntityTooLarge,
Message: fmt.Sprintf("Request entity too large: %s", message),
}}
} | NewRequestEntityTooLargeError returns an error indicating that the request
entity was too large. | NewRequestEntityTooLargeError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewGenericServerResponse(code int, verb string, qualifiedResource schema.GroupResource, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) *StatusError {
reason := metav1.StatusReasonUnknown
message := fmt.Sprintf("the server responded with the status code %d but did not return more information", code)
switch code {
case http.StatusConflict:
if verb == "POST" {
reason = metav1.StatusReasonAlreadyExists
} else {
reason = metav1.StatusReasonConflict
}
message = "the server reported a conflict"
case http.StatusNotFound:
reason = metav1.StatusReasonNotFound
message = "the server could not find the requested resource"
case http.StatusBadRequest:
reason = metav1.StatusReasonBadRequest
message = "the server rejected our request for an unknown reason"
case http.StatusUnauthorized:
reason = metav1.StatusReasonUnauthorized
message = "the server has asked for the client to provide credentials"
case http.StatusForbidden:
reason = metav1.StatusReasonForbidden
// the server message has details about who is trying to perform what action. Keep its message.
message = serverMessage
case http.StatusNotAcceptable:
reason = metav1.StatusReasonNotAcceptable
// the server message has details about what types are acceptable
if len(serverMessage) == 0 || serverMessage == "unknown" {
message = "the server was unable to respond with a content type that the client supports"
} else {
message = serverMessage
}
case http.StatusUnsupportedMediaType:
reason = metav1.StatusReasonUnsupportedMediaType
// the server message has details about what types are acceptable
message = serverMessage
case http.StatusMethodNotAllowed:
reason = metav1.StatusReasonMethodNotAllowed
message = "the server does not allow this method on the requested resource"
case http.StatusUnprocessableEntity:
reason = metav1.StatusReasonInvalid
message = "the server rejected our request due to an error in our request"
case http.StatusServiceUnavailable:
reason = metav1.StatusReasonServiceUnavailable
message = "the server is currently unable to handle the request"
case http.StatusGatewayTimeout:
reason = metav1.StatusReasonTimeout
message = "the server was unable to return a response in the time allotted, but may still be processing the request"
case http.StatusTooManyRequests:
reason = metav1.StatusReasonTooManyRequests
message = "the server has received too many requests and has asked us to try again later"
default:
if code >= 500 {
reason = metav1.StatusReasonInternalError
message = fmt.Sprintf("an error on the server (%q) has prevented the request from succeeding", serverMessage)
}
}
switch {
case !qualifiedResource.Empty() && len(name) > 0:
message = fmt.Sprintf("%s (%s %s %s)", message, strings.ToLower(verb), qualifiedResource.String(), name)
case !qualifiedResource.Empty():
message = fmt.Sprintf("%s (%s %s)", message, strings.ToLower(verb), qualifiedResource.String())
}
var causes []metav1.StatusCause
if isUnexpectedResponse {
causes = []metav1.StatusCause{
{
Type: metav1.CauseTypeUnexpectedServerResponse,
Message: serverMessage,
},
}
} else {
causes = nil
}
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: int32(code),
Reason: reason,
Details: &metav1.StatusDetails{
Group: qualifiedResource.Group,
Kind: qualifiedResource.Resource,
Name: name,
Causes: causes,
RetryAfterSeconds: int32(retryAfterSeconds),
},
Message: message,
}}
} | NewGenericServerResponse returns a new error for server responses that are not in a recognizable form. | NewGenericServerResponse | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsNotFound(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonNotFound {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusNotFound {
return true
}
return false
} | IsNotFound returns true if the specified error was created by NewNotFound.
It supports wrapped errors and returns false when the error is nil. | IsNotFound | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsAlreadyExists(err error) bool {
return ReasonForError(err) == metav1.StatusReasonAlreadyExists
} | IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
It supports wrapped errors and returns false when the error is nil. | IsAlreadyExists | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsConflict(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonConflict {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusConflict {
return true
}
return false
} | IsConflict determines if the err is an error which indicates the provided update conflicts.
It supports wrapped errors and returns false when the error is nil. | IsConflict | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsInvalid(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonInvalid {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusUnprocessableEntity {
return true
}
return false
} | IsInvalid determines if the err is an error which indicates the provided resource is not valid.
It supports wrapped errors and returns false when the error is nil. | IsInvalid | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsGone(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonGone {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusGone {
return true
}
return false
} | IsGone is true if the error indicates the requested resource is no longer available.
It supports wrapped errors and returns false when the error is nil. | IsGone | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsResourceExpired(err error) bool {
return ReasonForError(err) == metav1.StatusReasonExpired
} | IsResourceExpired is true if the error indicates the resource has expired and the current action is
no longer possible.
It supports wrapped errors and returns false when the error is nil. | IsResourceExpired | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsNotAcceptable(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonNotAcceptable {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusNotAcceptable {
return true
}
return false
} | IsNotAcceptable determines if err is an error which indicates that the request failed due to an invalid Accept header
It supports wrapped errors and returns false when the error is nil. | IsNotAcceptable | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsUnsupportedMediaType(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonUnsupportedMediaType {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusUnsupportedMediaType {
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 and returns false when the error is nil. | IsUnsupportedMediaType | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsMethodNotSupported(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonMethodNotAllowed {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusMethodNotAllowed {
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 and returns false when the error is nil. | IsMethodNotSupported | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsServiceUnavailable(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonServiceUnavailable {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusServiceUnavailable {
return true
}
return false
} | IsServiceUnavailable is true if the error indicates the underlying service is no longer available.
It supports wrapped errors and returns false when the error is nil. | IsServiceUnavailable | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsBadRequest(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonBadRequest {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusBadRequest {
return true
}
return false
} | IsBadRequest determines if err is an error which indicates that the request is invalid.
It supports wrapped errors and returns false when the error is nil. | IsBadRequest | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsUnauthorized(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonUnauthorized {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusUnauthorized {
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 and returns false when the error is nil. | IsUnauthorized | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsForbidden(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonForbidden {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusForbidden {
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 and returns false when the error is nil. | IsForbidden | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsTimeout(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonTimeout {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusGatewayTimeout {
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 and returns false when the error is nil. | IsTimeout | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
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
} | IsServerTimeout determines if err is an error which indicates that the request needs to be retried
by the client.
It supports wrapped errors and returns false when the error is nil. | IsServerTimeout | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsInternalError(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonInternalError {
return true
}
if _, ok := knownReasons[reason]; !ok && code == http.StatusInternalServerError {
return true
}
return false
} | IsInternalError determines if err is an error which indicates an internal server error.
It supports wrapped errors and returns false when the error is nil. | IsInternalError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsTooManyRequests(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonTooManyRequests {
return true
}
// 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
} | IsTooManyRequests determines if err is an error which indicates that there are too many requests
that the server cannot handle.
It supports wrapped errors and returns false when the error is nil. | IsTooManyRequests | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsRequestEntityTooLargeError(err error) bool {
reason, code := reasonAndCodeForError(err)
if reason == metav1.StatusReasonRequestEntityTooLarge {
return true
}
// 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
} | IsRequestEntityTooLargeError determines if err is an error which indicates
the request entity is too large.
It supports wrapped errors and returns false when the error is nil. | IsRequestEntityTooLargeError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsUnexpectedServerError(err error) bool {
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
}
}
}
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 and returns false when the error is nil. | IsUnexpectedServerError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func IsUnexpectedObjectError(err error) bool {
uoe, ok := err.(*UnexpectedObjectError)
return err != nil && (ok || errors.As(err, &uoe))
} | IsUnexpectedObjectError determines if err is due to an unexpected object from the master.
It supports wrapped errors and returns false when the error is nil. | IsUnexpectedObjectError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func SuggestsClientDelay(err error) (int, bool) {
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:
return int(t.Status().Details.RetryAfterSeconds), true
}
// If the client requests that we retry after a certain number of seconds
if t.Status().Details.RetryAfterSeconds > 0 {
return int(t.Status().Details.RetryAfterSeconds), true
}
}
return 0, false
} | 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 and returns false when the error is nil. | SuggestsClientDelay | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func ReasonForError(err error) metav1.StatusReason {
if status, ok := err.(APIStatus); ok || errors.As(err, &status) {
return status.Status().Reason
}
return metav1.StatusReasonUnknown
} | ReasonForError returns the HTTP status for a particular error.
It supports wrapped errors and returns StatusReasonUnknown when
the error is nil or doesn't have a status. | ReasonForError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewClientErrorReporter(code int, verb string, reason string) *ErrorReporter {
return &ErrorReporter{
code: code,
verb: verb,
reason: reason,
}
} | NewClientErrorReporter will respond with valid v1.Status objects that report
unexpected server responses. Primarily used by watch to report errors when
we attempt to decode a response from the server and it is not in the form
we expect. Because watch is a dependency of the core api, we can't return
meta/v1.Status in that package and so much inject this interface to convert a
generic error as appropriate. The reason is passed as a unique status cause
on the returned status, otherwise the generic "ClientError" is returned. | NewClientErrorReporter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go | Apache-2.0 |
func NewDefaultRESTMapper(defaultGroupVersions []schema.GroupVersion) *DefaultRESTMapper {
resourceToKind := make(map[schema.GroupVersionResource]schema.GroupVersionKind)
kindToPluralResource := make(map[schema.GroupVersionKind]schema.GroupVersionResource)
kindToScope := make(map[schema.GroupVersionKind]RESTScope)
singularToPlural := make(map[schema.GroupVersionResource]schema.GroupVersionResource)
pluralToSingular := make(map[schema.GroupVersionResource]schema.GroupVersionResource)
// TODO: verify name mappings work correctly when versions differ
return &DefaultRESTMapper{
resourceToKind: resourceToKind,
kindToPluralResource: kindToPluralResource,
kindToScope: kindToScope,
defaultGroupVersions: defaultGroupVersions,
singularToPlural: singularToPlural,
pluralToSingular: pluralToSingular,
}
} | NewDefaultRESTMapper initializes a mapping between Kind and APIVersion
to a resource name and back based on the objects in a runtime.Scheme
and the Kubernetes API conventions. Takes a group name, a priority list of the versions
to search when an object has no default version (set empty to return an error),
and a function that retrieves the correct metadata for a given version. | NewDefaultRESTMapper | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func UnsafeGuessKindToResource(kind schema.GroupVersionKind) ( /*plural*/ schema.GroupVersionResource /*singular*/, schema.GroupVersionResource) {
kindName := kind.Kind
if len(kindName) == 0 {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}
}
singularName := strings.ToLower(kindName)
singular := kind.GroupVersion().WithResource(singularName)
for _, skip := range unpluralizedSuffixes {
if strings.HasSuffix(singularName, skip) {
return singular, singular
}
}
switch string(singularName[len(singularName)-1]) {
case "s":
return kind.GroupVersion().WithResource(singularName + "es"), singular
case "y":
return kind.GroupVersion().WithResource(strings.TrimSuffix(singularName, "y") + "ies"), singular
}
return kind.GroupVersion().WithResource(singularName + "s"), singular
} | UnsafeGuessKindToResource converts Kind to a resource name.
Broken. This method only "sort of" works when used outside of this package. It assumes that Kinds and Resources match
and they aren't guaranteed to do so. | UnsafeGuessKindToResource | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func (m *DefaultRESTMapper) ResourceSingularizer(resourceType string) (string, error) {
partialResource := schema.GroupVersionResource{Resource: resourceType}
resources, err := m.ResourcesFor(partialResource)
if err != nil {
return resourceType, err
}
singular := schema.GroupVersionResource{}
for _, curr := range resources {
currSingular, ok := m.pluralToSingular[curr]
if !ok {
continue
}
if singular.Empty() {
singular = currSingular
continue
}
if currSingular.Resource != singular.Resource {
return resourceType, fmt.Errorf("multiple possible singular resources (%v) found for %v", resources, resourceType)
}
}
if singular.Empty() {
return resourceType, fmt.Errorf("no singular of resource %v has been defined", resourceType)
}
return singular.Resource, nil
} | ResourceSingularizer implements RESTMapper
It converts a resource name from plural to singular (e.g., from pods to pod) | ResourceSingularizer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func coerceResourceForMatching(resource schema.GroupVersionResource) schema.GroupVersionResource {
resource.Resource = strings.ToLower(resource.Resource)
if resource.Version == runtime.APIVersionInternal {
resource.Version = ""
}
return resource
} | coerceResourceForMatching makes the resource lower case and converts internal versions to unspecified (legacy behavior) | coerceResourceForMatching | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func (m *DefaultRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) {
mappings, err := m.RESTMappings(gk, versions...)
if err != nil {
return nil, err
}
if len(mappings) == 0 {
return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
// since we rely on RESTMappings method
// take the first match and return to the caller
// as this was the existing behavior.
return mappings[0], nil
} | RESTMapping returns a struct representing the resource path and conversion interfaces a
RESTClient should use to operate on the provided group/kind in order of versions. If a version search
order is not provided, the search order provided to DefaultRESTMapper will be used to resolve which
version should be used to access the named group/kind. | RESTMapping | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func (m *DefaultRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) {
mappings := make([]*RESTMapping, 0)
potentialGVK := make([]schema.GroupVersionKind, 0)
hadVersion := false
// Pick an appropriate version
for _, version := range versions {
if len(version) == 0 || version == runtime.APIVersionInternal {
continue
}
currGVK := gk.WithVersion(version)
hadVersion = true
if _, ok := m.kindToPluralResource[currGVK]; ok {
potentialGVK = append(potentialGVK, currGVK)
break
}
}
// Use the default preferred versions
if !hadVersion && len(potentialGVK) == 0 {
for _, gv := range m.defaultGroupVersions {
if gv.Group != gk.Group {
continue
}
potentialGVK = append(potentialGVK, gk.WithVersion(gv.Version))
}
}
if len(potentialGVK) == 0 {
return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
for _, gvk := range potentialGVK {
//Ensure we have a REST mapping
res, ok := m.kindToPluralResource[gvk]
if !ok {
continue
}
// Ensure we have a REST scope
scope, ok := m.kindToScope[gvk]
if !ok {
return nil, fmt.Errorf("the provided version %q and kind %q cannot be mapped to a supported scope", gvk.GroupVersion(), gvk.Kind)
}
mappings = append(mappings, &RESTMapping{
Resource: res,
GroupVersionKind: gvk,
Scope: scope,
})
}
if len(mappings) == 0 {
return nil, &NoResourceMatchError{PartialResource: schema.GroupVersionResource{Group: gk.Group, Resource: gk.Kind}}
}
return mappings, nil
} | RESTMappings returns the RESTMappings for the provided group kind. If a version search order
is not provided, the search order provided to DefaultRESTMapper will be used. | RESTMappings | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func MaybeResetRESTMapper(mapper RESTMapper) {
m, ok := mapper.(ResettableRESTMapper)
if ok {
m.Reset()
}
} | MaybeResetRESTMapper calls Reset() on the mapper if it is a ResettableRESTMapper. | MaybeResetRESTMapper | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go | Apache-2.0 |
func IsListType(obj runtime.Object) bool {
switch t := obj.(type) {
case runtime.Unstructured:
return t.IsList()
} | IsListType returns true if the provided Object has a slice called Items.
TODO: Replace the code in this check with an interface comparison by
creating and enforcing that lists implement a list accessor. | IsListType | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func GetItemsPtr(list runtime.Object) (interface{}, error) {
obj, err := getItemsPtr(list)
if err != nil {
return nil, fmt.Errorf("%T is not a list: %v", list, err)
}
return obj, nil
} | GetItemsPtr returns a pointer to the list object's Items member.
If 'list' doesn't have an Items member, it's not really a list type
and an error will be returned.
This function will either return a pointer to a slice, or an error, but not both.
TODO: this will be replaced with an interface in the future | GetItemsPtr | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func getItemsPtr(list runtime.Object) (interface{}, error) {
v, err := conversion.EnforcePtr(list)
if err != nil {
return nil, err
}
items := v.FieldByName("Items")
if !items.IsValid() {
return nil, errExpectFieldItems
}
switch items.Kind() {
case reflect.Interface, reflect.Pointer:
target := reflect.TypeOf(items.Interface()).Elem()
if target.Kind() != reflect.Slice {
return nil, errExpectSliceItems
}
return items.Interface(), nil
case reflect.Slice:
return items.Addr().Interface(), nil
default:
return nil, errExpectSliceItems
}
} | getItemsPtr returns a pointer to the list object's Items member or an error. | getItemsPtr | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func EachListItem(obj runtime.Object, fn func(runtime.Object) error) error {
return eachListItem(obj, fn, false)
} | EachListItem invokes fn on each runtime.Object in the list. Any error immediately terminates
the loop.
If items passed to fn are retained for different durations, and you want to avoid
retaining all items in obj as long as any item is referenced, use EachListItemWithAlloc instead. | EachListItem | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func EachListItemWithAlloc(obj runtime.Object, fn func(runtime.Object) error) error {
return eachListItem(obj, fn, true)
} | EachListItemWithAlloc works like EachListItem, but avoids retaining references to the items slice in obj.
It does this by making a shallow copy of non-pointer items in obj.
If the items passed to fn are not retained, or are retained for the same duration, use EachListItem instead for memory efficiency. | EachListItemWithAlloc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func eachListItem(obj runtime.Object, fn func(runtime.Object) error, allocNew bool) error {
if unstructured, ok := obj.(runtime.Unstructured); ok {
if allocNew {
return unstructured.EachListItemWithAlloc(fn)
}
return unstructured.EachListItem(fn)
}
// TODO: Change to an interface call?
itemsPtr, err := GetItemsPtr(obj)
if err != nil {
return err
}
items, err := conversion.EnforcePtr(itemsPtr)
if err != nil {
return err
}
len := items.Len()
if len == 0 {
return nil
}
takeAddr := false
if elemType := items.Type().Elem(); elemType.Kind() != reflect.Pointer && elemType.Kind() != reflect.Interface {
if !items.Index(0).CanAddr() {
return fmt.Errorf("unable to take address of items in %T for EachListItem", obj)
}
takeAddr = true
}
for i := 0; i < len; i++ {
raw := items.Index(i)
if takeAddr {
if allocNew {
// shallow copy to avoid retaining a reference to the original list item
itemCopy := reflect.New(raw.Type())
// assign to itemCopy and type-assert
itemCopy.Elem().Set(raw)
// reflect.New will guarantee that itemCopy must be a pointer.
raw = itemCopy
} else {
raw = raw.Addr()
}
}
// raw must be a pointer or an interface
// allocate a pointer is cheap
switch item := raw.Interface().(type) {
case *runtime.RawExtension:
if err := fn(item.Object); err != nil {
return err
}
case runtime.Object:
if err := fn(item); err != nil {
return err
}
default:
obj, ok := item.(runtime.Object)
if !ok {
return fmt.Errorf("%v: item[%v]: Expected object, got %#v(%s)", obj, i, raw.Interface(), raw.Kind())
}
if err := fn(obj); err != nil {
return err
}
}
} | allocNew: Whether shallow copy is required when the elements in Object.Items are struct | eachListItem | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func ExtractList(obj runtime.Object) ([]runtime.Object, error) {
return extractList(obj, false)
} | ExtractList returns obj's Items element as an array of runtime.Objects.
Returns an error if obj is not a List type (does not have an Items member).
If items in the returned list are retained for different durations, and you want to avoid
retaining all items in obj as long as any item is referenced, use ExtractListWithAlloc instead. | ExtractList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func ExtractListWithAlloc(obj runtime.Object) ([]runtime.Object, error) {
return extractList(obj, true)
} | ExtractListWithAlloc works like ExtractList, but avoids retaining references to the items slice in obj.
It does this by making a shallow copy of non-pointer items in obj.
If the items in the returned list are not retained, or are retained for the same duration, use ExtractList instead for memory efficiency. | ExtractListWithAlloc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func extractList(obj runtime.Object, allocNew bool) ([]runtime.Object, error) {
itemsPtr, err := GetItemsPtr(obj)
if err != nil {
return nil, err
}
items, err := conversion.EnforcePtr(itemsPtr)
if err != nil {
return nil, err
}
list := make([]runtime.Object, items.Len())
if len(list) == 0 {
return list, nil
}
elemType := items.Type().Elem()
isRawExtension := elemType == rawExtensionObjectType
implementsObject := elemType.Implements(objectType)
for i := range list {
raw := items.Index(i)
switch {
case isRawExtension:
item := raw.Interface().(runtime.RawExtension)
switch {
case item.Object != nil:
list[i] = item.Object
case item.Raw != nil:
// TODO: Set ContentEncoding and ContentType correctly.
list[i] = &runtime.Unknown{Raw: item.Raw}
default:
list[i] = nil
}
case implementsObject:
list[i] = raw.Interface().(runtime.Object)
case allocNew:
// shallow copy to avoid retaining a reference to the original list item
itemCopy := reflect.New(raw.Type())
// assign to itemCopy and type-assert
itemCopy.Elem().Set(raw)
var ok bool
// reflect.New will guarantee that itemCopy must be a pointer.
if list[i], ok = itemCopy.Interface().(runtime.Object); !ok {
return nil, fmt.Errorf("%v: item[%v]: Expected object, got %#v(%s)", obj, i, raw.Interface(), raw.Kind())
}
default:
var found bool
if list[i], found = raw.Addr().Interface().(runtime.Object); !found {
return nil, fmt.Errorf("%v: item[%v]: Expected object, got %#v(%s)", obj, i, raw.Interface(), raw.Kind())
}
}
}
return list, nil
} | allocNew: Whether shallow copy is required when the elements in Object.Items are struct | extractList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func LenList(list runtime.Object) int {
itemsPtr, err := GetItemsPtr(list)
if err != nil {
return 0
}
items, err := conversion.EnforcePtr(itemsPtr)
if err != nil {
return 0
}
return items.Len()
} | LenList returns the length of this list or 0 if it is not a list. | LenList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func SetList(list runtime.Object, objects []runtime.Object) error {
itemsPtr, err := GetItemsPtr(list)
if err != nil {
return err
}
items, err := conversion.EnforcePtr(itemsPtr)
if err != nil {
return err
}
if items.Type() == objectSliceType {
items.Set(reflect.ValueOf(objects))
return nil
}
slice := reflect.MakeSlice(items.Type(), len(objects), len(objects))
for i := range objects {
dest := slice.Index(i)
if dest.Type() == rawExtensionObjectType {
dest = dest.FieldByName("Object")
}
// check to see if you're directly assignable
if reflect.TypeOf(objects[i]).AssignableTo(dest.Type()) {
dest.Set(reflect.ValueOf(objects[i]))
continue
}
src, err := conversion.EnforcePtr(objects[i])
if err != nil {
return err
}
if src.Type().AssignableTo(dest.Type()) {
dest.Set(src)
} else if src.Type().ConvertibleTo(dest.Type()) {
dest.Set(src.Convert(dest.Type()))
} else {
return fmt.Errorf("item[%d]: can't assign or convert %v into %v", i, src.Type(), dest.Type())
}
}
items.Set(slice)
return nil
} | SetList sets the given list object's Items member have the elements given in
objects.
Returns an error if list is not a List type (does not have an Items member),
or if any of the objects are not of the right type. | SetList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/help.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/help.go | Apache-2.0 |
func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource schema.GroupVersionResource) (schema.GroupVersionResource, error) {
originalGVRs, originalErr := m.Delegate.ResourcesFor(partiallySpecifiedResource)
if originalErr != nil && len(originalGVRs) == 0 {
return schema.GroupVersionResource{}, originalErr
}
if len(originalGVRs) == 1 {
return originalGVRs[0], originalErr
}
remainingGVRs := append([]schema.GroupVersionResource{}, originalGVRs...)
for _, pattern := range m.ResourcePriority {
matchedGVRs := []schema.GroupVersionResource{}
for _, gvr := range remainingGVRs {
if resourceMatches(pattern, gvr) {
matchedGVRs = append(matchedGVRs, gvr)
}
}
switch len(matchedGVRs) {
case 0:
// if you have no matches, then nothing matched this pattern just move to the next
continue
case 1:
// one match, return
return matchedGVRs[0], originalErr
default:
// more than one match, use the matched hits as the list moving to the next pattern.
// this way you can have a series of selection criteria
remainingGVRs = matchedGVRs
}
}
return schema.GroupVersionResource{}, &AmbiguousResourceError{PartialResource: partiallySpecifiedResource, MatchingResources: originalGVRs}
} | ResourceFor finds all resources, then passes them through the ResourcePriority patterns to find a single matching hit. | ResourceFor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/priority.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go | Apache-2.0 |
func (m PriorityRESTMapper) KindFor(partiallySpecifiedResource schema.GroupVersionResource) (schema.GroupVersionKind, error) {
originalGVKs, originalErr := m.Delegate.KindsFor(partiallySpecifiedResource)
if originalErr != nil && len(originalGVKs) == 0 {
return schema.GroupVersionKind{}, originalErr
}
if len(originalGVKs) == 1 {
return originalGVKs[0], originalErr
}
remainingGVKs := append([]schema.GroupVersionKind{}, originalGVKs...)
for _, pattern := range m.KindPriority {
matchedGVKs := []schema.GroupVersionKind{}
for _, gvr := range remainingGVKs {
if kindMatches(pattern, gvr) {
matchedGVKs = append(matchedGVKs, gvr)
}
}
switch len(matchedGVKs) {
case 0:
// if you have no matches, then nothing matched this pattern just move to the next
continue
case 1:
// one match, return
return matchedGVKs[0], originalErr
default:
// more than one match, use the matched hits as the list moving to the next pattern.
// this way you can have a series of selection criteria
remainingGVKs = matchedGVKs
}
}
return schema.GroupVersionKind{}, &AmbiguousResourceError{PartialResource: partiallySpecifiedResource, MatchingKinds: originalGVKs}
} | KindFor finds all kinds, then passes them through the KindPriority patterns to find a single matching hit. | KindFor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/priority.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go | Apache-2.0 |
func NewLazyRESTMapperLoader(fn func() (RESTMapper, error)) RESTMapper {
obj := &lazyObject{loader: fn}
return obj
} | NewLazyRESTMapperLoader handles unrecoverable errors when creating a RESTMapper / ObjectTyper by
returning those initialization errors when the interface methods are invoked. This defers the
initialization and any server calls until a client actually needs to perform the action. | NewLazyRESTMapperLoader | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go | Apache-2.0 |
func (o *lazyObject) init() error {
o.lock.Lock()
defer o.lock.Unlock()
if o.loaded {
return o.err
}
o.mapper, o.err = o.loader()
o.loaded = true
return o.err
} | init lazily loads the mapper and typer, returning an error if initialization has failed. | init | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go | Apache-2.0 |
func (m FirstHitRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) {
errors := []error{}
for _, t := range m.MultiRESTMapper {
ret, err := t.RESTMapping(gk, versions...)
if err == nil {
return ret, nil
}
errors = append(errors, err)
}
return nil, collapseAggregateErrors(errors)
} | RESTMapping provides the REST mapping for the resource based on the
kind and version. This implementation supports multiple REST schemas and
return the first match. | RESTMapping | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go | Apache-2.0 |
func collapseAggregateErrors(errors []error) error {
if len(errors) == 0 {
return nil
}
if len(errors) == 1 {
return errors[0]
}
allNoMatchErrors := true
for _, err := range errors {
allNoMatchErrors = allNoMatchErrors && IsNoMatchError(err)
}
if allNoMatchErrors {
return errors[0]
}
return utilerrors.NewAggregate(errors)
} | collapseAggregateErrors returns the minimal errors. it handles empty as nil, handles one item in a list
by returning the item, and collapses all NoMatchErrors to a single one (since they should all be the same) | collapseAggregateErrors | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go | Apache-2.0 |
func SetStatusCondition(conditions *[]metav1.Condition, newCondition metav1.Condition) (changed bool) {
if conditions == nil {
return false
}
existingCondition := FindStatusCondition(*conditions, newCondition.Type)
if existingCondition == nil {
if newCondition.LastTransitionTime.IsZero() {
newCondition.LastTransitionTime = metav1.NewTime(time.Now())
}
*conditions = append(*conditions, newCondition)
return true
}
if existingCondition.Status != newCondition.Status {
existingCondition.Status = newCondition.Status
if !newCondition.LastTransitionTime.IsZero() {
existingCondition.LastTransitionTime = newCondition.LastTransitionTime
} else {
existingCondition.LastTransitionTime = metav1.NewTime(time.Now())
}
changed = true
}
if existingCondition.Reason != newCondition.Reason {
existingCondition.Reason = newCondition.Reason
changed = true
}
if existingCondition.Message != newCondition.Message {
existingCondition.Message = newCondition.Message
changed = true
}
if existingCondition.ObservedGeneration != newCondition.ObservedGeneration {
existingCondition.ObservedGeneration = newCondition.ObservedGeneration
changed = true
}
return changed
} | SetStatusCondition sets the corresponding condition in conditions to newCondition and returns true
if the conditions are changed by this call.
conditions must be non-nil.
1. if the condition of the specified type already exists (all fields of the existing condition are updated to
newCondition, LastTransitionTime is set to now if the new status differs from the old status)
2. if a condition of the specified type does not exist (LastTransitionTime is set to now() if unset, and newCondition is appended) | SetStatusCondition | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | Apache-2.0 |
func RemoveStatusCondition(conditions *[]metav1.Condition, conditionType string) (removed bool) {
if conditions == nil || len(*conditions) == 0 {
return false
}
newConditions := make([]metav1.Condition, 0, len(*conditions)-1)
for _, condition := range *conditions {
if condition.Type != conditionType {
newConditions = append(newConditions, condition)
}
}
removed = len(*conditions) != len(newConditions)
*conditions = newConditions
return removed
} | RemoveStatusCondition removes the corresponding conditionType from conditions if present. Returns
true if it was present and got removed.
conditions must be non-nil. | RemoveStatusCondition | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | Apache-2.0 |
func FindStatusCondition(conditions []metav1.Condition, conditionType string) *metav1.Condition {
for i := range conditions {
if conditions[i].Type == conditionType {
return &conditions[i]
}
}
return nil
} | FindStatusCondition finds the conditionType in conditions. | FindStatusCondition | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | Apache-2.0 |
func IsStatusConditionTrue(conditions []metav1.Condition, conditionType string) bool {
return IsStatusConditionPresentAndEqual(conditions, conditionType, metav1.ConditionTrue)
} | IsStatusConditionTrue returns true when the conditionType is present and set to `metav1.ConditionTrue` | IsStatusConditionTrue | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | Apache-2.0 |
func IsStatusConditionFalse(conditions []metav1.Condition, conditionType string) bool {
return IsStatusConditionPresentAndEqual(conditions, conditionType, metav1.ConditionFalse)
} | IsStatusConditionFalse returns true when the conditionType is present and set to `metav1.ConditionFalse` | IsStatusConditionFalse | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | Apache-2.0 |
func IsStatusConditionPresentAndEqual(conditions []metav1.Condition, conditionType string, status metav1.ConditionStatus) bool {
for _, condition := range conditions {
if condition.Type == conditionType {
return condition.Status == status
}
}
return false
} | IsStatusConditionPresentAndEqual returns true when conditionType is present and equal to status. | IsStatusConditionPresentAndEqual | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/conditions.go | Apache-2.0 |
func (m MultiRESTMapper) ResourceSingularizer(resource string) (singular string, err error) {
for _, t := range m {
singular, err = t.ResourceSingularizer(resource)
if err == nil {
return
}
}
return
} | ResourceSingularizer converts a REST resource name from plural to singular (e.g., from pods to pod)
This implementation supports multiple REST schemas and return the first match. | ResourceSingularizer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go | Apache-2.0 |
func (m MultiRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) {
allMappings := []*RESTMapping{}
errors := []error{}
for _, t := range m {
currMapping, err := t.RESTMapping(gk, versions...)
// ignore "no match" errors, but any other error percolates back up
if IsNoMatchError(err) {
continue
}
if err != nil {
errors = append(errors, err)
continue
}
allMappings = append(allMappings, currMapping)
}
// if we got exactly one mapping, then use it even if other requested failed
if len(allMappings) == 1 {
return allMappings[0], nil
}
if len(allMappings) > 1 {
var kinds []schema.GroupVersionKind
for _, m := range allMappings {
kinds = append(kinds, m.GroupVersionKind)
}
return nil, &AmbiguousKindError{PartialKind: gk.WithVersion(""), MatchingKinds: kinds}
}
if len(errors) > 0 {
return nil, utilerrors.NewAggregate(errors)
}
return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
} | RESTMapping provides the REST mapping for the resource based on the
kind and version. This implementation supports multiple REST schemas and
return the first match. | RESTMapping | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go | Apache-2.0 |
func (m MultiRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) {
var allMappings []*RESTMapping
var errors []error
for _, t := range m {
currMappings, err := t.RESTMappings(gk, versions...)
// ignore "no match" errors, but any other error percolates back up
if IsNoMatchError(err) {
continue
}
if err != nil {
errors = append(errors, err)
continue
}
allMappings = append(allMappings, currMappings...)
}
if len(errors) > 0 {
return nil, utilerrors.NewAggregate(errors)
}
if len(allMappings) == 0 {
return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
return allMappings, nil
} | RESTMappings returns all possible RESTMappings for the provided group kind, or an error
if the type is not recognized. | RESTMappings | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go | Apache-2.0 |
func CommonAccessor(obj interface{}) (metav1.Common, error) {
switch t := obj.(type) {
case List:
return t, nil
case ListMetaAccessor:
if m := t.GetListMeta(); m != nil {
return m, nil
}
return nil, errNotCommon
case metav1.ListMetaAccessor:
if m := t.GetListMeta(); m != nil {
return m, nil
}
return nil, errNotCommon
case metav1.Object:
return t, nil
case metav1.ObjectMetaAccessor:
if m := t.GetObjectMeta(); m != nil {
return m, nil
}
return nil, errNotCommon
default:
return nil, errNotCommon
} | CommonAccessor returns a Common interface for the provided object or an error if the object does
not provide List. | CommonAccessor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func ListAccessor(obj interface{}) (List, error) {
switch t := obj.(type) {
case List:
return t, nil
case ListMetaAccessor:
if m := t.GetListMeta(); m != nil {
return m, nil
}
return nil, errNotList
case metav1.ListMetaAccessor:
if m := t.GetListMeta(); m != nil {
return m, nil
}
return nil, errNotList
default:
return nil, errNotList
} | ListAccessor returns a List interface for the provided object or an error if the object does
not provide List.
IMPORTANT: Objects are NOT a superset of lists. Do not use this check to determine whether an
object *is* a List. | ListAccessor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func Accessor(obj interface{}) (metav1.Object, error) {
switch t := obj.(type) {
case metav1.Object:
return t, nil
case metav1.ObjectMetaAccessor:
if m := t.GetObjectMeta(); m != nil {
return m, nil
}
return nil, errNotObject
default:
return nil, errNotObject
} | Accessor takes an arbitrary object pointer and returns meta.Interface.
obj must be a pointer to an API type. An error is returned if the minimum
required fields are missing. Fields that are not required return the default
value and are a no-op if set. | Accessor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func AsPartialObjectMetadata(m metav1.Object) *metav1.PartialObjectMetadata {
switch t := m.(type) {
case *metav1.ObjectMeta:
return &metav1.PartialObjectMetadata{ObjectMeta: *t}
default:
return &metav1.PartialObjectMetadata{
ObjectMeta: metav1.ObjectMeta{
Name: m.GetName(),
GenerateName: m.GetGenerateName(),
Namespace: m.GetNamespace(),
SelfLink: m.GetSelfLink(),
UID: m.GetUID(),
ResourceVersion: m.GetResourceVersion(),
Generation: m.GetGeneration(),
CreationTimestamp: m.GetCreationTimestamp(),
DeletionTimestamp: m.GetDeletionTimestamp(),
DeletionGracePeriodSeconds: m.GetDeletionGracePeriodSeconds(),
Labels: m.GetLabels(),
Annotations: m.GetAnnotations(),
OwnerReferences: m.GetOwnerReferences(),
Finalizers: m.GetFinalizers(),
ManagedFields: m.GetManagedFields(),
},
}
} | AsPartialObjectMetadata takes the metav1 interface and returns a partial object.
TODO: consider making this solely a conversion action. | AsPartialObjectMetadata | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func TypeAccessor(obj interface{}) (Type, error) {
if typed, ok := obj.(runtime.Object); ok {
return objectAccessor{typed}, nil
}
v, err := conversion.EnforcePtr(obj)
if err != nil {
return nil, err
}
t := v.Type()
if v.Kind() != reflect.Struct {
return nil, fmt.Errorf("expected struct, but got %v: %v (%#v)", v.Kind(), t, v.Interface())
}
typeMeta := v.FieldByName("TypeMeta")
if !typeMeta.IsValid() {
return nil, fmt.Errorf("struct %v lacks embedded TypeMeta type", t)
}
a := &genericAccessor{}
if err := extractFromTypeMeta(typeMeta, a); err != nil {
return nil, fmt.Errorf("unable to find type fields on %#v: %v", typeMeta, err)
}
return a, nil
} | TypeAccessor returns an interface that allows retrieving and modifying the APIVersion
and Kind of an in-memory internal object.
TODO: this interface is used to test code that does not have ObjectMeta or ListMeta
in round tripping (objects which can use apiVersion/kind, but do not fit the Kube
api conventions). | TypeAccessor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func NewAccessor() MetadataAccessor {
return resourceAccessor{}
} | NewAccessor returns a MetadataAccessor that can retrieve
or manipulate resource version on objects derived from core API
metadata concepts. | NewAccessor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func extractFromOwnerReference(v reflect.Value, o *metav1.OwnerReference) error {
if err := runtime.Field(v, "APIVersion", &o.APIVersion); err != nil {
return err
}
if err := runtime.Field(v, "Kind", &o.Kind); err != nil {
return err
}
if err := runtime.Field(v, "Name", &o.Name); err != nil {
return err
}
if err := runtime.Field(v, "UID", &o.UID); err != nil {
return err
}
var controllerPtr *bool
if err := runtime.Field(v, "Controller", &controllerPtr); err != nil {
return err
}
if controllerPtr != nil {
controller := *controllerPtr
o.Controller = &controller
}
var blockOwnerDeletionPtr *bool
if err := runtime.Field(v, "BlockOwnerDeletion", &blockOwnerDeletionPtr); err != nil {
return err
}
if blockOwnerDeletionPtr != nil {
block := *blockOwnerDeletionPtr
o.BlockOwnerDeletion = &block
}
return nil
} | extractFromOwnerReference extracts v to o. v is the OwnerReferences field of an object. | extractFromOwnerReference | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func setOwnerReference(v reflect.Value, o *metav1.OwnerReference) error {
if err := runtime.SetField(o.APIVersion, v, "APIVersion"); err != nil {
return err
}
if err := runtime.SetField(o.Kind, v, "Kind"); err != nil {
return err
}
if err := runtime.SetField(o.Name, v, "Name"); err != nil {
return err
}
if err := runtime.SetField(o.UID, v, "UID"); err != nil {
return err
}
if o.Controller != nil {
controller := *(o.Controller)
if err := runtime.SetField(&controller, v, "Controller"); err != nil {
return err
}
}
if o.BlockOwnerDeletion != nil {
block := *(o.BlockOwnerDeletion)
if err := runtime.SetField(&block, v, "BlockOwnerDeletion"); err != nil {
return err
}
}
return nil
} | setOwnerReference sets v to o. v is the OwnerReferences field of an object. | setOwnerReference | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func extractFromTypeMeta(v reflect.Value, a *genericAccessor) error {
if err := runtime.FieldPtr(v, "APIVersion", &a.apiVersion); err != nil {
return err
}
if err := runtime.FieldPtr(v, "Kind", &a.kind); err != nil {
return err
}
return nil
} | extractFromTypeMeta extracts pointers to version and kind fields from an object | extractFromTypeMeta | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | Apache-2.0 |
func (m *Quantity) MarshalTo(data []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(data[:size])
} | MarshalTo is a customized version of the generated Protobuf unmarshaler for a struct
with a single string field. | MarshalTo | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto.go | Apache-2.0 |
func (m *Quantity) MarshalToSizedBuffer(data []byte) (int, error) {
i := len(data)
_ = i
var l int
_ = l
// BEGIN CUSTOM MARSHAL
out := m.String()
i -= len(out)
copy(data[i:], out)
i = encodeVarintGenerated(data, i, uint64(len(out)))
// END CUSTOM MARSHAL
i--
data[i] = 0xa
return len(data) - i, nil
} | MarshalToSizedBuffer is a customized version of the generated
Protobuf unmarshaler for a struct with a single string field. | MarshalToSizedBuffer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto.go | Apache-2.0 |
func (m *Quantity) Unmarshal(data []byte) error {
l := len(data)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenerated
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Quantity: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Quantity: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field String_", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenerated
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthGenerated
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
s := string(data[iNdEx:postIndex])
// BEGIN CUSTOM DECODE
p, err := ParseQuantity(s)
if err != nil {
return err
}
*m = p
// END CUSTOM DECODE
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipGenerated(data[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthGenerated
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
} | Unmarshal is a customized version of the generated Protobuf unmarshaler for a struct
with a single string field. | Unmarshal | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity_proto.go | Apache-2.0 |
func scaledValue(unscaled *big.Int, scale, newScale int) int64 {
dif := scale - newScale
if dif == 0 {
return unscaled.Int64()
}
// Handle scale up
// This is an easy case, we do not need to care about rounding and overflow.
// If any intermediate operation causes overflow, the result will overflow.
if dif < 0 {
return unscaled.Int64() * int64(math.Pow10(-dif))
}
// Handle scale down
// We have to be careful about the intermediate operations.
// fast path when unscaled < max.Int64 and exp(10,dif) < max.Int64
const log10MaxInt64 = 19
if unscaled.Cmp(maxInt64) < 0 && dif < log10MaxInt64 {
divide := int64(math.Pow10(dif))
result := unscaled.Int64() / divide
mod := unscaled.Int64() % divide
if mod != 0 {
return result + 1
}
return result
}
// We should only convert back to int64 when getting the result.
divisor := intPool.Get().(*big.Int)
exp := intPool.Get().(*big.Int)
result := intPool.Get().(*big.Int)
defer func() {
intPool.Put(divisor)
intPool.Put(exp)
intPool.Put(result)
}()
// divisor = 10^(dif)
// TODO: create loop up table if exp costs too much.
divisor.Exp(bigTen, exp.SetInt64(int64(dif)), nil)
// reuse exp
remainder := exp
// result = unscaled / divisor
// remainder = unscaled % divisor
result.DivMod(unscaled, divisor, remainder)
if remainder.Sign() != 0 {
return result.Int64() + 1
}
return result.Int64()
} | scaledValue scales given unscaled value from scale to new Scale and returns
an int64. It ALWAYS rounds up the result when scale down. The final result might
overflow.
scale, newScale represents the scale of the unscaled decimal.
The mathematical value of the decimal is unscaled * 10**(-scale). | scaledValue | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/scale_int.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/scale_int.go | Apache-2.0 |
func int64Add(a, b int64) (int64, bool) {
c := a + b
switch {
case a > 0 && b > 0:
if c < 0 {
return 0, false
}
case a < 0 && b < 0:
if c > 0 {
return 0, false
}
if a == mostNegative && b == mostNegative {
return 0, false
}
}
return c, true
} | int64Add returns a+b, or false if that would overflow int64. | int64Add | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func int64Multiply(a, b int64) (int64, bool) {
if a == 0 || b == 0 || a == 1 || b == 1 {
return a * b, true
}
if a == mostNegative || b == mostNegative {
return 0, false
}
c := a * b
return c, c/b == a
} | int64Multiply returns a*b, or false if that would overflow or underflow int64. | int64Multiply | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func int64MultiplyScale(a int64, b int64) (int64, bool) {
if a == 0 || a == 1 {
return a * b, true
}
if a == mostNegative && b != 1 {
return 0, false
}
c := a * b
return c, c/b == a
} | int64MultiplyScale returns a*b, assuming b is greater than one, or false if that would overflow or underflow int64.
Use when b is known to be greater than one. | int64MultiplyScale | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func int64MultiplyScale10(a int64) (int64, bool) {
if a == 0 || a == 1 {
return a * 10, true
}
if a == mostNegative {
return 0, false
}
c := a * 10
return c, c/10 == a
} | int64MultiplyScale10 multiplies a by 10, or returns false if that would overflow. This method is faster than
int64Multiply(a, 10) because the compiler can optimize constant factor multiplication. | int64MultiplyScale10 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func int64MultiplyScale100(a int64) (int64, bool) {
if a == 0 || a == 1 {
return a * 100, true
}
if a == mostNegative {
return 0, false
}
c := a * 100
return c, c/100 == a
} | int64MultiplyScale100 multiplies a by 100, or returns false if that would overflow. This method is faster than
int64Multiply(a, 100) because the compiler can optimize constant factor multiplication. | int64MultiplyScale100 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func int64MultiplyScale1000(a int64) (int64, bool) {
if a == 0 || a == 1 {
return a * 1000, true
}
if a == mostNegative {
return 0, false
}
c := a * 1000
return c, c/1000 == a
} | int64MultiplyScale1000 multiplies a by 1000, or returns false if that would overflow. This method is faster than
int64Multiply(a, 1000) because the compiler can optimize constant factor multiplication. | int64MultiplyScale1000 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func positiveScaleInt64(base int64, scale Scale) (int64, bool) {
switch scale {
case 0:
return base, true
case 1:
return int64MultiplyScale10(base)
case 2:
return int64MultiplyScale100(base)
case 3:
return int64MultiplyScale1000(base)
case 6:
return int64MultiplyScale(base, 1000000)
case 9:
return int64MultiplyScale(base, 1000000000)
default:
value := base
var ok bool
for i := Scale(0); i < scale; i++ {
if value, ok = int64MultiplyScale(value, 10); !ok {
return 0, false
}
}
return value, true
}
} | positiveScaleInt64 multiplies base by 10^scale, returning false if the
value overflows. Passing a negative scale is undefined. | positiveScaleInt64 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func negativeScaleInt64(base int64, scale Scale) (result int64, exact bool) {
if scale == 0 {
return base, true
}
value := base
var fraction bool
for i := Scale(0); i < scale; i++ {
if !fraction && value%10 != 0 {
fraction = true
}
value = value / 10
if value == 0 {
if fraction {
if base > 0 {
return 1, false
}
return -1, false
}
return 0, true
}
}
if fraction {
if base > 0 {
value++
} else {
value--
}
}
return value, !fraction
} | negativeScaleInt64 reduces base by the provided scale, rounding up, until the
value is zero or the scale is reached. Passing a negative scale is undefined.
The value returned, if not exact, is rounded away from zero. | negativeScaleInt64 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func divideByScaleInt64(base int64, scale Scale) (result, remainder int64, exact bool) {
if scale == 0 {
return base, 0, true
}
// the max scale representable in base 10 in an int64 is 18 decimal places
if scale >= 18 {
return 0, base, false
}
divisor := pow10Int64(int64(scale))
return base / divisor, base % divisor, true
} | negativeScaleInt64 returns the result of dividing base by scale * 10 and the remainder, or
false if no such division is possible. Dividing by negative scales is undefined. | divideByScaleInt64 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func removeInt64Factors(value int64, base int64) (result int64, times int32) {
times = 0
result = value
negative := result < 0
if negative {
result = -result
}
switch base {
// allow the compiler to optimize the common cases
case 10:
for result >= 10 && result%10 == 0 {
times++
result = result / 10
}
// allow the compiler to optimize the common cases
case 1024:
for result >= 1024 && result%1024 == 0 {
times++
result = result / 1024
}
default:
for result >= base && result%base == 0 {
times++
result = result / base
}
}
if negative {
result = -result
}
return result, times
} | removeInt64Factors divides in a loop; the return values have the property that
value == result * base ^ scale | removeInt64Factors | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func removeBigIntFactors(d, factor *big.Int) (result *big.Int, times int32) {
q := big.NewInt(0)
m := big.NewInt(0)
for d.Cmp(bigZero) != 0 {
q.DivMod(d, factor, m)
if m.Cmp(bigZero) != 0 {
break
}
times++
d, q = q, d
}
return d, times
} | removeBigIntFactors divides in a loop; the return values have the property that
d == result * factor ^ times
d may be modified in place.
If d == 0, then the return values will be (0, 0) | removeBigIntFactors | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/math.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/math.go | Apache-2.0 |
func (in *Quantity) DeepCopyInto(out *Quantity) {
*out = in.DeepCopy()
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/zz_generated.deepcopy.go | Apache-2.0 |
func (in *QuantityValue) DeepCopyInto(out *QuantityValue) {
*out = *in
out.Quantity = in.Quantity.DeepCopy()
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/zz_generated.deepcopy.go | Apache-2.0 |
func (in *QuantityValue) DeepCopy() *QuantityValue {
if in == nil {
return nil
}
out := new(QuantityValue)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QuantityValue. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/zz_generated.deepcopy.go | Apache-2.0 |
func MustParse(str string) Quantity {
q, err := ParseQuantity(str)
if err != nil {
panic(fmt.Errorf("cannot parse '%v': %v", str, err))
}
return q
} | MustParse turns the given string into a quantity or panics; for tests
or other cases where you know the string is valid. | MustParse | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go | Apache-2.0 |
func parseQuantityString(str string) (positive bool, value, num, denom, suffix string, err error) {
positive = true
pos := 0
end := len(str)
// handle leading sign
if pos < end {
switch str[0] {
case '-':
positive = false
pos++
case '+':
pos++
}
}
// strip leading zeros
Zeroes:
for i := pos; ; i++ {
if i >= end {
num = "0"
value = num
return
}
switch str[i] {
case '0':
pos++
default:
break Zeroes
}
}
// extract the numerator
Num:
for i := pos; ; i++ {
if i >= end {
num = str[pos:end]
value = str[0:end]
return
}
switch str[i] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
default:
num = str[pos:i]
pos = i
break Num
}
}
// if we stripped all numerator positions, always return 0
if len(num) == 0 {
num = "0"
}
// handle a denominator
if pos < end && str[pos] == '.' {
pos++
Denom:
for i := pos; ; i++ {
if i >= end {
denom = str[pos:end]
value = str[0:end]
return
}
switch str[i] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
default:
denom = str[pos:i]
pos = i
break Denom
}
}
// TODO: we currently allow 1.G, but we may not want to in the future.
// if len(denom) == 0 {
// err = ErrFormatWrong
// return
// }
}
value = str[0:pos]
// grab the elements of the suffix
suffixStart := pos
for i := pos; ; i++ {
if i >= end {
suffix = str[suffixStart:end]
return
}
if !strings.ContainsAny(str[i:i+1], "eEinumkKMGTP") {
pos = i
break
}
}
if pos < end {
switch str[pos] {
case '-', '+':
pos++
}
}
Suffix:
for i := pos; ; i++ {
if i >= end {
suffix = str[suffixStart:end]
return
}
switch str[i] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
default:
break Suffix
}
}
// we encountered a non decimal in the Suffix loop, but the last character
// was not a valid exponent
err = ErrFormatWrong
return
} | parseQuantityString is a fast scanner for quantity values. | parseQuantityString | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.