mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
cm: handle nil cpumanager avoiding segfault
If the cpumanager feature gate is disabled, the corresponsing field of the containerManager will be nil. A couple functions don't check for this occurrence and happily deference the pointer unconditionally, leading to possible segfaults. The relevant functions were introduced to support the podresources API, so to trigger this segfault all the following are needed: - cpumanager feature gate has to be disabled explicitely - any podresources API must be called Worth pointing out that when the new functions were introduced (around kubernetes 1.20) the default feature gate for cpumanager was already set to true, hence this bug is expected to be triggered rarely. Signed-off-by: Francesco Romani <fromani@redhat.com>
This commit is contained in:
parent
0d9c29078b
commit
369416b763
@ -1073,12 +1073,18 @@ func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.Conta
|
||||
}
|
||||
|
||||
func (cm *containerManagerImpl) GetCPUs(podUID, containerName string) []int64 {
|
||||
if cm.cpuManager != nil {
|
||||
return cm.cpuManager.GetCPUs(podUID, containerName).ToSliceNoSortInt64()
|
||||
}
|
||||
return []int64{}
|
||||
}
|
||||
|
||||
func (cm *containerManagerImpl) GetAllocatableCPUs() []int64 {
|
||||
if cm.cpuManager != nil {
|
||||
return cm.cpuManager.GetAllocatableCPUs().ToSliceNoSortInt64()
|
||||
}
|
||||
return []int64{}
|
||||
}
|
||||
|
||||
func (cm *containerManagerImpl) ShouldResetExtendedResourceCapacity() bool {
|
||||
return cm.deviceManager.ShouldResetExtendedResourceCapacity()
|
||||
|
Loading…
Reference in New Issue
Block a user