vidispine / hull

The incredible HULL - Helm Uniform Layer Library - is a Helm library chart to improve Helm chart based workflows
https://github.com/vidispine/hull
Apache License 2.0
213 stars 12 forks source link

Generating properties with transformations #266

Closed khmarochos closed 9 months ago

khmarochos commented 9 months ago

Hello again,

I have another newbie question if you please.

Is it possible to generate properties (not only properties' values) in the values set by transformations?

Something like that:

hull:
  object:
    deployment:
      my-cool-deployment:
        pod:
          _HT_ADD_PROPERTIES: _HT!{{ something_that_generates_a_dictionary }}

The _HT_ADD_PROPERTIES could be some code word to let HULL know that we're going to add some properties.

Thank you for your patience and, again, for a really nice tool!

gre9ory commented 9 months ago

Hi @khmarochos,

if I understand correctly you want to create an arbitrary number of properties via a transformation and add them to an (arbitrary) dictionary having the possibility to specify additional keys as well?

If so, that is not possible directly but can be done I think. I'll try to explain using the pod dictionary from above:

Let's assume you have a deployment like this:

hull:
  objects:
    deployment:
      example:
        pod:
          containers:
            main:
              image:
                repository: somerepo
                tag: "latest"

and you want to add some additional properties dynamically to the pod. At the moment there is no way to do that on the pod itself, transformations normally fully replace values and not add key-values to dicts where they are used.

But you can utilize the sources feature for this I think. If you put a transformation for the pod value in another object you don't render but reference as a source, this transformation is evaluated first and afterwards merged with the object which references it as a source under sources:

hull:
  objects:
    deployment:
      pod-values:
        enabled: false
        pod: |-
          _HT!{
            "replicas": 5
          }
      example:
        sources:
        - pod-values
        pod:
          containers:
            main:
              image:
                repository: somerepo
                tag: "latest"

So pod in pod-values is evaluated to replicas: 5 and this replicas: 5 is merged to the definition of example. pod-values deployment is disabled and will not be rendered at all.

In the end you have in the example deployment:

...
    spec:
      containers:
      - env: []
        envFrom: []
        image: somerepo:latest
        name: main
        ports: []
        volumeMounts: []
      imagePullSecrets:
      - name: release-name-hull-test-example-registry
      - name: release-name-hull-test-local-registry
      initContainers: []
      replicas: 5
      serviceAccountName: release-name-hull-test-default
      volumes: []

Hope it brings the idea across, more information on sources is here.

Quite late now so can't add more info at the moment. If you need more support please let me know and I will get back to you right after christmas days. Thanks.

khmarochos commented 9 months ago

I'd like to appreciate the detailed documentation you provided for the project. If I had been more careful, I'd have noticed the sources parameter before. Thank you!