Skip to main content
This guide will help you perform your first operations with the OpenShift Python Wrapper. You’ll learn how to connect to a cluster, create resources, and use the wrapper’s key features.

Prerequisites

1

Ensure Python 3.10+ is installed

2

Install the library

3

Configure cluster access

Ensure you have a valid kubeconfig file or cluster credentials. Test your connection:

Your First Resource

Let’s create a simple Namespace resource to understand the basic workflow.
The context manager pattern (with statement) is recommended as it ensures automatic resource cleanup, even if an error occurs.

Working with Pods

Pods are fundamental workload resources. Here’s how to create and interact with them:

Working with Deployments

Deployments manage replica sets and pod lifecycles:

Advanced Patterns

Using Resource Body

For complex resources, you can provide a complete body dictionary:

Creating Multiple Resources

Use ResourceList to create multiple similar resources efficiently:

Resource with Different API Groups

Some resources exist in multiple API groups:

Schema Validation

The wrapper includes built-in schema validation to catch errors early:

Common Operations

Wait for Conditions

Wait for resources to reach desired states:

Resource Discovery

Query and filter resources:

Resource Updates

Update existing resources:

Error Handling

Handle common scenarios gracefully:

Testing with Fake Client

Write tests without requiring a real cluster:

Best Practices

Always prefer context managers (with statements) for automatic cleanup:
Catch configuration errors early:
Don’t assume immediate availability:
Set realistic timeouts based on resource type:
Ensure resources are cleaned up even on errors:

Next Steps

Core Concepts

Learn about resources, namespaces, and context managers

API Reference

Explore all available resource classes and methods

Advanced Testing

See real-world examples and patterns

Fake Client

Learn how to test your code with the fake client

API Reference

Explore all available resource classes and methods

Class Generator

Auto-generate resource wrappers

Testing Guide

Learn how to test your code with the fake client