Metadata-Version: 2.1
Name: kubecrd
Version: 0.1.0
Summary: Create Kubernetes CRD using Python dataclasses
Home-page: https://github.com/maxking/kubcrd
License: Apache-2.0
Author: Abhilash Raj
Author-email: raj.abhilash1@gmail.com
Requires-Python: >=3.7,<4
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: PyYAML (>=6.0)
Requires-Dist: apischema (>=0.15.0)
Requires-Dist: kubernetes (>=23.3.0,<24.0.0)
Project-URL: Bug Tracker, https://github.com/maxking/kubecrd/issues
Project-URL: Repository, https://github.com/maxking/kubcrd
Description-Content-Type: text/x-rst

========
Kube CRD
========

The primary purpose of this project is to simplify working with Kubernetes
Custom Resources. To achieve that it provides a base class,
``kubecrd.OpenAPISchemaBase`` that can convert regular Python
dataclassses into Kubernetes Custom Resource Definitions.


  >>> from dataclasses import dataclass, field
  >>> from uuid import UUID
  >>> from kubecrd import OpenAPISchemaBase
  >>> from apischema import schema

  >>> @dataclass
  ... class Resource(OpenAPISchemaBase):
  ...     __group__ = 'example.com'
  ...     __version__ = 'v1alpha1'
  ...
  ...     name: str
  ...     tags: list[str] = field(
  ...         default_factory=list,
  ...         metadata=schema(
  ...            description='regroup multiple resources',
  ...            unique=False,
  ...         ),
  ...     )

  >>> print(Resource.crd_schema())
  apiVersion: apiextensions.k8s.io/v1
  kind: CustomResourceDefinition
  metadata:
    name: resources.example.com
  spec:
    group: example.com
    names:
      kind: Resource
      plural: resources
      singular: resource
    scope: Namespaced
    versions:
    - name: v1alpha1
      schema:
        openAPIV3Schema:
          properties:
            spec:
              properties:
                name:
                  type: string
                tags:
                  default: []
                  description: regroup multiple resources
                  items:
                    type: string
                  type: array
                  uniqueItems: false
              required:
              - name
              type: object
          type: object
      served: true
      storage: true
  <BLANKLINE>


It is also possible to install the CRD in a cluster using a Kubernetes Client
object::

  from from kubernetes import client, config
  config.load_kube_config()
  k8s_client = client.ApiClient()
  Resource.install(k8s_client)

You can then find the resource in the cluster::

  » kubectl get crds/resources.example.com
  NAME                    CREATED AT
  resources.example.com   2022-03-20T03:58:25Z

  $ kubectl api-resources | grep example.com
  resources     example.com/v1alpha1                  true         Resource

Installation of resource is idempotent, so re-installing an already installed
resource doesn't raise any exceptions if ``exist_ok=True`` is passed in::

  Resource.install(k8s_client, exist_ok=True)

