mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-22 10:47:17 +00:00
Fix skipping paths under kubernetes
Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
@@ -814,20 +814,24 @@ func GetSourceSize(config *Config, source *v1.ImageSource) (int64, error) {
|
||||
// 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")
|
||||
_, underKubernetes := os.LookupEnv("KUBERNETES_SERVICE_HOST")
|
||||
config.Logger.Logger.Info().Bool("status", underKubernetes).Msg("Running under kubernetes")
|
||||
// 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 == "" {
|
||||
if underKubernetes && hostDir == "" {
|
||||
hostDir = "/host"
|
||||
}
|
||||
err = fsutils.WalkDirFs(config.Fs, source.Value(), func(path string, d fs.DirEntry, err error) error {
|
||||
// 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") {
|
||||
config.Logger.Logger.Debug().Str("path", path).Str("hostDir", hostDir).Msg("Skipping dir as it is a runtime directory (/proc or /dev)")
|
||||
} else if underKubernetes && (strings.HasPrefix(path, "/proc") || strings.HasPrefix(path, "/dev") || strings.HasPrefix(path, "/run")) {
|
||||
// If under kubernetes, the upgrade will check the size of / which includes the host dir mounted under /host
|
||||
// But it also can bind the host mounts into / so we want to skip those runtime dirs
|
||||
// During install or upgrade outside kubernetes, we dont care about those dirs as they are not expected to be in the source dir
|
||||
config.Logger.Logger.Debug().Str("path", path).Str("hostDir", hostDir).Msg("Skipping dir as it is a runtime directory under kubernetes (/proc, /dev or /run)")
|
||||
} else {
|
||||
v := getSize(&size, filesVisited, path, d, err)
|
||||
return v
|
||||
|
Reference in New Issue
Block a user