saluki_env/features/
containerd.rs1use std::path::PathBuf;
2
3use saluki_config::GenericConfiguration;
4#[cfg(unix)]
5use tracing::{debug, error};
6
7#[cfg(unix)]
8use super::{
9 find_first_available_unix_socket, is_running_inside_docker, path_contains, path_empty, with_host_mount_prefixes,
10};
11
12#[cfg(unix)]
13const DEFAULT_CONTAINERD_SOCKET_PATH_LINUX: &str = "/var/run/containerd/containerd.sock";
14
15pub struct ContainerdDetector;
17
18impl ContainerdDetector {
19 #[cfg(unix)]
27 pub fn detect_grpc_socket_path(config: &GenericConfiguration) -> Option<PathBuf> {
28 let detected_socket_path = match config.try_get_typed::<PathBuf>("cri_socket_path") {
31 Ok(Some(cri_socket_path)) => Some(cri_socket_path),
32 Ok(None) => {
33 if is_running_inside_docker() {
34 None
35 } else {
36 debug!("Containerd socket path (`cri_socket_path`) not present in configuration. Trying to detect at default paths...");
37
38 let default_socket_paths = with_host_mount_prefixes([DEFAULT_CONTAINERD_SOCKET_PATH_LINUX]);
39 find_first_available_unix_socket(default_socket_paths)
40 }
41 }
42 Err(e) => {
43 error!(error = %e, "Value for `cri_socket_path` could not be parsed as a valid path.");
44 None
45 }
46 }?;
47
48 if !path_empty(&detected_socket_path) && path_contains(&detected_socket_path, "containerd") {
50 debug!(socket_path = %detected_socket_path.to_string_lossy(), "Detected containerd socket path.");
51 Some(detected_socket_path)
52 } else {
53 None
54 }
55 }
56
57 #[cfg(not(unix))]
59 pub fn detect_grpc_socket_path(_: &GenericConfiguration) -> Option<PathBuf> {
60 None
61 }
62}