tazjin/kontemplate

Add --include-file / --exclude-file for specific files in resource sets

Closed this issue · 8 comments

This is allowed with regular kubectl:

$ kubectl apply -f path/to/file-deploy.yaml

These don't seem to work:

$ kontemplate template beta-cluster.yaml -i path/to/file-deploy.yaml
 │Loading resources for path/to/file-deploy.yaml 

$ kontemplate template beta-cluster.yaml -i path/to/file-deploy
 │Loading resources for path/to/file-deploy

Meaning, they don't output the rendered file.

I attempted with the following beta-cluster.yaml:

---
context: lala
include:
  - name: path/to
    values:
      lala: land

  - name: path/to/file-deploy
    values:
      configStuff: stuff

  - name: path/to/file-deploy.yaml
    values:
      configStuff: stuff

Currently include/exclude works on resource sets (i.e. the whole folder containing resources and potentially default values).

I could theoretically extend that to allow targeting specific files but there are a few considerations (do default vars still get loaded from the files basedir?) that I need to think about.

Well I would assume no since that's what globals are for?

  - name: some-api/hello
    values:
      version: 1.0-0e6884d
      importantFeature: true
      apiPort: 4567

some-api/lala would not inherit variables from some-api/hello. I do think this feature is needed since kubectl allows it. I also think kubectl replace is idempotent when you write over with the same config unless you do add the --force label, then it deletes and adds the new resource.

Hmm, so you want to specify individual files inside a resource set in the context file? Why not just split them in separate resource sets then?

To elaborate, kontemplate does not call kubectl on a file - it renders the templates inside the resource set and passes them to the stdin of kubectl.

I also think kubectl replace is idempotent when you write over with the same config

Not entirely sure about this, I almost always apply with apply because that will normally do the correct thing :-)

Hmm, so you want to specify individual files inside a resource set in the context file? Why not just split them in separate resource sets then?

Well it makes sense to place them under the same folder but occasionally you'll make a change to stuff-deployment.yaml but not stuff-service.yaml, and thus you only want to apply stuff-deployment.

Okay, but in that case I assume you'd want to use the --include | --exclude flags on the CLI as a one-off, rather than specifying that specific file in the cluster context?

It is definitely useful to have support for individual files. My project is oriented per app (microservice) and I want the resource definition inside each directory. But the microservice directories also (potentially) contain lots of other JSON/YML files such as package.json. This is now presumed to be a resource definition but there appears to be absolutely no way around this. I cannot exclude any files, and I cannot selectively include specific files.

The project claims "no file naming conventions enforced at all", but there are definitely big assumptions on how the directories are structured (i.e. they must only contain resource definitions, or at least no other YML/JSON files since they cannot be excluded). This is not obvious from the documentation.

Hello!
Any update on this?

The source of kontemplate is moving to git.tazj.in and I've moved this issue to the depot@tazj.in mailing list over here.