kpt icon indicating copy to clipboard operation
kpt copied to clipboard

Provide a way to ignore files or directories

Open wstrange opened this issue 4 years ago • 10 comments

We have legacy helm/ directories in our project that cause kpt parsing errors due to Go templates in the yaml files.

We'd like to be able to tell Kpt to ignore sub-directories. Perhaps something like a .kptignore file, with globs for patterns to ignore.

wstrange avatar Apr 14 '20 18:04 wstrange

For implementing the ignore functionality of kpt live part of this, we'll need to update the apply pre-processor hook (which already does ordering and inventory object manipulation) to do filtering of files to ignore. This code lives in cli-utils/pkg/apply/applier.go:readAndPrepareObjects().

seans3 avatar Apr 21 '20 19:04 seans3

@wstrange I have a PR to add support for an ignore file as part of a kpt package at https://github.com/kubernetes-sigs/kustomize/pull/2898. When we pull this into kpt, the name of the file might be .kptignore instead of .krmignore, but the functionality should be the same. Does it look like this would fix your issue?

mortent avatar Aug 27 '20 16:08 mortent

I think it would work! Happy to test it out once it lands. Thanks!

wstrange avatar Aug 27 '20 18:08 wstrange

Is it possible to ignore files for kpt live but not kpt cfg set?

My use case is using skaffold GoogleContainerTools/skaffold#3904 and kpt live. My kpt package contains a skaffold.yaml. I want to use kpt setters inside my skaffold.yaml so I can consistently set the docker image. kpt livehowever will choke on skaffold.yaml unless I include it in the .krmignore file. However, this prevents kpt cfg from working.

jlewi avatar Nov 18 '20 14:11 jlewi

Is it possible to ignore files for kpt live but not kpt cfg set?

My use case is using skaffold GoogleContainerTools/skaffold#3904 and kpt live. My kpt package contains a skaffold.yaml. I want to use kpt setters inside my skaffold.yaml so I can consistently set the docker image. kpt livehowever will choke on skaffold.yaml unless I include it in the .krmignore file. However, this prevents kpt cfg from working.

Replied in GoogleContainerTools/skaffold#3904.

yuwenma avatar Dec 03 '20 07:12 yuwenma

when this is solved are you expecting that it will be possible to run

"kpt pkg get"

for a directory and not include subdirectories?

fritchie avatar Jun 15 '21 21:06 fritchie

Note: the config.kubernetes.io/local-config: "true" annotation should cause kpt live to ignore KRM-like config files with the annotation (in addition to ones it has built-in knowledge of, like Kptfile). #1064

bgrant0607 avatar Jul 09 '21 22:07 bgrant0607

Hi, Let me add few more cases

  1. kpt pkg get will download ALL files in the repository. This is not cool at all. e.g. I may have my IDE files inside, some scripts, Makefiles, Markdown, etc. WA: move Kptfile and everything to separate folder and don't put there any other resources. This doesn't look good to create such hierarchies for such reason

Note: most of the time I want to provide many of those files to user via kpt pkg get, but I want to control the list.

  1. kpt live apply I may have YAMLs that I don't want to apply, instead I want to include into other yamls during kpt fn.

That kind of yaml can be Chaos Mesh yaml which I want to include to Tekton to Target different namespace. Despite having WA (config.kubernetes.io/local-config: "true" - this file is not local-config and I don't want to see that inside my yaml and set that to every Chaos Mesh yaml file. Note: this file should be retrieved by kpt pkg, processed by kpt fn, but not by kpt live

kind: PodChaos
apiVersion: chaos-mesh.org/v1alpha1
metadata:
  namespace: $(params.namespace)
  name: pod-kill
spec:
  selector:
    namespaces:
      - $(params.namespace)
    labelSelectors:
      app.kubernetes.io/component: master
      app.kubernetes.io/name: redis
  mode: one
  action: pod-kill
  gracePeriod: 0

Possible solutions

  • Option#1 - Adding ignore to Kptfile for kpt pkg Applied to section pkg
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
  name: example
pipeline:
  pkg:
    - function: ignore
      configMap:
        resources:
          - '*.iml'
          - '*.idea'
          - 'Makefile'
  • Option#1 - Adding ignore to Kptfile for kpt live Applied to section live
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
  name: example
pipeline:
  live:
    - image: gcr.io/kpt-fn/ignore
      configMap:
        group: chaos-mesh.org

Cons: This list can be way too big and ugly especially for pkg

  • Option#2 - Creating separate file .Kptignorefile
apiVersion: kpt.dev/v1alpha
kind: Kptignorefile
metadata:
  name: example
pipeline:
  all:
  - function: ignore
    configMap:
       resources:
          - '*.iml'
          - '*.idea'
          - 'Makefile'  
  pkg:
    - function: ignore
      configMap:
        resources:
          - 'script.sh'
  live:
    - function: ignore
      configMap:
        resources:
          - 'skaffold.yaml'
  • Option#3 - Multiple ignore files
  • .kptignore - global ignore for everything
  • .kptpkgignore - ignore for function kpt pkg
  • .kptliveignore - ignore for function kpt live
  • .kptfnignore - ignore for function kpt fn
  • .kptpkggetignore - maybe even like this, ignore for kpt pkg get function

marniks7 avatar Aug 26 '22 02:08 marniks7

Thank you for the inputs @marniks7 !

  1. Have you tried the .krmignore solution @mortent provided? Basically users may still have some files unexpected from kpt pkg get, but those won't take effect in kpt fn and kpt live.
  2. KRM resources with "local-config" annotation will not be applied but will be include in kpt fn. If you think it's too much work to set the local-config to each Chaos Mesh, you can try a KRM function named gcr.io/kpt-fn/set-annotations to specifically add all Chaos Mesh resources a local-config annotation

yuwenma avatar Aug 26 '22 03:08 yuwenma

Hi @yuwenma ,

  1. I have tested before with .krmignore for kpt fn - it worked out. for kpt pkg get it doesn't https://github.com/marniks7/chaos-catalog/tree/master/54-kpt-pkg-get-with-krmignore
  2. set-annotations looks good. https://github.com/marniks7/chaos-catalog/tree/master/53-set-annotations p.s. For perfect solution I would prefer to remove local-config on-the-fly before including into another yaml image

marniks7 avatar Aug 28 '22 16:08 marniks7