patrickdappollonio / kubectl-slice

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.
MIT License
297 stars 23 forks source link

Allow pruning contents of directory #112

Closed reegnz closed 8 months ago

reegnz commented 8 months ago

What did you do?

I sliced the output of a kustomize build into separate files. Later I sliced a newer version of the kustomize build, with fewer resources, but the files for the old resources missing from the new output were not pruned by kubectl-slice.

What did you expect to see?

I expected the slice to only retain files that came from the input file, and clean up (prune) files that don't belong there. I hoped that it's just hidden behind a flag (eg. --prune), but no dice. So best thing I could do is to wrap kubectl-slice with a custom shell script and do the pruning around kubectl-slice. It would be great if the tool could itself prune and I wouldn't need to wrap it with a shell script.

What did you see instead?

No pruning. :(

patrickdappollonio commented 8 months ago

Hey!

This is good info, thanks a lot for the detailed notes! Just to clarify, you would like to see a way to delete the target folder contents whenever you rerun it, right?

There are a few challenges to do it by default, considering it could break old behaviour so I think it would be good to have a --prune option, that way it remains opt-in.

I have seen genuine interactions of not wanting to prune too, for example, if in some cases you have had a behaviour that downloads certain manifests and you want to slice multiple times, then the aggregated output can be used in a one-run kubectl apply -f path/to/location/.

All of that to say, I'll add the --prune flag, seems straightforward and a great idea 😁

reegnz commented 8 months ago

I think it is not necessary to have it do pruning by default, but having a --prune flag would definitely help!

patrickdappollonio commented 8 months ago

Here you go friend, version 1.2.9 is out with the new feature included. Test it out and please let me know what you think!

I'll keep this issue open for the time being.

Thank you for the request!

reegnz commented 8 months ago

Thanks! Will test drive it this week.

reegnz commented 8 months ago

Works great, I think this can be resolved.