summaryrefslogtreecommitdiff
path: root/pkg/machine/fcos.go
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2022-07-16 12:02:55 +0000
committerGitHub <noreply@github.com>2022-07-16 12:02:55 +0000
commit20a3c9969f11ce825276c46d9c93a9ba5d587b13 (patch)
tree244ad40f671a07e089cacb55930e6b9d3da8019d /pkg/machine/fcos.go
parentbbb7d4a9fb6049b1f805880f8aef9f3260987189 (diff)
parentb513dc4c1e9094cf1bc60aa86b2c71e2bccb857d (diff)
downloadpodman-20a3c9969f11ce825276c46d9c93a9ba5d587b13.tar.gz
podman-20a3c9969f11ce825276c46d9c93a9ba5d587b13.tar.bz2
podman-20a3c9969f11ce825276c46d9c93a9ba5d587b13.zip
Merge pull request #14900 from ashley-cui/machcache
Clean up cached machine images
Diffstat (limited to 'pkg/machine/fcos.go')
-rw-r--r--pkg/machine/fcos.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 4ccb99e96..246f92a19 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strings"
+ "time"
"github.com/coreos/stream-metadata-go/fedoracoreos"
"github.com/coreos/stream-metadata-go/release"
@@ -53,7 +54,7 @@ func NewFcosDownloader(vmType, vmName, imageStream string) (DistributionDownload
return nil, err
}
- dataDir, err := GetDataDir(vmType)
+ cacheDir, err := GetCacheDir(vmType)
if err != nil {
return nil, err
}
@@ -62,15 +63,20 @@ func NewFcosDownloader(vmType, vmName, imageStream string) (DistributionDownload
Download: Download{
Arch: getFcosArch(),
Artifact: artifact,
+ CacheDir: cacheDir,
Format: Format,
ImageName: imageName,
- LocalPath: filepath.Join(dataDir, imageName),
+ LocalPath: filepath.Join(cacheDir, imageName),
Sha256sum: info.Sha256Sum,
URL: url,
VMName: vmName,
},
}
- fcd.Download.LocalUncompressedFile = fcd.getLocalUncompressedName()
+ dataDir, err := GetDataDir(vmType)
+ if err != nil {
+ return nil, err
+ }
+ fcd.Download.LocalUncompressedFile = fcd.getLocalUncompressedFile(dataDir)
return fcd, nil
}
@@ -108,6 +114,13 @@ func (f FcosDownload) HasUsableCache() (bool, error) {
return sum.Encoded() == f.Sha256sum, nil
}
+func (f FcosDownload) CleanCache() error {
+ // Set cached image to expire after 2 weeks
+ // FCOS refreshes around every 2 weeks, assume old images aren't needed
+ expire := 14 * 24 * time.Hour
+ return removeImageAfterExpire(f.CacheDir, expire)
+}
+
func getFcosArch() string {
var arch string
// TODO fill in more architectures