utils

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 28 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// RevisionAnnotation is the revision annotation of a deployment's replica sets which records its rollout sequence
	RevisionAnnotation = "deployment.kubernetes.io/revision"
	// TimedOutReason is added in a deployment when its newest replica set fails to show any progress
	// within the given deadline (progressDeadlineSeconds).
	TimedOutReason = "ProgressDeadlineExceeded"
)

Variables

View Source
var (
	ErrNilObject  = errors.New("can't reference a nil object")
	ErrNoSelfLink = errors.New("selfLink was empty, can't make reference")
)

Errors that could be returned by GetReference.

Functions

func BlueF added in v0.5.0

func BlueF(format string, a ...interface{}) string

func BoldF added in v0.5.0

func BoldF(format string, a ...interface{}) string

func DeploymentProgressing

func DeploymentProgressing(deployment *appsv1.Deployment, newStatus *appsv1.DeploymentStatus) bool

DeploymentProgressing reports progress for a deployment. Progress is estimated by comparing the current with the new status of the deployment that the controller is observing. More specifically, when new pods are scaled up or become available, or old pods are scaled down, then we consider the deployment is progressing.

func DeploymentTimedOut

func DeploymentTimedOut(deployment *appsv1.Deployment, newStatus *appsv1.DeploymentStatus) bool

DeploymentTimedOut considers a deployment to have timed out once its condition that reports progress is older than progressDeadlineSeconds or a Progressing condition with a TimedOutReason reason already exists.

func DescribeEvents

func DescribeEvents(el *corev1.EventList)

func DirExists

func DirExists(path string) (bool, error)

func EqualIgnoreHash

func EqualIgnoreHash(template1, template2 corev1.PodTemplateSpec) bool

EqualIgnoreHash returns true if two given podTemplateSpec are equal, ignoring the diff in value of Labels[pod-template-hash] We ignore pod-template-hash because the hash result would be different upon podTemplateSpec API changes (e.g. the addition of a new field will cause the hash code to change) Note that we assume input podTemplateSpecs contain non-empty labels

func EventFieldSelectorFromResource

func EventFieldSelectorFromResource(obj interface{}) string

func EventFieldSelectorFromUnstructured added in v0.7.0

func EventFieldSelectorFromUnstructured(obj *unstructured.Unstructured) (field fields.Set, eventNs string)

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if path exists

func FindNewReplicaSet

func FindNewReplicaSet(deployment *appsv1.Deployment, rsList []*appsv1.ReplicaSet) (*appsv1.ReplicaSet, error)

FindNewReplicaSet returns the new RS this given deployment targets (the one with the same pod template).

func FindOldReplicaSets

func FindOldReplicaSets(deployment *appsv1.Deployment, rsList []*appsv1.ReplicaSet) ([]*appsv1.ReplicaSet, []*appsv1.ReplicaSet, error)

FindOldReplicaSets returns the old replica sets targeted by the given Deployment, with the given slice of RSes. Note that the first set of old replica sets doesn't include the ones with no pods, and the second set of old replica sets include all old replica sets.

func FormatEventSource

func FormatEventSource(es corev1.EventSource) string

FormatEventSource formats EventSource as a comma separated string excluding Host when empty

func GetAllReplicaSets

func GetAllReplicaSets(ctx context.Context, deployment *appsv1.Deployment, c kubernetes.Interface) ([]*appsv1.ReplicaSet, []*appsv1.ReplicaSet, *appsv1.ReplicaSet, error)

GetAllReplicaSets returns the old and new replica sets targeted by the given Deployment. It gets PodList and ReplicaSetList from client interface. Note that the first set of old replica sets doesn't include the ones with no pods, and the second set of old replica sets include all old replica sets. The third returned value is the new replica set, and it may be nil if it doesn't exist yet.

func GetControllerOf

func GetControllerOf(controllee metav1.Object) *metav1.OwnerReference

GetControllerOf returns the controllerRef if controllee has a controller, otherwise returns nil.

func GetDeploymentCondition

func GetDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition

GetDeploymentCondition returns the condition with the provided type.

func GetNewReplicaSetTemplate

func GetNewReplicaSetTemplate(deployment *appsv1.Deployment) corev1.PodTemplateSpec

GetNewReplicaSetTemplate returns the desired PodTemplateSpec for the new ReplicaSet corresponding to the given ReplicaSet. Callers of this helper need to set the DefaultDeploymentUniqueLabelKey k/v pair.

func GetPodReplicaSetName

func GetPodReplicaSetName(pod *corev1.Pod) string

func GetReference

func GetReference(obj runtime.Object) (*corev1.ObjectReference, error)

func GreenF added in v0.5.0

