Class PodUtils
java.lang.Object
org.csanchez.jenkins.plugins.kubernetes.PodUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
cancelQueueItemFor
(io.fabric8.kubernetes.api.model.Pod pod, String reason) Cancel queue items matching the given pod.static void
cancelQueueItemFor
(String runUrl, String label, String reason, String podDisplayName) static String
Create kubernetes resource name with a random suffix appended to the given base name.static String
Generate a random string to be used as the suffix for dynamic resource names.static List<io.fabric8.kubernetes.api.model.ContainerStatus>
getContainers
(io.fabric8.kubernetes.api.model.Pod pod, Predicate<io.fabric8.kubernetes.api.model.ContainerStatus> predicate) Get pod container statuses (does not include ephemeral or init containers) that match the given filter.static List<io.fabric8.kubernetes.api.model.ContainerStatus>
getContainerStatus
(io.fabric8.kubernetes.api.model.Pod pod) Get all container statuses (does not include ephemeral or init containers).static List<io.fabric8.kubernetes.api.model.ContainerStatus>
getTerminatedContainers
(io.fabric8.kubernetes.api.model.Pod pod) static List<io.fabric8.kubernetes.api.model.ContainerStatus>
getWaitingContainers
(io.fabric8.kubernetes.api.model.Pod pod) static boolean
isValidName
(String name) Check if the given name is a valid pod resource name.static String
logLastLines
(io.fabric8.kubernetes.api.model.Pod pod, io.fabric8.kubernetes.client.KubernetesClient client)
-
Field Details
-
CONTAINER_IS_TERMINATED
public static final Predicate<io.fabric8.kubernetes.api.model.ContainerStatus> CONTAINER_IS_TERMINATED -
CONTAINER_IS_WAITING
-
-
Method Details
-
getTerminatedContainers
@NonNull public static List<io.fabric8.kubernetes.api.model.ContainerStatus> getTerminatedContainers(io.fabric8.kubernetes.api.model.Pod pod) -
getWaitingContainers
public static List<io.fabric8.kubernetes.api.model.ContainerStatus> getWaitingContainers(io.fabric8.kubernetes.api.model.Pod pod) -
getContainerStatus
@NonNull public static List<io.fabric8.kubernetes.api.model.ContainerStatus> getContainerStatus(@NonNull io.fabric8.kubernetes.api.model.Pod pod) Get all container statuses (does not include ephemeral or init containers).- Parameters:
pod
- pod to get container statuses for- Returns:
- list of statuses, possibly empty, never null
-
getContainers
public static List<io.fabric8.kubernetes.api.model.ContainerStatus> getContainers(@NonNull io.fabric8.kubernetes.api.model.Pod pod, @NonNull Predicate<io.fabric8.kubernetes.api.model.ContainerStatus> predicate) Get pod container statuses (does not include ephemeral or init containers) that match the given filter.- Parameters:
pod
- pod to get container statuses forpredicate
- container status predicate- Returns:
- list of statuses, possibly empty, never null
-
cancelQueueItemFor
Cancel queue items matching the given pod.
The queue item has to have a task url matching the pod "runUrl"-annotation and the queue item assigned label needs to match the label jenkins/label of the pod.
It uses the current thread context to list item queues, so make sure to be in the right context before calling this method.
- Parameters:
pod
- The pod to cancel items for.reason
- The reason the item are being cancelled.
-
cancelQueueItemFor
-
logLastLines
@CheckForNull public static String logLastLines(@NonNull io.fabric8.kubernetes.api.model.Pod pod, @NonNull io.fabric8.kubernetes.client.KubernetesClient client) -
generateRandomSuffix
Generate a random string to be used as the suffix for dynamic resource names.- Returns:
- random string suitable for kubernetes resources
-
createNameWithRandomSuffix
Create kubernetes resource name with a random suffix appended to the given base name. This method performs some basic transforms to make the base name compliant (i.e. spaces and underscores). The returned string will also be truncated to a max of 63 characters.- Parameters:
name
- base name to append to- Returns:
- resource name with random suffix and maximum length of 63 characters
-
isValidName
Check if the given name is a valid pod resource name. Does not validate string length.- Parameters:
name
- name to check- Returns:
- true if the given string contains valid pod resource name characters
-