From f4599bebe1073c953c39319fc2115befbacbdb67 Mon Sep 17 00:00:00 2001 From: Savely Krasovsky Date: Sat, 10 May 2025 16:44:27 +0200 Subject: [PATCH 1/2] feat: support podman volatile containers It's used by all Podman Quadlets. Those containers are not in fact volatile, but due to the managed nature of those containers, they probably decided to make them transient. --- container/podman/fs.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/container/podman/fs.go b/container/podman/fs.go index e714e900c3..51ea8b4f90 100644 --- a/container/podman/fs.go +++ b/container/podman/fs.go @@ -24,7 +24,8 @@ import ( ) const ( - containersJSONFilename = "containers.json" + containersJSONFilename = "containers.json" + volatileContainersJSONFilename = "volatile-containers.json" ) type containersJSON struct { @@ -44,6 +45,25 @@ func rwLayerID(storageDriver docker.StorageDriver, storageDir string, containerI return "", err } + // Read volatile-containers.json if it exists. + // This is important for Podman Quadlets since they are not presented in the containers.json file. + volatileData, err := os.ReadFile(filepath.Join( + storageDir, + string(storageDriver)+"-containers", + volatileContainersJSONFilename, + )) + if err != nil && !os.IsNotExist(err) { + return "", err + } + if volatileData != nil { + var volatileContainers []containersJSON + err = json.Unmarshal(volatileData, &volatileContainers) + if err != nil { + return "", err + } + containers = append(containers, volatileContainers...) + } + for _, c := range containers { if c.ID == containerID { return c.Layer, nil From 039ded0479ed496cb18e5f8915b4d4ac241d6c68 Mon Sep 17 00:00:00 2001 From: Nicolas Ochsner Date: Tue, 9 Sep 2025 21:43:29 +0200 Subject: [PATCH 2/2] Fix early return when containers.json does not exist. --- container/podman/fs.go | 47 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/container/podman/fs.go b/container/podman/fs.go index 51ea8b4f90..a82cc36189 100644 --- a/container/podman/fs.go +++ b/container/podman/fs.go @@ -23,10 +23,10 @@ import ( "github.com/google/cadvisor/container/docker" ) -const ( - containersJSONFilename = "containers.json" - volatileContainersJSONFilename = "volatile-containers.json" -) +var containersJsonFilnames = []string{ + "containers.json", + "volatile-containers.json", +} type containersJSON struct { ID string `json:"id"` @@ -35,33 +35,26 @@ type containersJSON struct { } func rwLayerID(storageDriver docker.StorageDriver, storageDir string, containerID string) (string, error) { - data, err := os.ReadFile(filepath.Join(storageDir, string(storageDriver)+"-containers", containersJSONFilename)) - if err != nil { - return "", err - } var containers []containersJSON - err = json.Unmarshal(data, &containers) - if err != nil { - return "", err - } - // Read volatile-containers.json if it exists. - // This is important for Podman Quadlets since they are not presented in the containers.json file. - volatileData, err := os.ReadFile(filepath.Join( - storageDir, - string(storageDriver)+"-containers", - volatileContainersJSONFilename, - )) - if err != nil && !os.IsNotExist(err) { - return "", err - } - if volatileData != nil { - var volatileContainers []containersJSON - err = json.Unmarshal(volatileData, &volatileContainers) - if err != nil { + for _, filename := range containersJsonFilnames { + data, err := os.ReadFile(filepath.Join(storageDir, string(storageDriver)+"-containers", filename)) + if err != nil && !os.IsNotExist(err) { return "", err } - containers = append(containers, volatileContainers...) + + if data != nil { + var buffer []containersJSON + err = json.Unmarshal(data, &buffer) + if err != nil { + return "", err + } + containers = append(containers, buffer...) + } + } + + if len(containers) == 0 { + return "", fmt.Errorf("no containers found in containers.json or volatile-containers.json in %q", filepath.Join(storageDir, string(storageDriver)+"-containers")) } for _, c := range containers {