While dealing writing Kubernetes Operators we often need to write tests for scenarios where we are manipulating Kubernetes APIs and want to verify behavior of our Kubernetes controllers. It’s quite tedious and resource consuming to run your tests on a Kubernetes Cluster every time. Fabric8 Kubernetes Client provides us an extension with which you can mock Kubernetes API server and do your work. In this blog, I would be giving you an overview of mocking and writing tests for you Kubernetes controllers using Fabric8 Kubernetes Mock Server. It’s a library based on Fabric8 Kubernetes Client and Fabric8 Mockwebserver(extension of OkHttp’s mockwebserver) which provides us smooth dsl for mocking operations.

Fabric8 Kubernetes Java library

Fabric8 Kubenetes Java library

fabric8io/kubernetes-client

This client provides access to the full Kubernetes & OpenShift REST APIs via a fluent DSL.

github.com

Installing Fabric8 Kubernetes Mock Server in your project:

You can add Fabric8 Kubernetes Mock Server in your project by adding it as a dependency in your pom.xml :

<dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-server-mock</artifactId>
    <version>${kubernetes-server-mock.version}</version>
</dependency>

#java #testing #mock #kubernetes #kubernetes-api

Mock Kubernetes API server in Java using Fabric8 Kubernetes Mock Server
12.45 GEEK