diff --git a/pkg/config/cos.go b/pkg/config/cos.go index dc357f848..ea1c0466e 100644 --- a/pkg/config/cos.go +++ b/pkg/config/cos.go @@ -149,6 +149,12 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) { for _, module := range cfg.OS.Modules { initramfs.Commands = append(initramfs.Commands, "modprobe "+module) } + // Delete the cpu_manager_state file during the initramfs stage. During a reboot, this state file is always reverted + // because it was originally created during the system installation, becoming part of the root filesystem. + // As a result, the policy in cpu_manager_state file is "none" (default policy) after reboot. If we've already set + // the cpu-manager-policy to "static" before reboot, this mismatch can prevent kubelet from starting, + // and make the entire node unavailable. + initramfs.Commands = append(initramfs.Commands, "rm -f /var/lib/kubelet/cpu_manager_state") initramfs.Sysctl = cfg.OS.Sysctls initramfs.Environment = cfg.OS.Environment diff --git a/pkg/config/cos_test.go b/pkg/config/cos_test.go index 09057e94e..93c41f870 100644 --- a/pkg/config/cos_test.go +++ b/pkg/config/cos_test.go @@ -126,6 +126,16 @@ func TestConvertToCos_VerifyNetworkInstallMode(t *testing.T) { assert.False(t, containsFile(yipConfig.Stages["initramfs"][0].Files, "/etc/sysconfig/network/ifcfg-ens3")) } +func TestConvertToCos_Remove_CPUManagerState(t *testing.T) { + conf, err := LoadHarvesterConfig(util.LoadFixture(t, "harvester-config.yaml")) + assert.NoError(t, err) + + yipConfig, err := ConvertToCOS(conf) + assert.NoError(t, err) + + assert.Contains(t, yipConfig.Stages["initramfs"][0].Commands, "rm -f /var/lib/kubelet/cpu_manager_state") +} + func containsFile(files []yipSchema.File, fileName string) bool { for _, v := range files { if v.Path == fileName {