Skip to content

Commit 737b482

Browse files
committed
dockershim fallback for containerd (#630)
Co-authored-by: Aviram Hassan <[email protected]>
1 parent 73086e7 commit 737b482

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1313
- Added timeout for "waiting for pod to be ready..." in mirrord-layer to prevent unresponsive behavior. See [#579](https://github.com/metalbear-co/mirrord/issues/579)
1414
- IntelliJ Extension: Default log level to `ERROR` from `DEBUG`
1515

16+
### Fixed
17+
- Issue with [bottlerocket](https://github.com/bottlerocket-os/bottlerocket) where they use `/run/dockershim.sock` instead of the default containerd path. Add new path as fallback.
18+
1619
## 3.2.0
1720

1821
### Changed

mirrord-agent/src/runtime.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use tracing::debug;
1717
use crate::error::AgentError;
1818

1919
const CONTAINERD_SOCK_PATH: &str = "/run/containerd/containerd.sock";
20+
const CONTAINERD_ALTERNATIVE_SOCK_PATH: &str = "/run/dockershim.sock";
21+
2022
const DEFAULT_CONTAINERD_NAMESPACE: &str = "k8s.io";
2123

2224
pub async fn get_container_pid(
@@ -49,7 +51,10 @@ async fn get_docker_container_pid(container_id: String) -> Result<u64, AgentErro
4951
}
5052

5153
async fn get_containerd_container_pid(container_id: String) -> Result<u64, AgentError> {
52-
let channel = connect(CONTAINERD_SOCK_PATH).await?;
54+
let channel = match connect(CONTAINERD_SOCK_PATH).await {
55+
Ok(channel) => channel,
56+
Err(_) => connect(CONTAINERD_ALTERNATIVE_SOCK_PATH).await?,
57+
};
5358
let mut client = TasksClient::new(channel);
5459
let request = GetRequest {
5560
container_id,

mirrord-layer/src/pod_api.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, str::FromStr};
1+
use std::{collections::HashSet, fmt::Display, str::FromStr};
22

33
use async_trait::async_trait;
44
use futures::{StreamExt, TryStreamExt};
@@ -265,7 +265,7 @@ impl KubernetesAPI {
265265
"--container-id".to_string(),
266266
runtime_data.container_id,
267267
"--container-runtime".to_string(),
268-
runtime_data.container_runtime,
268+
runtime_data.container_runtime.to_string(),
269269
"-l".to_string(),
270270
connection_port.to_string(),
271271
];
@@ -307,7 +307,7 @@ impl KubernetesAPI {
307307
{
308308
"name": "sockpath",
309309
"hostPath": {
310-
"path": runtime_data.socket_path
310+
"path": runtime_data.container_runtime.mount_path()
311311
}
312312
}
313313
],
@@ -321,7 +321,7 @@ impl KubernetesAPI {
321321
},
322322
"volumeMounts": [
323323
{
324-
"mountPath": runtime_data.socket_path,
324+
"mountPath": runtime_data.container_runtime.mount_path(),
325325
"name": "sockpath"
326326
}
327327
],
@@ -476,13 +476,35 @@ async fn wait_for_agent_startup(
476476
Ok(())
477477
}
478478

479+
pub(crate) enum ContainerRuntime {
480+
Docker,
481+
Containerd,
482+
}
483+
484+
impl ContainerRuntime {
485+
pub(crate) fn mount_path(&self) -> String {
486+
match self {
487+
ContainerRuntime::Docker => "/var/run/docker.sock".to_string(),
488+
ContainerRuntime::Containerd => "/run/".to_string(),
489+
}
490+
}
491+
}
492+
493+
impl Display for ContainerRuntime {
494+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
495+
match self {
496+
ContainerRuntime::Docker => write!(f, "docker"),
497+
ContainerRuntime::Containerd => write!(f, "containerd"),
498+
}
499+
}
500+
}
501+
479502
pub(crate) struct RuntimeData {
480503
pod_name: String,
481504
node_name: String,
482505
container_id: String,
483-
container_runtime: String,
506+
container_runtime: ContainerRuntime,
484507
container_name: String,
485-
socket_path: String,
486508
}
487509

488510
impl RuntimeData {
@@ -524,9 +546,9 @@ impl RuntimeData {
524546

525547
let mut split = container_id_full.split("://");
526548

527-
let (container_runtime, socket_path) = match split.next() {
528-
Some("docker") => Ok(("docker", "/var/run/docker.sock")),
529-
Some("containerd") => Ok(("containerd", "/run/containerd/containerd.sock")),
549+
let container_runtime = match split.next() {
550+
Some("docker") => Ok(ContainerRuntime::Docker),
551+
Some("containerd") => Ok(ContainerRuntime::Containerd),
530552
_ => Err(LayerError::ContainerRuntimeParseError(
531553
container_id_full.to_string(),
532554
)),
@@ -537,16 +559,12 @@ impl RuntimeData {
537559
.ok_or_else(|| LayerError::ContainerRuntimeParseError(container_id_full.to_string()))?
538560
.to_owned();
539561

540-
let container_runtime = container_runtime.to_string();
541-
let socket_path = socket_path.to_string();
542-
543562
Ok(RuntimeData {
544563
pod_name,
545564
node_name,
546565
container_id,
547566
container_runtime,
548567
container_name,
549-
socket_path,
550568
})
551569
}
552570
}

0 commit comments

Comments
 (0)