Hi, I cannot get pants to infer dependencies for a...
# general
b
Hi, I cannot get pants to infer dependencies for a
helm_deployment
target. I have added the docker_image target to the
values
in the `helm_deployment`as described in the documentation. When I add the target explicitly as a dependency pants will build the docker image but it will not replace the image with the actually image (pants seems to treat it as a normal string)
Copy code
helm_chart(
    name = 'test',
)
helm_deployment(
    name = 'test-preview',
    chart = ':test',
    sources = [
        'values.yaml',
        'values.preview.yaml',
    ],
    values = {"test-loader.image": "load/test:test_docker"},
    namespace= 'test-preview',
)
load/test/BUILD
Copy code
docker_image(
    name="test_docker",
    build_platform=["linux/amd64"],
    image_tags=["1.0", "latest"],
)
I did some further digging and it seems that pants is not just using the values.yamls to infer the dependencies.
Okay. I think I found the issue but I do not know how to solve. It only seems to work for standard kubernetes resources. It does not work for custom resource definition. I use argo-workflow and even the most simple helm chart will not work with it.
is there a way to "enable" custom resource definitions?
This works:
Copy code
---
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  labels:
    chart: "test"
spec:
  containers:
    - name: my-app
      # Uses the `image` value entry from the deployment inputs
      image: {{ index .Values "test-loader" "image" }}
This does not work:
Copy code
---
apiVersion: <http://argoproj.io/v1alpha1|argoproj.io/v1alpha1>
kind: CronWorkflow
metadata:
  name: my-pod
  labels:
    chart: "test"
spec:
  containers:
    - name: my-app
      # Uses the `image` value entry from the deployment inputs
      image: {{ index .Values "test-loader" "image" }}
b
The image parsing for inference happens in k8s_parser_main.py which uses hikaru for the actual parsing. According to this comment, hikaru only supports well known resource types: `# Hikaru fails with a
RuntimeError
when it finds a K8S manifest for an`
# API version and kind that doesn't understand.
Did you try explicitly adding your images to the
dependencies
field of the
helm_deployment
target?
b
yes I have added the images explicitly to the
dependencies
field of the
helm_deployment
target. Pants knows than to build the docker images but unfortunately it will still not be added to the kubernetes deployment
However, maybe it is possible because according to the docu:
Create Custom Resource Definitions
As of release 1.0.0, Hikaru supports the creation of CRDs that integrate with the rest of Hikaru. Automatically generate schema from a Hikaru class, define CRDs to Kubernetes, manage CRD instances with CRUD methods, and create watchers that allow you to build your own controllers for your CRDs.
I was able to define the CRD in pants and it works with the local pants installation. 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 have added following code to
k8s_parser_main.py
and it is able to infer the dependencies and render the helm charts correctly.
Copy code
from hikaru.model.rel_1_28.v1 import *
from hikaru import (HikaruBase, HikaruDocumentBase,
                    set_default_release)
from hikaru.crd import register_crd_class, HikaruCRDDocumentMixin
from typing import Optional, List
from dataclasses import dataclass

set_default_release("rel_1_28")
plural = "myplatforms"
@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


register_crd_class(MyPlatform, plural, is_namespaced=False)
👍 1