Skip to content

Library for easy testing of kubernetes deployments and operators using fabric8 api

License

Notifications You must be signed in to change notification settings

skodjob/test-frame

TEST-FRAME

Library for easy testing of Kubernetes deployments and operators using Fabric8 API.

Build Publish-snapshot License GitHub Release Maven Central Version

Provided functionality

Kubernetes resource manager

KubeResourceManager provides management of resources created during test phases. Every Kubernetes resource created by KubeResourceManager is automatically deleted at the end of the test, whether the test passed or failed. So the Kubernetes environment is clean before and after every test run and user do not need to handle it. Working with Kubernetes resources using KubeResourceManager also provides proper wait for resource readiness.

Fabric8 Kubernetes client and CMD client

Instance of KubeResourceManager contains accessible fabric8 kubernetes client and kubernetes cmd client. These clients are initialized and connected to the test cluster based on the configuration provided by the env file, env variables, or kubeconfig.

Test visual separation

For better clarity regarding the test logs, TestFrame library provides ASCII vial separation of tests and test classes.

Metrics Collector

The MetricsCollector is designed to facilitate the collection of metrics from Kubernetes pods. It integrates seamlessly with Kubernetes environments to gather and process metrics data efficiently. For more detailed documentation, see the MetricsCollector README.

Log Collector

LogCollector is utility for collecting logs from the Pods (and their containers), descriptions of Pods, and YAML descriptions of resources specified by users, collected from the desired Namespaces. To Log Collector's README contains detailed documentation about this component, together with the usage and installation.

Utils

TestFrame contains also tweaks and utils for better working with kubernetes cluster.

Usage

Include dependency to your maven test project

<dependency>
    <groupId>io.skodjob</groupId>
    <artifactId>test-frame-common</artifactId>
</dependency>

Use annotations for working with KubeResourceManager or other provided functionality

//...
@ResourceManager
@TestVisualSeparator
class Test {
    //...
}
//...

To disable KubeResourceManager clean resources functionality

//...
@ResourceManager(cleanResources = false)
@TestVisualSeparator
class Test {
    //...
}
//...

Work with KubeResourceManager and clients

//...
@ResourceManager
class Test {
    @Test
    void testMethod() {
        KubeResourceManager.getInstance().createResourceWithWait(
                new NamespaceBuilder().withNewMetadata().withName("test").endMetadata().build());
        assertNotNull(KubeResourceManager.getKubeCmdClient().get("namespace", "test"));
    }
}
//...

Register ResourceType or NamespacedResourceType classes into KubeResourceManager

KubeResourceManager.getInstance().setResourceTypes(
        new NamespaceType(),
        new JobType(),
        new NetworkPolicyType()
);

Examples

Examples are stored in test-frame-test-examples module.

Config environment variables

  • ENV_FILE - path to YAML file with env variables values
  • KUBE_TOKEN - token of Kube access (use instead of username/password)
  • KUBE_URL - URL of the cluster (API URL)
  • CLIENT_TYPE - Switch between kubectl or oc cmd client

Adopters

Maintainers