runtime-rs: Add -info flag support for containerd v2.0+

Add -info flag handling to containerd-shim-kata-v2 (Rust version).
This outputs RuntimeInfo protobuf (name, version, revision) to stdout,
providing compatibility with containerd v2.0+ which queries runtime
information via this flag.

This is the runtime-rs counterpart to the Go implementation.

Fixes #12133

Signed-off-by: tak-ka3 <takumi.hiraoka@acompany-ac.com>
This commit is contained in:
tak-ka3
2026-01-24 10:07:37 +09:00
committed by Fabiano Fidêncio
parent c7f5ff45a2
commit 5471fa133c
3 changed files with 34 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -4005,6 +4005,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"common",
"containerd-shim-protos",
"go-flag",
"logging",
"nix 0.26.4",

View File

@@ -22,6 +22,7 @@ cloud-hypervisor = ["runtimes/cloud-hypervisor"]
[dependencies]
anyhow = { workspace = true }
containerd-shim-protos = { workspace = true }
go-flag = { workspace = true }
nix = { workspace = true }
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }

View File

@@ -6,10 +6,15 @@
use std::{
ffi::{OsStr, OsString},
io::Write,
path::PathBuf,
};
use anyhow::{anyhow, Context, Result};
use containerd_shim_protos::{
protobuf::Message,
types::introspection::{RuntimeInfo, RuntimeVersion},
};
use nix::{
mount::{mount, MsFlags},
sched::{self, CloneFlags},
@@ -29,11 +34,13 @@ enum Action {
Delete(Args),
Help,
Version,
Info,
}
fn parse_args(args: &[OsString]) -> Result<Action> {
let mut help = false;
let mut version = false;
let mut info = false;
let mut shim_args = Args::default();
// Crate `go_flag` is used to keep compatible with go/flag package.
@@ -46,6 +53,7 @@ fn parse_args(args: &[OsString]) -> Result<Action> {
flags.add_flag("publish-binary", &mut shim_args.publish_binary);
flags.add_flag("help", &mut help);
flags.add_flag("version", &mut version);
flags.add_flag("info", &mut info);
})
.context(Error::ParseArgument(format!("{args:?}")))?;
@@ -53,6 +61,8 @@ fn parse_args(args: &[OsString]) -> Result<Action> {
Ok(Action::Help)
} else if version {
Ok(Action::Version)
} else if info {
Ok(Action::Info)
} else if rest_args.is_empty() {
Ok(Action::Run(shim_args))
} else if rest_args[0] == "start" {
@@ -83,6 +93,8 @@ fn show_help(cmd: &OsStr) {
enable debug output in logs
-id string
id of the task
-info
output the runtime info as protobuf (for containerd v2.0+)
-namespace string
namespace that owns the shim
-publish-binary string
@@ -114,6 +126,25 @@ fn show_version(err: Option<anyhow::Error>) {
}
}
fn show_info() -> Result<()> {
let mut version = RuntimeVersion::new();
version.version = config::RUNTIME_VERSION.to_string();
version.revision = config::RUNTIME_GIT_COMMIT.to_string();
let mut info = RuntimeInfo::new();
info.name = config::CONTAINERD_RUNTIME_NAME.to_string();
info.version = Some(version).into();
let data = info
.write_to_bytes()
.context("failed to marshal RuntimeInfo")?;
std::io::stdout()
.write_all(&data)
.context("failed to write RuntimeInfo to stdout")?;
Ok(())
}
fn get_tokio_runtime() -> Result<tokio::runtime::Runtime> {
let worker_threads = std::env::var(ENV_TOKIO_RUNTIME_WORKER_THREADS)
.unwrap_or_default()
@@ -155,6 +186,7 @@ fn real_main() -> Result<()> {
}
Action::Help => show_help(&args[0]),
Action::Version => show_version(None),
Action::Info => show_info().context("show info")?,
}
Ok(())
}