Class PodUtils

java.lang.Object
org.csanchez.jenkins.plugins.kubernetes.PodUtils

public final class PodUtils extends Object
  • Field Details

    • CONTAINER_IS_TERMINATED

      public static final Predicate<io.fabric8.kubernetes.api.model.ContainerStatus> CONTAINER_IS_TERMINATED
    • CONTAINER_IS_WAITING

      public static final Predicate<io.fabric8.kubernetes.api.model.ContainerStatus> 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 for
      predicate - container status predicate
      Returns:
      list of statuses, possibly empty, never null
    • cancelQueueItemFor

      public static void cancelQueueItemFor(io.fabric8.kubernetes.api.model.Pod pod, String reason)

      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

      public static void cancelQueueItemFor(@NonNull String runUrl, @NonNull String label, @CheckForNull String reason, @CheckForNull String podDisplayName)
    • logLastLines

      @CheckForNull public static String logLastLines(@NonNull io.fabric8.kubernetes.api.model.Pod pod, @NonNull io.fabric8.kubernetes.client.KubernetesClient client)
    • generateRandomSuffix

      @NonNull public static String generateRandomSuffix()
      Generate a random string to be used as the suffix for dynamic resource names.
      Returns:
      random string suitable for kubernetes resources
    • createNameWithRandomSuffix

      @NonNull public static String createNameWithRandomSuffix(@NonNull String name)
      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

      public static boolean isValidName(@NonNull String name)
      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