Package io.skodjob.testframe.resources
Class KubeResourceManager
java.lang.Object
io.skodjob.testframe.resources.KubeResourceManager
Manages Kubernetes resources for testing purposes.
-
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddCreateCallback(Consumer<io.fabric8.kubernetes.api.model.HasMetadata> callback) Add callback function which is called after creation of every resourcefinal voidaddDeleteCallback(Consumer<io.fabric8.kubernetes.api.model.HasMetadata> callback) Add callback function which is called after deletion of every resourcefinal <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voidcreateOrUpdateResourceWithoutWait(T... resources) Creates or updates resources.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voidcreateOrUpdateResourceWithWait(T... resources) Creates or updates resources and waits for readiness.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voidcreateResourceWithoutWait(T... resources) Creates resources without waiting for readiness.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voidcreateResourceWithWait(T... resources) Creates resources and waits for readiness.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voiddeleteResource(T... resources) Deletes resources.voidDeletes all stored resources.static KubeResourceManagerRetrieves the singleton instance of KubeResourceManager.static KubeClientRetrieves the Kubernetes client.static KubeCmdClient<?>Retrieves the Kubernetes command-line client.static org.junit.jupiter.api.extension.ExtensionContextRetrieves the test context.voidprintAllResources(org.slf4j.event.Level logLevel) Logs all managed resources across all test contexts with set log levelvoidprintCurrentResources(org.slf4j.event.Level logLevel) Logs all managed resources in current test context with set log levelfinal voidpushToStack(ResourceItem<?> item) Pushes a resource item to the stack.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voidpushToStack(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>readResourcesFromFile(Path file) Reads Kubernetes resources from a file at the specified path.final voidsetResourceTypes(ResourceType<?>... types) Sets the resource types.static voidsetTestContext(org.junit.jupiter.api.extension.ExtensionContext context) Sets the test context.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
voidupdateResource(T... resources) Updates resources.final <T extends io.fabric8.kubernetes.api.model.HasMetadata>
booleanwaitResourceCondition(T resource, ResourceCondition<T> condition) Waits for a resource condition to be fulfilled.
-
Method Details
-
getInstance
Retrieves the singleton instance of KubeResourceManager.- Returns:
- The singleton instance of KubeResourceManager.
-
getKubeClient
Retrieves the Kubernetes client.- Returns:
- The Kubernetes client.
-
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
Sets the resource types.- Parameters:
types- The resource types implementingResourceType
-
addCreateCallback
Add callback function which is called after creation of every resource- Parameters:
callback- function
-
addDeleteCallback
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
HasMetadataresources 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
HasMetadataresources defined in the stream. - Throws:
IOException- If an I/O error occurs.
-
pushToStack
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.
-