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