kube

package
v0.0.0-...-90065ab Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanSchedule

func CanSchedule(node *corev1.Node, podSpec *corev1.PodSpec) bool

CanSchedule checks if a given pod can be scheduled on a node based on various conditions.

func DeletePod

func DeletePod(ctx context.Context, client kubernetes.Interface, pod corev1.Pod) error

DeletePod deletes a pod using the Kubernetes client.

func FilterPods

func FilterPods(list *corev1.PodList, filter func(*corev1.Pod) bool) []*corev1.Pod

FilterPods filters the given list of Pods using the provided filter function and returns a list of filtered Pods.

func FilterScheduleable

func FilterScheduleable(nodes []*corev1.Node, podSpec *corev1.PodSpec) []*corev1.Node

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

func GetAllNodes(ctx context.Context, client kubernetes.Interface) ([]*corev1.Node, error)

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 IsEvicted

func IsEvicted(_ context.Context, pod corev1.Pod) bool

IsEvicted returns the pod is already Evicted. Deprecated: Use IsEvictedPod instead

func IsEvictedPod

func IsEvictedPod(pod *corev1.Pod) bool

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

func IsPodReadyRunning(po corev1.Pod) bool

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

type ReplicaSetStatus struct {
	Owners map[types.UID]int
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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