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

uv tool install openshift-python-wrapper

Shell Completion

For enhanced CLI experience, add shell completion to your profile:
# Add to ~/.bashrc or ~/.zshrc
if type class-generator > /dev/null; then 
  eval "$(_CLASS_GENERATOR_COMPLETE=zsh_source class-generator)"
fi

Basic Usage

Generating Classes for Specific Resources

Generate wrapper classes for one or more resource kinds:
class-generator --kind Pod
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

class-generator --help

Overwriting Existing Files

When regenerating or updating existing resource files, use the --overwrite flag with --backup to preserve existing files:
class-generator --kind Deployment --overwrite --backup
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:
class-generator --discover-missing

JSON Output for CI/CD

Generate machine-readable output for automation:
class-generator --discover-missing --json

Disable Cache

Force fresh discovery without using cached results:
class-generator --discover-missing --no-cache
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

Resource Coverage Report

╭─────────────────────────── Coverage Statistics ────────────────────────────╮
│ Total Discovered Resources: 397                                             │
│ Total Implemented: 197                                                      │
│ Covered Resources: 172                                                      │
│ Total Missing: 225                                                          │
│ Coverage Percentage: 43.32%                                                 │
╰─────────────────────────────────────────────────────────────────────────────╯

Missing Resources (sorted by priority)

┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Priority   ┃ Kind                          ┃ API Version                   ┃ Namespaced ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ CORE       │ Binding                       │ v1                            │ Yes        │
│ CORE       │ ComponentStatus               │ v1                            │ No         │
│ HIGH       │ ControllerRevision            │ apps/v1                       │ Yes        │
│ MEDIUM     │ ClusterResourceQuota          │ quota.openshift.io/v1         │ No         │
└────────────┴───────────────────────────────┴───────────────────────────────┴────────────┘

Tip: You can generate multiple resources at once:
  class-generator -k Binding,ComponentStatus,ControllerRevision

Batch Operations

Regenerate All Resources

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

Adding Tests

Automatically generate tests for new resources:
class-generator --kind Pod --add-tests
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:
class-generator --update-schema
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:
class-generator --update-schema-for LlamaStackDistribution
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:
class-generator --kind LlamaStackDistribution --overwrite
--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

class-generator --update-schema-for MyCustomResource
3

Generate the class

class-generator --kind MyCustomResource --add-tests
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

class-generator --update-schema
3

Regenerate all classes

class-generator --regenerate-all --backup
4

Run tests

Run your test suite to verify compatibility

Workflow 3: Coverage Analysis

1

Discover missing resources

class-generator --discover-missing
2

Prioritize resources

Review the report and select high-priority resources
3

Generate selected resources

class-generator --kind Resource1,Resource2,Resource3

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:
kubectl api-resources | grep <kind>
Ensure you have cluster-admin privileges:
kubectl auth can-i get customresourcedefinitions
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

Build docs developers (and LLMs) love