kata-agent: fixing bug of unable setting hostname correctly.

When do update_container_namespaces updating namespaces, setting
all UTS(and IPC) namespace paths to None resulted in hostnames
set prior to the update becoming ineffective. This was primarily
due to an error made while aligning with the oci spec: in an attempt
to match empty strings with None values in oci-spec-rs, all paths
were incorrectly set to None.

Fixes #10325

Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn
2024-10-12 17:39:00 +08:00
committed by stevenhorsman
parent 98886a7571
commit 3dabe0f5f0

View File

@@ -1679,13 +1679,19 @@ fn update_container_namespaces(
if let Some(namespaces) = linux.namespaces_mut() {
for namespace in namespaces.iter_mut() {
if namespace.typ().to_string() == NSTYPEIPC {
namespace.set_path(Some(PathBuf::from(&sandbox.shared_ipcns.path.clone())));
namespace.set_path(None);
namespace.set_path(if !sandbox.shared_ipcns.path.is_empty() {
Some(PathBuf::from(&sandbox.shared_ipcns.path))
} else {
None
});
continue;
}
if namespace.typ().to_string() == NSTYPEUTS {
namespace.set_path(Some(PathBuf::from(&sandbox.shared_utsns.path.clone())));
namespace.set_path(None);
namespace.set_path(if !sandbox.shared_utsns.path.is_empty() {
Some(PathBuf::from(&sandbox.shared_utsns.path))
} else {
None
});
continue;
}
}