Skip to content

Commit

Permalink
clear pod cpuset
Browse files Browse the repository at this point in the history
When the kubelet configures cpuManagerPolicy as static, the Pod will specify CPU IDs for CPU affinity. Due to the different cpusets of the guest OS and host OS, this can lead to configuration failures. There is no need for CPU affinity in the guest OS, so the Pod's cpuset should be cleared.

Signed-off-by: MorningTZH <[email protected]>
  • Loading branch information
morningtzh committed Jan 10, 2025
1 parent 3374d0a commit 790a23e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vmm/sandbox/src/container/handler/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use containerd_sandbox::{
error::Error,
spec::{JsonSpec, Mount},
};
use log::debug;
use path_clean::clean;
use vmm_common::{
ETC_HOSTNAME, ETC_HOSTS, ETC_RESOLV, HOSTNAME_FILENAME, HOSTS_FILENAME, KUASAR_STATE_DIR,
Expand Down Expand Up @@ -69,6 +70,21 @@ where
if let Some(p) = spec.process.as_mut() {
p.apparmor_profile = "".to_string();
}

// When the kubelet configures cpuManagerPolicy as static, the Pod will specify CPU IDs
// for CPU affinity. Due to the different cpusets of the guest OS and host OS, this can
// lead to configuration failures. There is no need for CPU affinity in the guest OS,
// so the Pod's cpuset should be cleared.
spec.linux
.as_mut()
.and_then(|l| l.resources.as_mut())
.and_then(|r| {
r.cpu.as_mut().map(|cpu| {
debug!("Container cpuset will be clear: {:?}", &cpu.cpus);
cpu.cpus = "".to_string();
})
});

// Update sandbox files mounts for container
container_mounts(&shared_path, spec);
let spec_str = serde_json::to_string(spec)
Expand Down

0 comments on commit 790a23e

Please sign in to comment.