fix: New cleanup when using --cleanup flag (#1406)
This commit is contained in:
parent
d070187005
commit
a0615c88aa
|
|
@ -787,7 +787,7 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
|
|||
}
|
||||
}
|
||||
if opts.Cleanup {
|
||||
if err = util.DeleteFilesystem(); err != nil {
|
||||
if err = util.CleanupFilesystem(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
|
@ -228,6 +229,30 @@ func GetFSFromLayers(root string, layers []v1.Layer, opts ...FSOpt) ([]string, e
|
|||
return extractedFiles, nil
|
||||
}
|
||||
|
||||
// CleanupFilesystem deletes the extracted image file system, snapshots and stage dependent files
|
||||
func CleanupFilesystem() error {
|
||||
DeleteFilesystem()
|
||||
logrus.Info("Deleting snapshots and layer dependet files...")
|
||||
numericPattern := regexp.MustCompile(`^\d+$`)
|
||||
return filepath.Walk(config.KanikoDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
// ignore errors when deleting.
|
||||
return nil //nolint:nilerr
|
||||
}
|
||||
|
||||
if numericPattern.MatchString(info.Name()) && isExist(path) {
|
||||
err := os.RemoveAll(path)
|
||||
if err != nil {
|
||||
logrus.Debugf("Error deleting path: %s\n", path)
|
||||
return nil //nolint:nilerr
|
||||
}
|
||||
logrus.Debugf("Deleted path: %s\n", path)
|
||||
}
|
||||
|
||||
return nil //nolint:nilerr
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteFilesystem deletes the extracted image file system
|
||||
func DeleteFilesystem() error {
|
||||
logrus.Info("Deleting filesystem...")
|
||||
|
|
|
|||
Loading…
Reference in New Issue