diff --git a/pkg/kubelet/cm/cpumanager/policy_static.go b/pkg/kubelet/cm/cpumanager/policy_static.go index 2120b5f789005..5688ca67862c7 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static.go +++ b/pkg/kubelet/cm/cpumanager/policy_static.go @@ -205,7 +205,8 @@ func (p *staticPolicy) validateState(s state.State) error { tmpDefaultCPUset := s.GetDefaultCPUSet() allCPUs := p.topology.CPUDetails.CPUs() - if p.options.StrictCPUReservation { + strictCPUReservation := p.options.StrictCPUReservation || managed.IsEnabled() + if strictCPUReservation { allCPUs = allCPUs.Difference(p.reservedCPUs) } @@ -217,10 +218,6 @@ func (p *staticPolicy) validateState(s state.State) error { // state is empty initialize s.SetDefaultCPUSet(allCPUs) klog.InfoS("Static policy initialized", "defaultCPUSet", allCPUs) - if managed.IsEnabled() { - defaultCpus := s.GetDefaultCPUSet().Difference(p.reservedCPUs) - s.SetDefaultCPUSet(defaultCpus) - } return nil } @@ -228,7 +225,7 @@ func (p *staticPolicy) validateState(s state.State) error { // 1. Check if the reserved cpuset is not part of default cpuset because: // - kube/system reserved have changed (increased) - may lead to some containers not being able to start // - user tampered with file - if p.options.StrictCPUReservation { + if strictCPUReservation { if !p.reservedCPUs.Intersection(tmpDefaultCPUset).IsEmpty() { return fmt.Errorf("some of strictly reserved cpus: \"%s\" are present in defaultCpuSet: \"%s\"", p.reservedCPUs.Intersection(tmpDefaultCPUset).String(), tmpDefaultCPUset.String()) @@ -236,7 +233,7 @@ func (p *staticPolicy) validateState(s state.State) error { } else { // 2. This only applies when managed mode is disabled. Active workload partitioning feature // removes the reserved cpus from the default cpu mask on purpose. - if !managed.IsEnabled() && !p.reservedCPUs.Intersection(tmpDefaultCPUset).Equals(p.reservedCPUs) { + if !p.reservedCPUs.Intersection(tmpDefaultCPUset).Equals(p.reservedCPUs) { return fmt.Errorf("not all reserved cpus: \"%s\" are present in defaultCpuSet: \"%s\"", p.reservedCPUs.String(), tmpDefaultCPUset.String()) } @@ -268,17 +265,9 @@ func (p *staticPolicy) validateState(s state.State) error { } } totalKnownCPUs = totalKnownCPUs.Union(tmpCPUSets...) - availableCPUs := p.topology.CPUDetails.CPUs() - - // CPU (workload) partitioning removes reserved cpus - // from the default mask intentionally - if managed.IsEnabled() { - availableCPUs = availableCPUs.Difference(p.reservedCPUs) - } - - if !totalKnownCPUs.Equals(availableCPUs) { + if !totalKnownCPUs.Equals(allCPUs) { return fmt.Errorf("current set of available CPUs \"%s\" doesn't match with CPUs in state \"%s\"", - availableCPUs.String(), totalKnownCPUs.String()) + allCPUs.String(), totalKnownCPUs.String()) } return nil diff --git a/pkg/kubelet/cm/cpumanager/policy_static_test.go b/pkg/kubelet/cm/cpumanager/policy_static_test.go index e51f7336b57b6..54cf988070302 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static_test.go +++ b/pkg/kubelet/cm/cpumanager/policy_static_test.go @@ -1021,6 +1021,18 @@ func TestStaticPolicyStartWithResvList(t *testing.T) { stDefaultCPUSet: cpuset.New(), expCSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11), }, + { + // context issue: https://issues.redhat.com/browse/OCPBUGS-77659 + // start, record state before run any pods, restart empty + description: "empty cpuset with StrictCPUReservationOption enabled, simulate restart from empty", + topo: topoDualSocketHT, + numReservedCPUs: 2, + reserved: cpuset.New(0, 1), + cpuPolicyOptions: map[string]string{StrictCPUReservationOption: "true"}, + stAssignments: state.ContainerCPUAssignments{}, + stDefaultCPUSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11), + expCSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11), + }, { description: "reserved cores 0 & 1 are not present in available cpuset", topo: topoDualSocketHT,