1
0
mirror of https://github.com/rancher/os.git synced 2025-08-29 19:44:22 +00:00

Reduce repeated system image loading

This commit is contained in:
niusmallnan 2018-11-20 11:08:26 +08:00 committed by niusmallnan
parent f508c86d5a
commit 6be7426bf3

View File

@ -1,10 +1,12 @@
package sysinit
import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
"github.com/rancher/os/cmd/control"
@ -20,6 +22,7 @@ import (
const (
systemImagesPreloadDirectory = "/var/lib/rancher/preload/system-docker"
systemImagesLoadStamp = "/var/lib/rancher/.sysimages_%s_loaded.done"
)
func hasImage(name string) bool {
@ -46,7 +49,14 @@ func LoadBootstrapImages(cfg *config.CloudConfig) (*config.CloudConfig, error) {
}
func LoadSystemImages(cfg *config.CloudConfig) (*config.CloudConfig, error) {
stamp := fmt.Sprintf(systemImagesLoadStamp, strings.Replace(config.Version, ".", "_", -1))
if _, err := os.Stat(stamp); os.IsNotExist(err) {
os.Create(stamp)
return loadImages(cfg, false)
}
log.Infof("Skipped loading system images because %s exists", systemImagesLoadStamp)
return cfg, nil
}
func loadImages(cfg *config.CloudConfig, bootstrap bool) (*config.CloudConfig, error) {
@ -75,7 +85,7 @@ func loadImages(cfg *config.CloudConfig, bootstrap bool) (*config.CloudConfig, e
dockerImages, _ := client.ImageList(context.Background(), types.ImageListOptions{})
for _, dimg := range dockerImages {
log.Infof("Got image repo tags: %s", dimg.RepoTags)
log.Debugf("Loaded a docker image: %s", dimg.RepoTags)
}
return cfg, nil