From 9a0d4f424394de66c7450c1b00efd5d24717f8b3 Mon Sep 17 00:00:00 2001 From: tbavelier Date: Thu, 28 Mar 2024 13:52:24 +0100 Subject: [PATCH 01/10] parity-wise sqlite-backend client --- go.mod | 1 + pkg/util/podman/sqlite_db_client.go | 117 ++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 pkg/util/podman/sqlite_db_client.go diff --git a/go.mod b/go.mod index b541ed7463323..81a4cb796a543 100644 --- a/go.mod +++ b/go.mod @@ -683,6 +683,7 @@ require ( github.com/godror/godror v0.37.0 github.com/jmoiron/sqlx v1.3.5 github.com/kr/pretty v0.3.1 + github.com/mattn/go-sqlite3 v1.14.16 github.com/planetscale/vtprotobuf v0.6.0 github.com/prometheus-community/pro-bing v0.3.0 github.com/rickar/props v1.0.0 diff --git a/pkg/util/podman/sqlite_db_client.go b/pkg/util/podman/sqlite_db_client.go new file mode 100644 index 0000000000000..c78029921fa4d --- /dev/null +++ b/pkg/util/podman/sqlite_db_client.go @@ -0,0 +1,117 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build podman + +package podman + +import ( + "database/sql" + "encoding/json" + "fmt" + "path/filepath" + + // SQLite backend for database/sql + _ "github.com/mattn/go-sqlite3" + + "github.com/DataDog/datadog-agent/pkg/util/log" +) + +// Same strategy as for BoltDB : we do not need the full podman go package. +// This reduces the number of dependencies and the size of the ultimately shipped binary. +// +// The functions in this file have been copied from +// https://github.com/containers/podman/blob/v5.0.0/libpod/sqlite_state.go +// The code has been adapted a bit to our needs. The only functions of that file +// that we need are AllContainers() and NewSqliteState(). +// +// This code could break in future versions of Podman. This has been tried with +// v4.9.2 and v5.0.0. + +// SQLDBClient is a client for the podman's state database in the SQLite format. +type SQLDBClient struct { + DBPath string +} + +const ( + // Deal with timezone automatically. + sqliteOptionLocation = "_loc=auto" + // Read-only mode (https://www.sqlite.org/pragma.html#pragma_query_only) + sqliteOptionQueryOnly = "&_query_only=true" + // Make sure busy timeout is set to high value to keep retrying when the db is locked. + // Timeout is in ms, so set it to 100s to have enough time to retry the operations. + sqliteOptionBusyTimeout = "&_busy_timeout=100000" + + // Assembled sqlite options used when opening the database. + sqliteOptions = "db.sql?" + + sqliteOptionLocation + + sqliteOptionQueryOnly + + sqliteOptionBusyTimeout +) + +// NewSQLDBClient returns a DB client that uses the DB stored in dbPath. +func NewSQLDBClient(dbPath string) *SQLDBClient { + return &SQLDBClient{ + DBPath: dbPath, + } +} + +// Note: original function comes from https://github.com/containers/podman/blob/e71ec6f1d94d2d97fb3afe08aae0d8adaf8bddf0/libpod/sqlite_state.go#L57-L96 +// It was adapted as we don't need to write any information to the DB. +// getDBCon opens a connection to the SQLite-backed state database. +func (client *SQLDBClient) getDBCon() (*sql.DB, error) { + conn, err := sql.Open("sqlite3", filepath.Join(client.DBPath, sqliteOptions)) + if err != nil { + return nil, fmt.Errorf("opening sqlite database: %w", err) + } + return conn, nil +} + +// AllContainers retrieves all the containers in the database. +// We retrieve the state always. +func (client *SQLDBClient) GetAllContainers() ([]Container, error) { + var res []Container + + conn, err := client.getDBCon() + if err != nil { + return nil, err + } + defer func() { + if errClose := conn.Close(); errClose != nil { + log.Warnf("failed to close libpod db: %q", err) + } + }() + + rows, err := conn.Query("SELECT ContainerConfig.JSON, ContainerState.JSON AS StateJSON FROM ContainerConfig INNER JOIN ContainerState ON ContainerConfig.ID = ContainerState.ID;") + if err != nil { + return nil, fmt.Errorf("retrieving all containers from database: %w", err) + } + defer rows.Close() + + for rows.Next() { + var configJSON, stateJSON string + if err := rows.Scan(&configJSON, &stateJSON); err != nil { + return nil, fmt.Errorf("scanning container from database: %w", err) + } + + ctr := new(Container) + ctr.Config = new(ContainerConfig) + ctr.State = new(ContainerState) + + if err := json.Unmarshal([]byte(configJSON), ctr.Config); err != nil { + return nil, fmt.Errorf("unmarshalling container config: %w", err) + } + if err := json.Unmarshal([]byte(stateJSON), ctr.State); err != nil { + return nil, fmt.Errorf("unmarshalling container %s state: %w", ctr.Config.ID, err) + } + + res = append(res, *ctr) + } + if err := rows.Err(); err != nil { + return nil, err + } + + return res, nil +} From c9bca8f08173246a43ff9495828df4ee4e99fd7b Mon Sep 17 00:00:00 2001 From: tbavelier Date: Thu, 28 Mar 2024 15:11:58 +0100 Subject: [PATCH 02/10] config to use sqlite client --- .../workloadmeta/collectors/internal/podman/podman.go | 6 +++++- pkg/config/config_template.yaml | 11 +++++++++++ pkg/config/setup/config.go | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/comp/core/workloadmeta/collectors/internal/podman/podman.go b/comp/core/workloadmeta/collectors/internal/podman/podman.go index ba7f13f7dcd8a..a798fb74ce5d0 100644 --- a/comp/core/workloadmeta/collectors/internal/podman/podman.go +++ b/comp/core/workloadmeta/collectors/internal/podman/podman.go @@ -63,7 +63,11 @@ func (c *collector) Start(_ context.Context, store workloadmeta.Component) error return dderrors.NewDisabled(componentName, "Podman not detected") } - c.client = podman.NewDBClient(config.Datadog.GetString("podman_db_path")) + if !config.Datadog.GetBool("podman_use_sqlite") { + c.client = podman.NewDBClient(config.Datadog.GetString("podman_db_path")) + } else { + c.client = podman.NewSQLDBClient(config.Datadog.GetString("podman_sqlite_db_path")) + } c.store = store return nil diff --git a/pkg/config/config_template.yaml b/pkg/config/config_template.yaml index 44e060eff8ff0..79f732f7758fc 100644 --- a/pkg/config/config_template.yaml +++ b/pkg/config/config_template.yaml @@ -2867,6 +2867,17 @@ api_key: # # podman_db_path: /var/lib/containers/storage/libpod/bolt_state.db +## @param podman_use_sqlite - boolean - optional - default: false +## Set to true if Podman DB is SQLite (default in podman 4.8: https://github.com/containers/podman/blob/main/RELEASE_NOTES.md#480) +# +# podman_use_sqlite: false + +## @param podman_sqlite_db_path - string - optional - default: /var/lib/containers/storage +## Directory with `db.sql` of Podman DB. The default value is for rootfull containers. +## Rootless containers are stored in `$HOME/.local/share/containers/storage/` by default. +# +# podman_sqlite_db_path: /var/lib/containers/storage + {{ end -}} {{- if .ClusterAgent }} diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index 28639b840a3ef..d6b5c48fe1baf 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -632,6 +632,8 @@ func InitConfig(config pkgconfigmodel.Config) { // Podman config.BindEnvAndSetDefault("podman_db_path", "/var/lib/containers/storage/libpod/bolt_state.db") + config.BindEnvAndSetDefault("podman_use_sqlite", false) + config.BindEnvAndSetDefault("podman_sqlite_db_path", "/var/lib/containers/storage") // Kubernetes config.BindEnvAndSetDefault("kubernetes_kubelet_host", "") From b12875f7d794e6366110cab4849212d0cacd3a8d Mon Sep 17 00:00:00 2001 From: tbavelier Date: Thu, 28 Mar 2024 15:24:54 +0100 Subject: [PATCH 03/10] release note --- .../podman-sqlite-backend-support-8437c6d5254b39ef.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml diff --git a/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml b/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml new file mode 100644 index 0000000000000..28c04cb71203e --- /dev/null +++ b/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml @@ -0,0 +1,6 @@ +--- +enhancements: + - | + Supports Podman newer versions (4.8+) using SQLite instead of BoltDB for the containers database backend by introducing the parameters ``podman_use_sqlite`` and ``podman_sqlite_db_path``. + - ``podman_use_sqlite`` is **false** by default for retro-compatibility and needs to be set to **true** to have the Agent query the SQLite database. + - ``podman_sqlite_db_path`` is the directory containing the ``db.sql`` file and defaults to ``/var/lib/containers/storage``. From fa69ff8bd1b508f440cabc275771c0ce01df4bb5 Mon Sep 17 00:00:00 2001 From: tbavelier Date: Thu, 28 Mar 2024 16:12:51 +0100 Subject: [PATCH 04/10] Fix comments --- pkg/util/podman/sqlite_db_client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/util/podman/sqlite_db_client.go b/pkg/util/podman/sqlite_db_client.go index c78029921fa4d..32545cf20b906 100644 --- a/pkg/util/podman/sqlite_db_client.go +++ b/pkg/util/podman/sqlite_db_client.go @@ -58,9 +58,9 @@ func NewSQLDBClient(dbPath string) *SQLDBClient { } } +// getDBCon opens a connection to the SQLite-backed state database. // Note: original function comes from https://github.com/containers/podman/blob/e71ec6f1d94d2d97fb3afe08aae0d8adaf8bddf0/libpod/sqlite_state.go#L57-L96 // It was adapted as we don't need to write any information to the DB. -// getDBCon opens a connection to the SQLite-backed state database. func (client *SQLDBClient) getDBCon() (*sql.DB, error) { conn, err := sql.Open("sqlite3", filepath.Join(client.DBPath, sqliteOptions)) if err != nil { @@ -69,7 +69,7 @@ func (client *SQLDBClient) getDBCon() (*sql.DB, error) { return conn, nil } -// AllContainers retrieves all the containers in the database. +// GetAllContainers retrieves all the containers in the database. // We retrieve the state always. func (client *SQLDBClient) GetAllContainers() ([]Container, error) { var res []Container From b75a687b7c7a5babe391e2ee40a510dc42ca8e88 Mon Sep 17 00:00:00 2001 From: tbavelier Date: Thu, 28 Mar 2024 17:00:10 +0100 Subject: [PATCH 05/10] licenses --- LICENSE-3rdparty.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 94c3e7a04c4ca..71bab32a290be 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -1220,6 +1220,7 @@ core,github.com/mattn/go-colorable,MIT,Copyright (c) 2016 Yasuhiro Matsumoto core,github.com/mattn/go-isatty,MIT,Copyright (c) Yasuhiro MATSUMOTO core,github.com/mattn/go-runewidth,MIT,Copyright (c) 2016 Yasuhiro Matsumoto core,github.com/mattn/go-shellwords,MIT,Copyright (c) 2017 Yasuhiro Matsumoto +core,github.com/mattn/go-sqlite3,MIT,Copyright (c) 2014 Yasuhiro Matsumoto core,github.com/mdlayher/netlink,MIT,Copyright (C) 2016-2022 Matt Layher core,github.com/mdlayher/netlink/nlenc,MIT,Copyright (C) 2016-2022 Matt Layher core,github.com/mdlayher/socket,MIT,Copyright (C) 2021 Matt Layher From cd07bf60b0d43d9fe42952ecf09b01404cb8e2bf Mon Sep 17 00:00:00 2001 From: tbavelier Date: Tue, 2 Apr 2024 17:15:33 +0200 Subject: [PATCH 06/10] Selects client based on file extension in containers DB --- .../collectors/internal/podman/podman.go | 11 ++++++++--- pkg/config/config_template.yaml | 13 ++----------- pkg/config/setup/config.go | 2 -- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/comp/core/workloadmeta/collectors/internal/podman/podman.go b/comp/core/workloadmeta/collectors/internal/podman/podman.go index a798fb74ce5d0..28bd85297013c 100644 --- a/comp/core/workloadmeta/collectors/internal/podman/podman.go +++ b/comp/core/workloadmeta/collectors/internal/podman/podman.go @@ -63,10 +63,15 @@ func (c *collector) Start(_ context.Context, store workloadmeta.Component) error return dderrors.NewDisabled(componentName, "Podman not detected") } - if !config.Datadog.GetBool("podman_use_sqlite") { - c.client = podman.NewDBClient(config.Datadog.GetString("podman_db_path")) + dbPath := config.Datadog.GetString("podman_db_path") + + // As the containers database file is hard-coded in Podman (non-user customizable), the client to use is determined thanks to the file extension. + // If `podman_db_path` references a `db.sql` file, the SQLite client is used. Defaults to BoltDB client otherwise (`bolt_state.db`). + if strings.Contains(dbPath, "db.sql") { + log.Debugf("Using SQLite client for Podman DB as provided path contains db.sql") + c.client = podman.NewSQLDBClient(config.Datadog.GetString(dbPath)) } else { - c.client = podman.NewSQLDBClient(config.Datadog.GetString("podman_sqlite_db_path")) + c.client = podman.NewDBClient(config.Datadog.GetString(dbPath)) } c.store = store diff --git a/pkg/config/config_template.yaml b/pkg/config/config_template.yaml index 79f732f7758fc..4fbf2968c7037 100644 --- a/pkg/config/config_template.yaml +++ b/pkg/config/config_template.yaml @@ -2863,21 +2863,12 @@ api_key: # listen_address: /var/vcap/data/garden/garden.sock ## @param podman_db_path - string - optional - default: /var/lib/containers/storage/libpod/bolt_state.db +## @env DD_PODMAN_DB_PATH - string - optional - default: /var/lib/containers/storage/libpod/bolt_state.db ## Settings for Podman DB that Datadog Agent collects container metrics. +## If using Podman 4.8+ with SQLite back-end, this parameter should be set to /var/lib/containers/storage/db.sql (rootfull containers). # # podman_db_path: /var/lib/containers/storage/libpod/bolt_state.db -## @param podman_use_sqlite - boolean - optional - default: false -## Set to true if Podman DB is SQLite (default in podman 4.8: https://github.com/containers/podman/blob/main/RELEASE_NOTES.md#480) -# -# podman_use_sqlite: false - -## @param podman_sqlite_db_path - string - optional - default: /var/lib/containers/storage -## Directory with `db.sql` of Podman DB. The default value is for rootfull containers. -## Rootless containers are stored in `$HOME/.local/share/containers/storage/` by default. -# -# podman_sqlite_db_path: /var/lib/containers/storage - {{ end -}} {{- if .ClusterAgent }} diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index d2c7b00baa3c0..af586b0a712bf 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -632,8 +632,6 @@ func InitConfig(config pkgconfigmodel.Config) { // Podman config.BindEnvAndSetDefault("podman_db_path", "/var/lib/containers/storage/libpod/bolt_state.db") - config.BindEnvAndSetDefault("podman_use_sqlite", false) - config.BindEnvAndSetDefault("podman_sqlite_db_path", "/var/lib/containers/storage") // Kubernetes config.BindEnvAndSetDefault("kubernetes_kubelet_host", "") From 66affba413f29f21e7733f95842c6f4ab04db70e Mon Sep 17 00:00:00 2001 From: tbavelier Date: Tue, 2 Apr 2024 17:40:52 +0200 Subject: [PATCH 07/10] Modifies release note + correctly use dbpath from the client --- pkg/util/podman/sqlite_db_client.go | 5 +---- .../podman-sqlite-backend-support-8437c6d5254b39ef.yaml | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/util/podman/sqlite_db_client.go b/pkg/util/podman/sqlite_db_client.go index 32545cf20b906..8d2b402c2e362 100644 --- a/pkg/util/podman/sqlite_db_client.go +++ b/pkg/util/podman/sqlite_db_client.go @@ -45,10 +45,7 @@ const ( sqliteOptionBusyTimeout = "&_busy_timeout=100000" // Assembled sqlite options used when opening the database. - sqliteOptions = "db.sql?" + - sqliteOptionLocation + - sqliteOptionQueryOnly + - sqliteOptionBusyTimeout + sqliteOptions = "?" + sqliteOptionLocation + sqliteOptionQueryOnly + sqliteOptionBusyTimeout ) // NewSQLDBClient returns a DB client that uses the DB stored in dbPath. diff --git a/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml b/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml index 28c04cb71203e..0b48612ba0ae4 100644 --- a/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml +++ b/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml @@ -1,6 +1,4 @@ --- enhancements: - | - Supports Podman newer versions (4.8+) using SQLite instead of BoltDB for the containers database backend by introducing the parameters ``podman_use_sqlite`` and ``podman_sqlite_db_path``. - - ``podman_use_sqlite`` is **false** by default for retro-compatibility and needs to be set to **true** to have the Agent query the SQLite database. - - ``podman_sqlite_db_path`` is the directory containing the ``db.sql`` file and defaults to ``/var/lib/containers/storage``. + Supports Podman newer versions (4.8+) using SQLite instead of BoltDB for the containers database backend. Setting ``podman_db_path`` to the path with the ``db.sql`` file (e.g. ``/var/lib/containers/storage/db.sql``) will make the Datadog Agent use the SQLite format. From 57f0413bcce8d389ab5e5655c779603189964df6 Mon Sep 17 00:00:00 2001 From: tbavelier Date: Wed, 3 Apr 2024 14:19:59 +0200 Subject: [PATCH 08/10] Detect podman + select client based on file extension + prevent failing loop + release note --- .../collectors/internal/podman/podman.go | 49 ++++++++++++++++--- pkg/config/config_template.yaml | 7 ++- pkg/config/env/environment_containers.go | 20 +++++--- pkg/config/setup/config.go | 2 +- pkg/util/podman/sqlite_db_client.go | 2 +- ...lite-backend-support-8437c6d5254b39ef.yaml | 4 +- 6 files changed, 62 insertions(+), 22 deletions(-) diff --git a/comp/core/workloadmeta/collectors/internal/podman/podman.go b/comp/core/workloadmeta/collectors/internal/podman/podman.go index 28bd85297013c..a5b3b23a68e6e 100644 --- a/comp/core/workloadmeta/collectors/internal/podman/podman.go +++ b/comp/core/workloadmeta/collectors/internal/podman/podman.go @@ -11,6 +11,7 @@ package podman import ( "context" "errors" + "os" "sort" "strings" @@ -25,8 +26,10 @@ import ( ) const ( - collectorID = "podman" - componentName = "workloadmeta-podman" + collectorID = "podman" + componentName = "workloadmeta-podman" + defaultBoltDBPath = "/var/lib/containers/storage/libpod/bolt_state.db" + defaultSqlitePath = "/var/lib/containers/storage/db.sql" ) type podmanClient interface { @@ -63,15 +66,37 @@ func (c *collector) Start(_ context.Context, store workloadmeta.Component) error return dderrors.NewDisabled(componentName, "Podman not detected") } - dbPath := config.Datadog.GetString("podman_db_path") + var dbPath string + dbPath = config.Datadog.GetString("podman_db_path") + + // We verify the user-provided path exists to prevent the collector entering a failing loop. + if dbPath != "" && !dbIsAccessible(dbPath) { + return dderrors.NewDisabled(componentName, "podman_db_path is misconfigured/not accessible") + } + + // If dbPath is empty (default value of `podman_db_path`), attempts to use the default rootfull database (BoltDB first, then SQLite) as podman feature was detected (existence of /var/lib/containers/storage) + if dbPath == "" { + if dbIsAccessible(defaultBoltDBPath) { + log.Infof("Podman feature detected and podman_db_path not configured, defaulting to: %s", defaultBoltDBPath) + dbPath = defaultBoltDBPath + } else if dbIsAccessible(defaultSqlitePath) { + log.Infof("Podman feature detected and podman_db_path not configured, defaulting to: %s", defaultSqlitePath) + dbPath = defaultSqlitePath + } else { + // `/var/lib/containers/storage` exists but the Agent cannot list out its content. + return dderrors.NewDisabled(componentName, "Podman feature detected but the default location for the containers DB is not accessible") + } + } // As the containers database file is hard-coded in Podman (non-user customizable), the client to use is determined thanks to the file extension. - // If `podman_db_path` references a `db.sql` file, the SQLite client is used. Defaults to BoltDB client otherwise (`bolt_state.db`). - if strings.Contains(dbPath, "db.sql") { - log.Debugf("Using SQLite client for Podman DB as provided path contains db.sql") - c.client = podman.NewSQLDBClient(config.Datadog.GetString(dbPath)) + if strings.HasSuffix(dbPath, ".sql") { + log.Debugf("Using SQLite client for Podman DB as provided path ends with .sql") + c.client = podman.NewSQLDBClient(dbPath) + } else if strings.HasSuffix(dbPath, ".db") { + log.Debugf("Using BoltDB client for Podman DB as provided path ends with .db") + c.client = podman.NewDBClient(dbPath) } else { - c.client = podman.NewDBClient(config.Datadog.GetString(dbPath)) + return dderrors.NewDisabled(componentName, "Podman detected but podman_db_path does not end in a known-format (.db or .sql)") } c.store = store @@ -279,3 +304,11 @@ func status(state podman.ContainerStatus) workloadmeta.ContainerStatus { return workloadmeta.ContainerStatusUnknown } + +// dbIsAccessible verifies whether or not the provided file is accessible by the Agent +func dbIsAccessible(dbPath string) bool { + if _, err := os.Stat(dbPath); err == nil { + return true + } + return false +} diff --git a/pkg/config/config_template.yaml b/pkg/config/config_template.yaml index 4fbf2968c7037..e103586ac48c6 100644 --- a/pkg/config/config_template.yaml +++ b/pkg/config/config_template.yaml @@ -2862,12 +2862,11 @@ api_key: # # listen_address: /var/vcap/data/garden/garden.sock -## @param podman_db_path - string - optional - default: /var/lib/containers/storage/libpod/bolt_state.db -## @env DD_PODMAN_DB_PATH - string - optional - default: /var/lib/containers/storage/libpod/bolt_state.db +## @param podman_db_path - string - optional - default: "" +## @env DD_PODMAN_DB_PATH - string - optional - default: "" ## Settings for Podman DB that Datadog Agent collects container metrics. -## If using Podman 4.8+ with SQLite back-end, this parameter should be set to /var/lib/containers/storage/db.sql (rootfull containers). # -# podman_db_path: /var/lib/containers/storage/libpod/bolt_state.db +# podman_db_path: "" {{ end -}} {{- if .ClusterAgent }} diff --git a/pkg/config/env/environment_containers.go b/pkg/config/env/environment_containers.go index f5f186ff152dd..962af0f2fd549 100644 --- a/pkg/config/env/environment_containers.go +++ b/pkg/config/env/environment_containers.go @@ -26,7 +26,7 @@ const ( defaultWindowsContainerdSocketPath = "//./pipe/containerd-containerd" defaultLinuxCrioSocket = "/var/run/crio/crio.sock" defaultHostMountPrefix = "/host" - defaultPodmanContainersStoragePath = "/var/lib/containers" + defaultPodmanContainersStoragePath = "/var/lib/containers/storage" unixSocketPrefix = "unix://" winNamedPipePrefix = "npipe://" @@ -66,7 +66,7 @@ func detectContainerFeatures(features FeatureMap, cfg model.Reader) { detectContainerd(features, cfg) detectAWSEnvironments(features, cfg) detectCloudFoundry(features, cfg) - detectPodman(features) + detectPodman(features, cfg) } func detectKubernetes(features FeatureMap, cfg model.Reader) { @@ -195,11 +195,17 @@ func detectCloudFoundry(features FeatureMap, cfg model.Reader) { } } -func detectPodman(features FeatureMap) { - for _, defaultPath := range getDefaultPodmanPaths() { - if _, err := os.Stat(defaultPath); err == nil { - features[Podman] = struct{}{} - return +func detectPodman(features FeatureMap, cfg model.Reader) { + podmanDbPath := cfg.GetString("podman_db_path") + if podmanDbPath != "" { + features[Podman] = struct{}{} + return + } else { + for _, defaultPath := range getDefaultPodmanPaths() { + if _, err := os.Stat(defaultPath); err == nil { + features[Podman] = struct{}{} + return + } } } } diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index af586b0a712bf..0b74ee8cfecb0 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -631,7 +631,7 @@ func InitConfig(config pkgconfigmodel.Config) { config.BindEnvAndSetDefault("container_labels_as_tags", map[string]string{}) // Podman - config.BindEnvAndSetDefault("podman_db_path", "/var/lib/containers/storage/libpod/bolt_state.db") + config.BindEnvAndSetDefault("podman_db_path", "") // Kubernetes config.BindEnvAndSetDefault("kubernetes_kubelet_host", "") diff --git a/pkg/util/podman/sqlite_db_client.go b/pkg/util/podman/sqlite_db_client.go index 8d2b402c2e362..30c60fb108e99 100644 --- a/pkg/util/podman/sqlite_db_client.go +++ b/pkg/util/podman/sqlite_db_client.go @@ -77,7 +77,7 @@ func (client *SQLDBClient) GetAllContainers() ([]Container, error) { } defer func() { if errClose := conn.Close(); errClose != nil { - log.Warnf("failed to close libpod db: %q", err) + log.Warnf("failed to close sqlite db: %q", err) } }() diff --git a/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml b/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml index 0b48612ba0ae4..699d2a7d93f00 100644 --- a/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml +++ b/releasenotes/notes/podman-sqlite-backend-support-8437c6d5254b39ef.yaml @@ -1,4 +1,6 @@ --- enhancements: - | - Supports Podman newer versions (4.8+) using SQLite instead of BoltDB for the containers database backend. Setting ``podman_db_path`` to the path with the ``db.sql`` file (e.g. ``/var/lib/containers/storage/db.sql``) will make the Datadog Agent use the SQLite format. + Supports Podman newer versions (4.8+) using SQLite instead of BoltDB for the containers database backend. + Setting ``podman_db_path`` to the path with the ``db.sql`` file (e.g. ``/var/lib/containers/storage/db.sql``) will make the Datadog Agent use the SQLite format. + *Note: If ``podman_db_path`` is not set (default), the Datadog Agent attempts to use the default file ``libpod/bolt_state.db`` and ``db.sql`` from ``/var/lib/containers/storage``.* From cfaebfca923f19973376e65d053522338104d0a6 Mon Sep 17 00:00:00 2001 From: tbavelier Date: Wed, 3 Apr 2024 15:02:44 +0200 Subject: [PATCH 09/10] lint --- pkg/config/env/environment_containers.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/config/env/environment_containers.go b/pkg/config/env/environment_containers.go index 962af0f2fd549..7e1c267123e12 100644 --- a/pkg/config/env/environment_containers.go +++ b/pkg/config/env/environment_containers.go @@ -200,12 +200,11 @@ func detectPodman(features FeatureMap, cfg model.Reader) { if podmanDbPath != "" { features[Podman] = struct{}{} return - } else { - for _, defaultPath := range getDefaultPodmanPaths() { - if _, err := os.Stat(defaultPath); err == nil { - features[Podman] = struct{}{} - return - } + } + for _, defaultPath := range getDefaultPodmanPaths() { + if _, err := os.Stat(defaultPath); err == nil { + features[Podman] = struct{}{} + return } } } From cb212953941b8c8a60c8b29a99e12e24e3803dcc Mon Sep 17 00:00:00 2001 From: tbavelier Date: Thu, 4 Apr 2024 14:40:36 +0200 Subject: [PATCH 10/10] update docker to 24.0.9 --- tasks/docker_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/docker_tasks.py b/tasks/docker_tasks.py index 5017695169040..c8cf1fa2eabeb 100644 --- a/tasks/docker_tasks.py +++ b/tasks/docker_tasks.py @@ -54,7 +54,7 @@ def dockerize_test(ctx, binary, skip_cleanup=False): with open(f"{temp_folder}/Dockerfile", 'w') as stream: stream.write( - """FROM docker/compose:debian-1.29.2 + """FROM docker:24.0.9 ENV DOCKER_DD_AGENT=yes WORKDIR / CMD /test.bin