Class KubeResourceManager

java.lang.Object
io.skodjob.testframe.resources.KubeResourceManager

public class KubeResourceManager extends Object
Manages Kubernetes resources for testing purposes.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    addCreateCallback(Consumer<io.fabric8.kubernetes.api.model.HasMetadata> callback)
    Add callback function which is called after creation of every resource
    final void
    addDeleteCallback(Consumer<io.fabric8.kubernetes.api.model.HasMetadata> callback)
    Add callback function which is called after deletion of every resource
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    Creates or updates resources.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    Creates or updates resources and waits for readiness.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    createResourceWithoutWait(T... resources)
    Creates resources without waiting for readiness.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    createResourceWithWait(T... resources)
    Creates resources and waits for readiness.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    deleteResource(T... resources)
    Deletes resources.
    void
    Deletes all stored resources.
    Retrieves the singleton instance of KubeResourceManager.
    static KubeClient
    Retrieves the Kubernetes client.
    static KubeCmdClient<?>
    Retrieves the Kubernetes command-line client.
    static org.junit.jupiter.api.extension.ExtensionContext
    Retrieves the test context.
    void
    printAllResources(org.slf4j.event.Level logLevel)
    Logs all managed resources across all test contexts with set log level
    void
    printCurrentResources(org.slf4j.event.Level logLevel)
    Logs all managed resources in current test context with set log level
    final void
    Pushes a resource item to the stack.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    pushToStack(T resource)
    Pushes a resource to the stack.
    List<io.fabric8.kubernetes.api.model.HasMetadata>
    Reads Kubernetes resources from an InputStream.
    List<io.fabric8.kubernetes.api.model.HasMetadata>
    Reads Kubernetes resources from a file at the specified path.
    final void
    Sets the resource types.
    static void
    setTestContext(org.junit.jupiter.api.extension.ExtensionContext context)
    Sets the test context.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    void
    updateResource(T... resources)
    Updates resources.
    final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
    boolean
    waitResourceCondition(T resource, ResourceCondition<T> condition)
    Waits for a resource condition to be fulfilled.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static KubeResourceManager getInstance()
      Retrieves the singleton instance of KubeResourceManager.
      Returns:
      The singleton instance of KubeResourceManager.
    • getKubeClient

      public static KubeClient getKubeClient()
      Retrieves the Kubernetes client.
      Returns:
      The Kubernetes client.
    • getKubeCmdClient

      public static KubeCmdClient<?> getKubeCmdClient()
      Retrieves the Kubernetes command-line client.
      Returns:
      The Kubernetes command-line client.
    • setTestContext

      public static void setTestContext(org.junit.jupiter.api.extension.ExtensionContext context)
      Sets the test context.
      Parameters:
      context - The extension context.
    • getTestContext

      public static org.junit.jupiter.api.extension.ExtensionContext getTestContext()
      Retrieves the test context.
      Returns:
      The extension context.
    • setResourceTypes

      public final void setResourceTypes(ResourceType<?>... types)
      Sets the resource types.
      Parameters:
      types - The resource types implementing ResourceType
    • addCreateCallback

      public final void addCreateCallback(Consumer<io.fabric8.kubernetes.api.model.HasMetadata> callback)
      Add callback function which is called after creation of every resource
      Parameters:
      callback - function
    • addDeleteCallback

      public final void addDeleteCallback(Consumer<io.fabric8.kubernetes.api.model.HasMetadata> callback)
      Add callback function which is called after deletion of every resource
      Parameters:
      callback - function
    • readResourcesFromFile

      public List<io.fabric8.kubernetes.api.model.HasMetadata> readResourcesFromFile(Path file) throws IOException
      Reads Kubernetes resources from a file at the specified path.
      Parameters:
      file - The path to the file containing Kubernetes resources.
      Returns:
      A list of HasMetadata resources defined in the file.
      Throws:
      IOException - If an I/O error occurs reading from the file.
    • readResourcesFromFile

      public List<io.fabric8.kubernetes.api.model.HasMetadata> readResourcesFromFile(InputStream is) throws IOException
      Reads Kubernetes resources from an InputStream.
      Parameters:
      is - The InputStream containing Kubernetes resources.
      Returns:
      A list of HasMetadata resources defined in the stream.
      Throws:
      IOException - If an I/O error occurs.
    • pushToStack

      public final void pushToStack(ResourceItem<?> item)
      Pushes a resource item to the stack.
      Parameters:
      item - The resource item to push.
    • pushToStack

      public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void pushToStack(T resource)
      Pushes a resource to the stack.
      Type Parameters:
      T - The type of the resource.
      Parameters:
      resource - The resource to push.
    • printAllResources

      public void printAllResources(org.slf4j.event.Level logLevel)
      Logs all managed resources across all test contexts with set log level
      Parameters:
      logLevel - slf4j log level event
    • printCurrentResources

      public void printCurrentResources(org.slf4j.event.Level logLevel)
      Logs all managed resources in current test context with set log level
      Parameters:
      logLevel - slf4j log level event
    • createResourceWithoutWait

      @SafeVarargs public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void createResourceWithoutWait(T... resources)
      Creates resources without waiting for readiness.
      Type Parameters:
      T - The type of the resources.
      Parameters:
      resources - The resources to create.
    • createResourceWithWait

      @SafeVarargs public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void createResourceWithWait(T... resources)
      Creates resources and waits for readiness.
      Type Parameters:
      T - The type of the resources.
      Parameters:
      resources - The resources to create.
    • createOrUpdateResourceWithWait

      @SafeVarargs public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void createOrUpdateResourceWithWait(T... resources)
      Creates or updates resources and waits for readiness.
      Type Parameters:
      T - The type of the resources.
      Parameters:
      resources - The resources to create.
    • createOrUpdateResourceWithoutWait

      @SafeVarargs public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void createOrUpdateResourceWithoutWait(T... resources)
      Creates or updates resources.
      Type Parameters:
      T - The type of the resources.
      Parameters:
      resources - The resources to create.
    • deleteResource

      @SafeVarargs public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void deleteResource(T... resources)
      Deletes resources.
      Type Parameters:
      T - The type of the resources.
      Parameters:
      resources - The resources to delete.
    • updateResource

      @SafeVarargs public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> void updateResource(T... resources)
      Updates resources.
      Type Parameters:
      T - The type of the resources.
      Parameters:
      resources - The resources to update.
    • waitResourceCondition

      public final <T extends io.fabric8.kubernetes.api.model.HasMetadata> boolean waitResourceCondition(T resource, ResourceCondition<T> condition)
      Waits for a resource condition to be fulfilled.
      Type Parameters:
      T - The type of the resource.
      Parameters:
      resource - The resource to wait for.
      condition - The condition to fulfill.
      Returns:
      True if the condition is fulfilled, false otherwise.
    • deleteResources

      public void deleteResources()
      Deletes all stored resources.