func GreenF(format string, a ...interface{}) string

func IsReplicaSetNew

func IsReplicaSetNew(deployment *appsv1.Deployment, rsMap map[string]*appsv1.ReplicaSet, rsName string) (bool, error)

func JSONPath added in v0.7.0

func JSONPath(tmpl string, input interface{}) (result string, found bool, err error)

func ListEventsForObject

func ListEventsForObject(ctx context.Context, client kubernetes.Interface, obj interface{}) (*corev1.EventList, error)

func ListEventsForUnstructured added in v0.7.0

func ListEventsForUnstructured(ctx context.Context, client kubernetes.Interface, obj *unstructured.Unstructured) (*corev1.EventList, error)

func ListPods

func ListPods(deployment *appsv1.Deployment, rsList []*appsv1.ReplicaSet, getPodList PodListFunc) (*corev1.PodList, error)

ListPods returns a list of pods the given deployment targets. This needs a list of ReplicaSets for the Deployment, which can be found with ListReplicaSets(). Note that this does NOT attempt to reconcile ControllerRef (adopt/orphan), because only the controller itself should do that. However, it does filter out anything whose ControllerRef doesn't match.

func ListReplicaSets

func ListReplicaSets(deployment *appsv1.Deployment, getRSList rsListFunc) ([]*appsv1.ReplicaSet, error)

ListReplicaSets returns a slice of RSes the given deployment targets. Note that this does NOT attempt to reconcile ControllerRef (adopt/orphan), because only the controller itself should do that. However, it does filter out anything whose ControllerRef doesn't match.

func RedF added in v0.5.0

func RedF(format string, a ...interface{}) string

func Revision

func Revision(obj runtime.Object) (int64, error)

Revision returns the revision number of the input object.

func TranslateTimestampSince

func TranslateTimestampSince(timestamp metav1.Time) string

func YellowF added in v0.5.0

func YellowF(format string, a ...interface{}) string

Types

type ControllerMetadata

type ControllerMetadata interface {
	NewReplicaSetTemplate() corev1.PodTemplateSpec
	LabelSelector() *metav1.LabelSelector
	Namespace() string
	Name() string
	UID() types.UID
}

func ControllerAccessor

func ControllerAccessor(controller interface{}) ControllerMetadata

type PodListFunc

type PodListFunc func(string, metav1.ListOptions) (*corev1.PodList, error)

func PodListFromClient

func PodListFromClient(ctx context.Context, c kubernetes.Interface) PodListFunc

PodListFromClient returns an PodListFunc that wraps the given client.

type ReplicaSetControllerWrapper

type ReplicaSetControllerWrapper struct {
	// contains filtered or unexported fields
}

func (*ReplicaSetControllerWrapper) LabelSelector

func (w *ReplicaSetControllerWrapper) LabelSelector() *metav1.LabelSelector

func (*ReplicaSetControllerWrapper) Name

func (*ReplicaSetControllerWrapper) Namespace

func (w *ReplicaSetControllerWrapper) Namespace() string

func (*ReplicaSetControllerWrapper) NewReplicaSetTemplate

func (w *ReplicaSetControllerWrapper) NewReplicaSetTemplate() corev1.PodTemplateSpec

func (*ReplicaSetControllerWrapper) UID

type ReplicaSetsByCreationTimestamp

type ReplicaSetsByCreationTimestamp []*appsv1.ReplicaSet

ReplicaSetsByCreationTimestamp sorts a list of ReplicaSet by creation timestamp, using their names as a tie breaker.

func (ReplicaSetsByCreationTimestamp) Len

func (ReplicaSetsByCreationTimestamp) Less

func (ReplicaSetsByCreationTimestamp) Swap

func (o ReplicaSetsByCreationTimestamp) Swap(i, j int)

type SortableEvents

type SortableEvents []corev1.Event

SortableEvents implements sort.Interface for []api.Event based on the Timestamp field

func (SortableEvents) Len

func (list SortableEvents) Len() int

func (SortableEvents) Less

func (list SortableEvents) Less(i, j int) bool

func (SortableEvents) Swap

func (list SortableEvents) Swap(i, j int)

type Table

type Table struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable(columnsRatio ...float64) Table

func (*Table) Commit

func (t *Table) Commit(extraColumns ...interface{})

func (*Table) Header

func (t *Table) Header(columns ...interface{})

func (*Table) Render

func (t *Table) Render() string

func (*Table) Row

func (t *Table) Row(columns ...interface{})

func (*Table) Rows

func (t *Table) Rows(rows ...[]interface{})

func (*Table) SetWidth

func (t *Table) SetWidth(width int)

func (*Table) SubTable

func (t *Table) SubTable(columnsRatio ...float64) Table

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL