kapitan icon indicating copy to clipboard operation
kapitan copied to clipboard

Targets ordering or/and dependencies

Open eug-maly opened this issue 4 years ago • 5 comments

Describe the bug/feature We have a target where we generate grafana dashboards (for example). We tried to use these templates as an input in other targets to create kubernetes configmaps. But didn't find a way to force this target to be the first one (added "00-" prefix to the name, etc). It would be nice control the target generation orders or to add target generation dependencies.

To Reproduce Steps to reproduce the behavior:

  1. Create a target with the name 00-target. create other targets
  2. run kapitan compile
  3. Output of the command shows that some other targets were generated before 00-target.

Expected behavior 00-target should be generated the first.

eug-maly avatar Sep 25 '20 08:09 eug-maly

Maybe you can try to compile the target with grafana configurations first using $ kapitan compile -t <grafana-target-name> and then use $ kapitan compile to compile all the targets. Alternatively, you can try labeling your targets under parameters.kapitan.labels e.g.

parameters:
  kapitan:
    compile: ...

    labels:
      type: grafana
parameters:
  kapitan:
    compile: ...

    labels:
      type: kubernetes

And then use $ kapitan compile -l type=grafana followed by $ kapitan compile -l type=kubernetes

royari avatar Sep 25 '20 09:09 royari

@eug-maly curious to know why you have a dependency on the order of compilation? You can always iterate through compiled target names and match/order externally. Alternatively, you should consider @AlphaRoy14 suggestion if you're ok with multi stage compilation.

ramaro avatar Sep 25 '20 12:09 ramaro

@ramaro here is an example:

  1. generate grafana dashboards using jsonnet
  2. use dashboards from p.1 to generate kubernetes configmaps
  3. apply changes to kubernetes clusters

eug-maly avatar Sep 29 '20 16:09 eug-maly

@eug-maly If you want, the grafana dashboards and k8s configmaps could each be there own class. The compile stage of a target has a few phases listed here in the docs: https://github.com/deepmind/kapitan/blob/master/docs/compile.md#phases-of-the-compile-command

What you could do is ensure that the grafana class is run first through ordering it before the k8s configmap class in your target definition file. As a part of the k8s configmap class you could reference the generated grafana dashboards as an input:

# k8s-configmap.yml
parameters:
  kapitan:
    vars:
      target: ${target_name}
    compile:
      - input_type: copy
        input_paths:
          - compiled/${kapitan:vars:target}/grafana-dashboards/configmap.yml
        output_path: .

sebradloff avatar Oct 01 '20 13:10 sebradloff