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.3.tar.gz
(2.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crds_generator-0.0.3.tar.gz.
File metadata
- Download URL: crds_generator-0.0.3.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
716410c6e729c641cee8375e50635c3058c98b38818ddcd92b1f3d2e8a7024b1
|
|
| MD5 |
0ccd81edfca46d5f7c9892c269cf275c
|
|
| BLAKE2b-256 |
9788a168341105291f8836407579fe972a3cd9b3df72e5b3ff3baec7840dd34e
|
File details
Details for the file crds_generator-0.0.3-py3-none-any.whl.
File metadata
- Download URL: crds_generator-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c09c67aef29ab1cca5182d3040f0136ea08c43ae4f80ac8927772d749b09f1d7
|
|
| MD5 |
f1f37cd605b2957c09213fee7c387ebf
|
|
| BLAKE2b-256 |
67b15a00d3657ad7868cbdb4ee44f56b9d645022ebeed9c5f75031abe5ab8643
|