cool-easter-32542
07/01/2025, 3:07 PMpants.toml like:
[helm_deployment]
crd = ["path_to_crd_definition.py"]
and/or in the target `helm_deployment`:
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`:
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`:
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:
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