Skip to main content
The class generator is a powerful utility that automatically creates Python wrapper classes for Kubernetes and OpenShift resources based on their CRDs (Custom Resource Definitions). It ensures your wrapper library stays in sync with cluster resources.

Installation

Shell Completion

For enhanced CLI experience, add shell completion to your profile:

Basic Usage

Generating Classes for Specific Resources

Generate wrapper classes for one or more resource kinds:
The generator will:
  • Fetch the resource schema from your cluster
  • Generate a Python class with proper attributes
  • Create the file in the appropriate location (e.g., pod.py, service.py)
Review generated files to ensure naming conventions are correct:
  • OATHoath
  • CDIConfigcdi_config

View All Options

Overwriting Existing Files

When regenerating or updating existing resource files, use the --overwrite flag with --backup to preserve existing files:
Backups are stored in .backups/backup-YYYYMMDD-HHMMSS/ with the original directory structure preserved.

Discovering Missing Resources

The class-generator can automatically discover resources in your cluster that don’t have wrapper classes yet. Discovery runs in parallel for 3-5x faster performance.

Basic Discovery

Discover missing resources and generate a coverage report:

JSON Output for CI/CD

Generate machine-readable output for automation:

Disable Cache

Force fresh discovery without using cached results:
Discovery results are cached for 24 hours in ~/.cache/openshift-python-wrapper/ for improved performance.

Coverage Report

The coverage report provides detailed information about resource implementation status.

Understanding the Report

  • Total Discovered Resources: All resources found in the cluster (including CRDs)
  • Total Implemented: Number of Python wrapper classes in ocp_resources/
  • Covered Resources: Resources that have corresponding wrapper classes
  • Total Missing: Resources without wrapper implementations
  • Coverage Percentage: Percentage of discovered resources with implementations
Resources are prioritized as:
  • CORE: Essential Kubernetes resources (v1 API group)
  • HIGH: Common workload resources (apps/v1, batch/v1)
  • MEDIUM: Platform-specific resources (OpenShift, operators)
  • LOW: Custom resources and less common APIs

Example Output

Batch Operations

Regenerate All Resources

Regenerate all existing wrapper classes (useful after cluster upgrades):
This operation will regenerate all classes. Always use --backup to preserve existing files.

Adding Tests

Automatically generate tests for new resources:
This creates a test file in tests/test_resources/test_pod.py with standard CRUD operations.

Updating Schema Files

Schema files contain resource definitions used by the class generator. Update them from a connected Kubernetes/OpenShift cluster.

Prerequisites

Cluster Access

Kubernetes/OpenShift cluster with admin access

CLI Tools

UV

uv package manager

Full Schema Update

Update the entire schema from the connected cluster:
If connected to an older cluster, existing schemas are preserved and only missing resources are added.

Single Resource Schema Update

Update the schema for a single resource without affecting others:
This is useful when:
  • Connected to an older cluster but need to update a specific CRD
  • A new operator was installed and you need its resource schema
  • You want to refresh just one resource without a full update
After updating the schema, regenerate the class:
--update-schema and --update-schema-for are mutually exclusive. Use one or the other, not both.

Advanced Workflows

Workflow 1: Adding a New CRD

1

Install the operator

Install your operator in the cluster
2

Update the schema

3

Generate the class

4

Review and test

Review the generated class and run tests

Workflow 2: Cluster Upgrade

1

Backup existing classes

Ensure you have version control or backups
2

Update all schemas

3

Regenerate all classes

4

Run tests

Run your test suite to verify compatibility

Workflow 3: Coverage Analysis

1

Discover missing resources

2

Prioritize resources

Review the report and select high-priority resources
3

Generate selected resources

Best Practices

Always Use Backups

Use --backup when overwriting existing files to prevent data loss

Test Generated Classes

Use --add-tests to generate tests for new resources

Keep Schemas Updated

Regularly update schemas after cluster upgrades or operator installations

Review Generated Code

Always review generated classes for naming conventions and correctness

Troubleshooting

Ensure you’re connected to a cluster and the resource exists:
Ensure you have cluster-admin privileges:
The generator uses naming conventions to determine file placement. Check the resource’s API group and version.

Next Steps

Testing

Learn how to test your generated classes with the fake client

Fake Client

Explore the fake Kubernetes client for testing