Skip to main content
The fake Kubernetes client provides a complete mock implementation of the Kubernetes dynamic client, allowing you to test Kubernetes-related code without needing an actual cluster.

Features

Full CRUD Operations

Create, Read, Update, and Delete operations for all resources

Custom Resources

Support for standard Kubernetes resources and CRDs

Label & Field Selectors

Filter resources using labels and field selectors

Watch Operations

Watch functionality with event generation

Realistic Status

Automatic status generation for resources

Namespace Support

Full namespace isolation and management

Installation & Setup

The fake client is included with openshift-python-wrapper. To use it in your tests:

Basic Usage

Creating Resources

Create resources using standard Kubernetes manifests:

Listing Resources

Updating Resources

Deleting Resources

Watch Operations

Configuring Resource Ready Status

You can configure resources to be in a “not ready” state for testing failure scenarios.

Using Annotations

Add the fake-client.io/ready annotation to any resource:
For Pods specifically, you can also use fake-client.io/pod-ready annotation for backward compatibility.

Using Spec Field

Alternatively, use readyStatus in the spec:

Resource-Specific Behavior

Different resources behave differently when not ready:
Show as not ready with containers in waiting state:
  • status.phase: Pending
  • Container states show as waiting
  • Ready condition is False
Show 0 ready replicas and unavailable condition:
  • status.readyReplicas: 0
  • status.availableReplicas: 0
  • Available condition is False
Show as Terminating phase:
  • status.phase: Terminating
Show Ready condition as False:
  • Ready condition set to False
  • Resource-specific status fields reflect not-ready state

Custom Resources

The fake client automatically supports any Custom Resource:

Advanced Features

Automatic Namespace Creation

Namespaces are automatically created when you create resources in non-existent namespaces:

Realistic Resource Status

Resources automatically get realistic status fields:

OpenShift Resources

The client includes OpenShift-specific resources:

Testing Patterns

Using Pytest Fixtures

Testing Resource Lifecycle

Testing Error Conditions

Limitations

The fake client is designed for testing and has some limitations:
No real networking or pod execution occurs. Containers don’t actually run.
Watch implementation provides immediate events only, not continuous streaming.
Only metadata.name and metadata.namespace field selectors are supported.
No admission webhooks or validation beyond basic structure checking.
Status updates are simplified and may not reflect all real-world complexities.

Complete Testing Example

Next Steps

Testing Guide

Learn comprehensive testing patterns and best practices

Class Generator

Generate wrapper classes for your resources