Skip to main content

No project description provided

Project description

crds-generator

This tool was created to generate a simple kubernetes crds from a pydantic-like object.

You can install it as shown below:

pip install crds-generator

You can create a CRDS with the code below:

from typing import Literal, Optional
import yaml
from crds_generator import CustomResourceDefinition, Schema, generate_crd, AdditionalPrinterColumns 


class Server(Schema):
    name: str
    cpu_type: str
    gpu_type: str
    os: Literal["mac", "linux"]

class Spec(Schema):
    servers: list[Server]
    budget: int

class Status(Schema):
    ping_result: bool

class ServerPool(Schema):
    spec: Spec
    status: Status = None


apc = AdditionalPrinterColumns(
    name="Name",
    type="string",
    description="Server Name",
    jsonPath= ".spec.servers[*].name"
)

print(
    yaml.dump(
        generate_crd(
            CustomResourceDefinition(
                spec={
                    "scope": "Namespaced",
                    "group": "example.com",
                    "names": {
                        "kind": "ServerPool",
                        "plural": "serverpools",
                        "singular": "serverpool",
                        "shortNames": ["sp"],
                    },
                    "versions": [
                        {
                            "name": "v1",
                            "served": True,
                            "storage": True,
                            "schema": ServerPool,
                            "additionalPrinterColumns": [
                                apc
                            ],
                        }
                    ],
                },
            )
        )
    )
)

then print

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: serverpools.example.com
spec:
  group: example.com
  names:
    kind: ServerPool
    plural: serverpools
    shortNames:
    - sp
    singular: serverpool
  scope: Namespaced
  versions:
  - additionalPrinterColumns:
    - description: Server Name
      jsonPath: .spec.servers[*].name
      name: Name
      type: string
    name: v1
    schema:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              budget:
                type: integer
              servers:
                items:
                  properties:
                    cpu_type:
                      type: string
                    gpu_type:
                      type: string
                    name:
                      type: string
                    os:
                      enum:
                      - mac
                      - linux
                      type: string
                  required:
                  - name
                  - cpu_type
                  - gpu_type
                  - os
                  type: object
                type: array
            required:
            - servers
            - budget
            type: object
          status:
            properties:
              ping_result:
                type: boolean
            required:
            - ping_result
            type: object
        required:
        - spec
        type: object
    served: true
    storage: true

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crds_generator-0.0.5.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crds_generator-0.0.5-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file crds_generator-0.0.5.tar.gz.

File metadata

  • Download URL: crds_generator-0.0.5.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for crds_generator-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6f8d19ac85f5762cac38aef04e3b22853d8f5f7594746e393160afc16160bd71
MD5 a46f31e8aabc3a417dab46c67a46e633
BLAKE2b-256 58830230c8fbd14373f5570967cfcc688ff3a550d82169fcc04d6f637ba1a9c5

See more details on using hashes here.

File details

Details for the file crds_generator-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: crds_generator-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for crds_generator-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 876fd39ec800119b65b40224a12345d0392d5e0a489e36c632892825ceabb23e
MD5 078c42777004ec0e4086b63daa6bcba0
BLAKE2b-256 c9532b18e48a2c396b214c6d17c3902e859a1503a184fd01f068af1f6d24ccc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page