Documentation ¶
Index ¶
- func CanSchedule(node *corev1.Node, podSpec *corev1.PodSpec) bool
- func DeletePod(ctx context.Context, client kubernetes.Interface, pod corev1.Pod) error
- func FilterPods(list *corev1.PodList, filter func(*corev1.Pod) bool) []*corev1.Pod
- func FilterScheduleable(nodes []*corev1.Node, podSpec *corev1.PodSpec) []*corev1.Node
- func GetAllNodes(ctx context.Context, client kubernetes.Interface) ([]*corev1.Node, error)
- func GetNodeResourceCapacity(node *corev1.Node) (corev1.ResourceList, error)
- func GetPodRequestResources(podSpec corev1.PodSpec) corev1.ResourceList
- func IsEvictedPod(pod *corev1.Pod) bool
- func IsPodOwnedBy(rs *appsv1.ReplicaSet, po *corev1.Pod) bool
- func IsPodReadyRunning(po corev1.Pod) bool
- func RestartDeployment(ctx context.Context, client kubernetes.Interface, dep *appsv1.Deployment) error
- type ReplicaSetStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanSchedule ¶
CanSchedule checks if a given pod can be scheduled on a node based on various conditions.
func FilterPods ¶
FilterPods filters the given list of Pods using the provided filter function and returns a list of filtered Pods.
func FilterScheduleable ¶
FilterScheduleable filters the list of nodes based on whether each node can schedule the given pod spec. It takes a slice of node pointers and a pod spec as arguments. It returns a new slice of node pointers that can schedule the pod spec.
func GetAllNodes ¶
GetAllNodes retrieves a list of all nodes in the Kubernetes cluster. It takes a context and a client as arguments. It returns a slice of pointers to Node objects and an error.
func GetNodeResourceCapacity ¶
func GetNodeResourceCapacity(node *corev1.Node) (corev1.ResourceList, error)
GetNodeResourceCapacity retrieves the allocatable resource capacity of a node. It takes a pointer to a Node object as an argument. It returns a ResourceList and an error.
func GetPodRequestResources ¶
func GetPodRequestResources(podSpec corev1.PodSpec) corev1.ResourceList
GetPodRequestResources calculates the maximum CPU and memory resources requested by the containers in a given PodSpec. It iterates over each container in the PodSpec and checks if it has requested resources. If so, it compares the requested CPU and memory with the previously calculated maximums, and updates them if necessary. Finally, it returns the maximum CPU and memory resources as a corev1.ResourceList.
func IsEvictedPod ¶
IsEvictedPod checks if a given Pod has been evicted. It returns true if the Pod's phase is "Failed" and the reason is "Evicted", otherwise, it returns false.
func IsPodOwnedBy ¶
func IsPodOwnedBy(rs *appsv1.ReplicaSet, po *corev1.Pod) bool
IsPodOwnedBy returns true if the given Pod is owned by the specified ReplicaSet, false otherwise. It compares the UID of the ReplicaSet with the UID of each owner reference in the Pod's metadata. Example usage:
rs := &appsv1.ReplicaSet{ ObjectMeta: metav1.ObjectMeta{UID: types.UID("owner-1")}, } po := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ OwnerReferences: []metav1.OwnerReference{ {UID: types.UID("owner-1")}, {UID: types.UID("owner-2")}, }, }, }
isOwned := IsPodOwnedBy(rs, po) assert.True(t, isOwned) po.ObjectMeta.OwnerReferences = []metav1.OwnerReference{{UID: types.UID("owner-3")}} isOwned = IsPodOwnedBy(rs, po) assert.False(t, isOwned)
func IsPodReadyRunning ¶
IsPodReadyRunning checks if a given Pod is both ready and running.
func RestartDeployment ¶
func RestartDeployment(ctx context.Context, client kubernetes.Interface, dep *appsv1.Deployment) error
RestartDeployment restarts a deployment by updating its template metadata annotations with the current time.
Types ¶
type ReplicaSetStatus ¶
ReplicaSetStatus represents the status of a replica set.
func NewReplicaSetStatus ¶
func NewReplicaSetStatus(rs []*appsv1.ReplicaSet) ReplicaSetStatus
NewReplicaSetStatus returns a new instance of ReplicaSetStatus interface. It initializes and returns a rsOwners struct by iterating over the given list of ReplicaSets.
func (*ReplicaSetStatus) IsRollingUpdating ¶
func (u *ReplicaSetStatus) IsRollingUpdating(_ context.Context, rs *appsv1.ReplicaSet) bool
IsRollingUpdating checks if a ReplicaSet is undergoing rolling updates. It takes a context and a ReplicaSet as parameters. It iterates over the OwnerReferences of the ReplicaSet and checks if any of the OwnerReferences have more than one occurrence in the Owners map. If it finds such an OwnerReference, it returns true. Otherwise, it returns false.