Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions pkg/kubelet/cm/cpumanager/policy_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -217,26 +218,22 @@ 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
}

// State has already been initialized from file (is not empty)
// 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())
}
} 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())
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pkg/kubelet/cm/cpumanager/policy_static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down