kpt
kpt copied to clipboard
Provide a way to ignore files or directories
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.
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()
.
@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?
I think it would work! Happy to test it out once it lands. Thanks!
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 live
however will choke on skaffold.yaml unless I include it in the .krmignore file. However, this prevents kpt cfg
from working.
Is it possible to ignore files for
kpt live
but notkpt cfg set
?My use case is using skaffold GoogleContainerTools/skaffold#3904 and
kpt live
. My kpt package contains askaffold.yaml
. I want to use kpt setters inside my skaffold.yaml so I can consistently set the docker image.kpt live
however will choke on skaffold.yaml unless I include it in the .krmignore file. However, this preventskpt cfg
from working.
Replied in GoogleContainerTools/skaffold#3904.
when this is solved are you expecting that it will be possible to run
"kpt pkg get"
for a directory and not include subdirectories?
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
Hi, Let me add few more cases
-
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.
-
kpt live apply
I may have YAMLs that I don't want to apply, instead I want to include into other yamls duringkpt 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 sectionpkg
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 sectionlive
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 functionkpt pkg
-
.kptliveignore
- ignore for functionkpt live
-
.kptfnignore
- ignore for functionkpt fn
-
.kptpkggetignore
- maybe even like this, ignore forkpt pkg get
function
Thank you for the inputs @marniks7 !
- Have you tried the
.krmignore
solution @mortent provided? Basically users may still have some files unexpected fromkpt pkg get
, but those won't take effect inkpt fn
andkpt live
. - 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 namedgcr.io/kpt-fn/set-annotations
to specifically add all Chaos Mesh resources alocal-config
annotation
Hi @yuwenma ,
- I have tested before with
.krmignore
forkpt fn
- it worked out. forkpt pkg get
it doesn't https://github.com/marniks7/chaos-catalog/tree/master/54-kpt-pkg-get-with-krmignore - 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