Skip to content

Commit bf4f183

Browse files
committed
Don't clear resize status when resources are missing
1 parent 8420165 commit bf4f183

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pkg/kubelet/kubelet_pods.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,23 +1772,40 @@ func (kl *Kubelet) determinePodResizeStatus(allocatedPod *v1.Pod, podStatus *kub
17721772
func allocatedResourcesMatchStatus(allocatedPod *v1.Pod, podStatus *kubecontainer.PodStatus) bool {
17731773
for _, c := range allocatedPod.Spec.Containers {
17741774
if cs := podStatus.FindContainerStatusByName(c.Name); cs != nil {
1775-
if cs.State != kubecontainer.ContainerStateRunning || cs.Resources == nil {
1775+
if cs.State != kubecontainer.ContainerStateRunning {
17761776
// If the container isn't running, it isn't resizing.
17771777
continue
17781778
}
17791779

1780+
cpuReq, hasCPUReq := c.Resources.Requests[v1.ResourceCPU]
1781+
cpuLim, hasCPULim := c.Resources.Limits[v1.ResourceCPU]
1782+
memLim, hasMemLim := c.Resources.Limits[v1.ResourceMemory]
1783+
1784+
if cs.Resources == nil {
1785+
if hasCPUReq || hasCPULim || hasMemLim {
1786+
// Container status is missing Resources information, but the container does
1787+
// have resizable resources configured.
1788+
klog.ErrorS(nil, "Missing runtime resources information for resizing container",
1789+
"pod", format.Pod(allocatedPod), "container", c.Name)
1790+
return false // We don't want to clear resize status with insufficient information.
1791+
} else {
1792+
// No resizable resources configured; this might be ok.
1793+
continue
1794+
}
1795+
}
1796+
17801797
// Only compare resizeable resources, and only compare resources that are explicitly configured.
1781-
if cpuReq, present := c.Resources.Requests[v1.ResourceCPU]; present {
1798+
if hasCPUReq {
17821799
if !cpuReq.Equal(*cs.Resources.CPURequest) {
17831800
return false
17841801
}
17851802
}
1786-
if cpuLim, present := c.Resources.Limits[v1.ResourceCPU]; present {
1803+
if hasCPULim {
17871804
if !cpuLim.Equal(*cs.Resources.CPULimit) {
17881805
return false
17891806
}
17901807
}
1791-
if memLim, present := c.Resources.Limits[v1.ResourceMemory]; present {
1808+
if hasMemLim {
17921809
if !memLim.Equal(*cs.Resources.MemoryLimit) {
17931810
return false
17941811
}

0 commit comments

Comments
 (0)