Documentation ¶
Overview ¶
Package kube contains utility types and methods for managing kubernetes state.
Index ¶
- Constants
- func ApplyStrategicMergePatch[T any](target, patch T) error
- func AvailablePods(pods []*corev1.Pod, minReady time.Duration, now time.Time) []*corev1.Pod
- func ComputeRollout(maxUnavail *intstr.IntOrString, desired, ready int) int
- func CreateOrUpdate(ctx context.Context, client client.Writer, obj client.Object) error
- func FindOrDefaultCopy[T client.Object](existing []T, comparator T) T
- func IgnoreAlreadyExists(err error) error
- func IgnoreNotFound(err error) error
- func IndexOwner[T client.Object](kind string) client.IndexerFunc
- func IsAlreadyExists(err error) bool
- func IsJobFinished(job *batchv1.Job) bool
- func IsNotFound(err error) bool
- func IsPodAvailable(pod *corev1.Pod, minReady time.Duration, now time.Time) bool
- func MustToInt(s string) int64
- func NormalizeMetadata(obj *metav1.ObjectMeta)
- func ParseImageVersion(imageRef string) string
- func RecentVolumeSnapshot(ctx context.Context, lister Lister, namespace string, ...) (*snapshotv1.VolumeSnapshot, error)
- func ToIntegerValue[T constraints.Signed](n T) string
- func ToLabelKey(val string) string
- func ToName(val string) string
- func VolumeSnapshotIsReady(status *snapshotv1.VolumeSnapshotStatus) bool
- type EventReporter
- func (r EventReporter) Debug(msg string, keysAndValues ...interface{})
- func (r EventReporter) Error(err error, msg string, keysAndValues ...interface{})
- func (r EventReporter) Info(msg string, keysAndValues ...interface{})
- func (r EventReporter) RecordError(reason string, err error)
- func (r EventReporter) RecordInfo(reason, msg string)
- type Lister
- type Logger
- type ReconcileError
- type ReconcileErrors
- type Reporter
Constants ¶
const ( ControllerLabel = "app.kubernetes.io/created-by" InstanceLabel = "app.kubernetes.io/instance" NameLabel = "app.kubernetes.io/name" VersionLabel = "app.kubernetes.io/version" ComponentLabel = "app.kubernetes.io/component" // OrdinalAnnotation is used to order resources. The value must be a base 10 integer string. OrdinalAnnotation = "app.kubernetes.io/ordinal" )
Recommended labels. See: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
const ( EventWarning = "Warning" EventNormal = "Normal" )
The two accepted event types for recording events.
const (
ControllerOwnerField = ".metadata.controller"
)
Fields.
Variables ¶
This section is empty.
Functions ¶
func ApplyStrategicMergePatch ¶
ApplyStrategicMergePatch applies a strategic merge patch to a target object. Inspired by: https://github.com/kubernetes/apiserver/blob/45f55ded302a02ed2023e8b45bd241cf7d81169e/pkg/endpoints/handlers/patch.go
func AvailablePods ¶
AvailablePods returns pods which are available as defined in IsPodAvailable.
func ComputeRollout ¶
func ComputeRollout(maxUnavail *intstr.IntOrString, desired, ready int) int
ComputeRollout returns the number of replicas allowed to be updated to keep within a max unavailable threshold. Example: If max unavailable is 5 with a desired replica count of 10, that means rollout cannot happen until 6 or more replicas are ready. The replicas must stay within the minimum threshold of 5 ready replicas.
If "maxUnavail" is nil, defaults to 25% and string value must be a percentage. "desired" must be >= 1 and "ready" must be >= 0 or else this function panics.
func CreateOrUpdate ¶
CreateOrUpdate first attempts to create the obj. If it already exists, it makes a second call to update the obj.
func FindOrDefaultCopy ¶
FindOrDefaultCopy returns a deep copy of the object if it exists in the collection, otherwise it returns a deep copy of the comparator. Also defaults .metadata.labels and .metadata.annotations to an empty map if they are nil.
func IgnoreAlreadyExists ¶
IgnoreAlreadyExists returns nil if err reason is "already exists".
func IgnoreNotFound ¶
IgnoreNotFound returns nil if err reason is "not found".
func IndexOwner ¶
func IndexOwner[T client.Object](kind string) client.IndexerFunc
IndexOwner returns field values for indexing "child" resources that are "owned" by a controller (typically the CRD such as CosmosFullNode). Indexing is required for client.Client methods such as listing resources.
It returns a field to index only if all are true: 1) resource is part of cosmosv1.GroupVersion. 2) resource is owned by a controller equal to "kind".
func IsAlreadyExists ¶
IsAlreadyExists determines if the error indicates that a specified resource already exists. It supports wrapped errors and returns false when the error is nil.
func IsJobFinished ¶
IsJobFinished checks whether the given Job has finished execution. It does not discriminate between successful and failed terminations.
func IsNotFound ¶
IsNotFound returns true if the err reason is "not found".
func IsPodAvailable ¶
IsPodAvailable returns true if a pod is available; false otherwise. Precondition for an available pod is that it must be ready. Additionally, there are two cases when a pod can be considered available: 1. minReady == 0, or 2. LastTransitionTime (is set) + minReadySeconds < current time
Much of this code was vendored from the kubernetes codebase.
func NormalizeMetadata ¶
func NormalizeMetadata(obj *metav1.ObjectMeta)
NormalizeMetadata normalizes name, labels, and annotations. See: https://unofficial-kubernetes.readthedocs.io/en/latest/concepts/overview/working-with-objects/names/ See: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set.
func ParseImageVersion ¶
ParseImageVersion parses the version (aka tag) out of imageRef. As an example, "busybox:stable" would return "stable". If no tag, defaults to "latest".
func RecentVolumeSnapshot ¶
func RecentVolumeSnapshot(ctx context.Context, lister Lister, namespace string, selector map[string]string) (*snapshotv1.VolumeSnapshot, error)
RecentVolumeSnapshot finds the most recent, ready to use VolumeSnapshot. This function may not work well given very large lists and therefore assumes a reasonable number of VolumeSnapshots. If you must search among many VolumeSnapshots, consider refactoring to use Limit and Continue features of listing.
func ToIntegerValue ¶
func ToIntegerValue[T constraints.Signed](n T) string
ToIntegerValue converts n to a base 10 integer string.
func ToLabelKey ¶
ToLabelKey normalizes val per kubernetes label constraints to a max of 63 characters. See: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set.
func ToName ¶
ToName normalizes val per kubernetes name constraints to a max of 253 characters. See: https://unofficial-kubernetes.readthedocs.io/en/latest/concepts/overview/working-with-objects/names/
func VolumeSnapshotIsReady ¶
func VolumeSnapshotIsReady(status *snapshotv1.VolumeSnapshotStatus) bool
VolumeSnapshotIsReady returns true if the snapshot is ready to use.
Types ¶
type EventReporter ¶
type EventReporter struct {
// contains filtered or unexported fields
}
EventReporter both logs and records events.
func NewEventReporter ¶
func NewEventReporter(logger logr.Logger, recorder record.EventRecorder, resource runtime.Object) EventReporter
func (EventReporter) Debug ¶
func (r EventReporter) Debug(msg string, keysAndValues ...interface{})
Debug logs as a debug log entry.
func (EventReporter) Error ¶
func (r EventReporter) Error(err error, msg string, keysAndValues ...interface{})
Error logs as an error log entry.
func (EventReporter) Info ¶
func (r EventReporter) Info(msg string, keysAndValues ...interface{})
Info logs as an info log entry.
func (EventReporter) RecordError ¶
func (r EventReporter) RecordError(reason string, err error)
RecordError records a warning event.
func (EventReporter) RecordInfo ¶
func (r EventReporter) RecordInfo(reason, msg string)
RecordInfo records a normal event.
type Lister ¶
type Lister interface {
List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}
Lister can list resources, subset of client.Client.
type Logger ¶
type Logger interface { Info(msg string, keysAndValues ...interface{}) Debug(msg string, keysAndValues ...interface{}) Error(err error, msg string, keysAndValues ...interface{}) }
Logger is a structured logger
type ReconcileError ¶
type ReconcileError interface { error // IsTransient returns true if the error is temporary. IsTransient() bool }
ReconcileError is a controller-specific error.
func TransientError ¶
func TransientError(err error) ReconcileError
TransientError can be recovered or retried.
func UnrecoverableError ¶
func UnrecoverableError(err error) ReconcileError
UnrecoverableError cannot be recovered and should not be retried.
type ReconcileErrors ¶
type ReconcileErrors struct {
// contains filtered or unexported fields
}
ReconcileErrors is a collection of ReconcileError
func (*ReconcileErrors) Any ¶
func (errs *ReconcileErrors) Any() bool
Any returns true if any errors were collected.
func (*ReconcileErrors) Append ¶
func (errs *ReconcileErrors) Append(err ReconcileError)
Append adds the ReconcileError.
func (*ReconcileErrors) Error ¶
func (errs *ReconcileErrors) Error() string
func (*ReconcileErrors) IsTransient ¶
func (errs *ReconcileErrors) IsTransient() bool
IsTransient returns true if all errors are transient. False if at least one is not transient.