<#22445 Add support for Custom Resource Definition...
# github-notifications
c
#22445 Add support for Custom Resource Definitions Issue created by tim-werner Is your feature request related to a problem? Please describe. Currently, pants only supports standard kubernetes resources to infer dependencies for helm_deployment targets. Describe the solution you'd like Allow to add CRD definitions to pants. Pants is currently using hikaru to parse the manifest.yaml file. hikaru supports the creation of CRDs. It would be great if pants allows to define CRDs for hikaru in python and than load it dynamically into pants and register it. I would like to have an option in the
pants.toml
like:
Copy code
[helm_deployment]
crd = ["path_to_crd_definition.py"]
and/or in the target `helm_deployment`:
Copy code
helm_deployment(crd=["path_to_crd_definition.py"])
Additional context I try to use pants with argo-worflows but because this is not a standard kubernetes definition pants is not able to infer the dependencies. I have played around a little bit with pants and was able to hack the support of CRDs into my local pants. As a proof-of-concept I have added following line to my local pants source. I have added following lines to `k8s_parser.py`:
Copy code
crd_sources = open("pantsbuild/crd_cron.py", 'rb').read() 
    if not crd_sources:
        raise ValueError(
            f"Unable to find source to crd_cron"
        )
    parser_file_content_source = FileContent(
        path="__crd_source.py", content=crd_sources, is_executable=False
    )
to include the CRD definiton that is located in my monorepo. In addition I had to add to `k8s_parser_main.py`:
Copy code
try:
        import __crd_source
        register_crd_class(__crd_source.MyPlatform, "crd", is_namespaced=False)
    except ImportError as e:
        print(f"WARN: No CRD defined: {e}", file=sys.stderr)
within the main function. The crd_cron.py file looks like this:
Copy code
from __future__ import annotations
from hikaru.model.rel_1_28.v1 import *

from hikaru import (HikaruBase, HikaruDocumentBase,
                    set_default_release)
from hikaru.crd import HikaruCRDDocumentMixin
from typing import Optional, List
from dataclasses import dataclass

set_default_release("rel_1_28")
@dataclass
class ContainersSpec(Container):
   name: Optional[str]

@dataclass
class TemplatesSpec(HikaruBase):
    name: str
    container: Optional[ContainersSpec]

@dataclass
class WorkflowSpec(HikaruBase):
    templates: List[TemplatesSpec]

@dataclass
class MyPlatformSpec(HikaruBase):
    workflowSpec: WorkflowSpec


@dataclass
class MyPlatform(HikaruDocumentBase, HikaruCRDDocumentMixin):
    metadata: ObjectMeta
    apiVersion: str = f"<http://argoproj.io/v1alpha1|argoproj.io/v1alpha1>"
    kind: str = "CronWorkflow"
    spec: Optional[MyPlatformSpec] = None
This is all very hacky but I hope the idea is clear... pantsbuild/pants