fix: New cleanup when using --cleanup flag (#1406) #2783
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1406
Description
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Reviewer Notes
** Notes**
Flag cleanup does not clean kaniko root directory (default /kaniko). As a result, when building more than one image on same kaniko container we can face the problem of leftovers directories like
/kaniko/0/...
which are stage-dependent files (https://github.com/GoogleContainerTools/kaniko/blob/v1.16.0/pkg/executor/build.go#L807) saved by kaniko.New function CleanupFilesystem() first calls DeleteFilesystem() and then removes all files and directories from kaniko root directory with names are digits. Those files are directories that store stage-dependent files and snapshots.
This fix can be also achieved in different way. All snapshot can be placed in kanikoDir/snapshots and layers dependent files in kanikoDir/layers and then CleanupFilesystem() could simply call os.RemoveAll() on those directories instead of this logic with regex.
Described also in issue #1406
I'm open to discussion.