mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-22 02:36:58 +00:00
Fix upgrade size calculation inside k8s (#537)
Co-authored-by: Dimitris Karakasilis <dimitris@karakasilis.me>
(cherry picked from commit 7c6c195bd5
)
This commit is contained in:
@@ -808,11 +808,33 @@ func GetSourceSize(config *Config, source *v1.ImageSource) (int64, error) {
|
||||
size = int64(float64(size) * 2.5)
|
||||
case source.IsDir():
|
||||
filesVisited = make(map[string]bool, 30000) // An Ubuntu system has around 27k files. This improves performance by not having to resize the map for every file visited
|
||||
// In kubernetes we use the suc script to upgrade (https://github.com/kairos-io/packages/blob/main/packages/system/suc-upgrade/suc-upgrade.sh)
|
||||
// , which mounts the host root into $HOST_DIR
|
||||
// we should skip that dir when calculating the size as we would be doubling the calculated size
|
||||
// Plus we will hit the usual things when checking a running system. Processes that go away, tmpfiles, etc...
|
||||
|
||||
// This is always set for pods running under kubernetes
|
||||
underKubernetes := os.Getenv("KUBERNETES_SERVICE_HOST")
|
||||
// Try to get the HOST_DIR in case we are not using the default one
|
||||
hostDir := os.Getenv("HOST_DIR")
|
||||
// If we are under kubernetes but the HOST_DIR var is empty, default to /host as system-upgrade-controller mounts
|
||||
// the host in that dir by default
|
||||
if underKubernetes != "" && hostDir == "" {
|
||||
hostDir = "/host"
|
||||
}
|
||||
err = fsutils.WalkDirFs(config.Fs, source.Value(), func(path string, d fs.DirEntry, err error) error {
|
||||
v := getSize(&size, filesVisited, path, d, err)
|
||||
|
||||
return v
|
||||
// If its empty we are just not setting it, so probably out of the k8s upgrade path
|
||||
if hostDir != "" && strings.HasPrefix(path, hostDir) {
|
||||
config.Logger.Logger.Debug().Str("path", path).Str("hostDir", hostDir).Msg("Skipping file as it is a host directory")
|
||||
} else if strings.HasPrefix(path, "/proc") || strings.HasPrefix(path, "/dev") || strings.HasPrefix(path, "/run") {
|
||||
config.Logger.Logger.Debug().Str("path", path).Str("hostDir", hostDir).Msg("Skipping dir as it is a system directory (/proc, /dev or /run)")
|
||||
} else {
|
||||
v := getSize(&size, filesVisited, path, d, err)
|
||||
return v
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
case source.IsFile():
|
||||
|
Reference in New Issue
Block a user