diff --git a/pkg/kubelet/allocation/allocation_manager.go b/pkg/kubelet/allocation/allocation_manager.go index 576612c52a1..dac8f2f1fd0 100644 --- a/pkg/kubelet/allocation/allocation_manager.go +++ b/pkg/kubelet/allocation/allocation_manager.go @@ -176,12 +176,12 @@ func allocationFromPod(pod *v1.Pod) map[string]v1.ResourceRequirements { } func (m *manager) RemovePod(uid types.UID) { - if err := m.allocated.Delete(uid, ""); err != nil { + if err := m.allocated.RemovePod(uid); err != nil { // If the deletion fails, it will be retried by RemoveOrphanedPods, so we can safely ignore the error. klog.V(3).ErrorS(err, "Failed to delete pod allocation", "podUID", uid) } - if err := m.actuated.Delete(uid, ""); err != nil { + if err := m.actuated.RemovePod(uid); err != nil { // If the deletion fails, it will be retried by RemoveOrphanedPods, so we can safely ignore the error. klog.V(3).ErrorS(err, "Failed to delete pod allocation", "podUID", uid) } diff --git a/pkg/kubelet/allocation/state/state.go b/pkg/kubelet/allocation/state/state.go index fff569ce3d1..21d240294ab 100644 --- a/pkg/kubelet/allocation/state/state.go +++ b/pkg/kubelet/allocation/state/state.go @@ -46,7 +46,7 @@ type Reader interface { type writer interface { SetContainerResourceAllocation(podUID types.UID, containerName string, alloc v1.ResourceRequirements) error SetPodResourceAllocation(podUID types.UID, alloc map[string]v1.ResourceRequirements) error - Delete(podUID types.UID, containerName string) error + RemovePod(podUID types.UID) error // RemoveOrphanedPods removes the stored state for any pods not included in the set of remaining pods. RemoveOrphanedPods(remainingPods sets.Set[types.UID]) } diff --git a/pkg/kubelet/allocation/state/state_checkpoint.go b/pkg/kubelet/allocation/state/state_checkpoint.go index 54807991967..df07cae051f 100644 --- a/pkg/kubelet/allocation/state/state_checkpoint.go +++ b/pkg/kubelet/allocation/state/state_checkpoint.go @@ -139,13 +139,13 @@ func (sc *stateCheckpoint) SetPodResourceAllocation(podUID types.UID, alloc map[ } // Delete deletes allocations for specified pod -func (sc *stateCheckpoint) Delete(podUID types.UID, containerName string) error { +func (sc *stateCheckpoint) RemovePod(podUID types.UID) error { sc.mux.Lock() defer sc.mux.Unlock() // Skip writing the checkpoint for pod deletion, since there is no side effect to // keeping a deleted pod. Deleted pods will eventually be cleaned up by RemoveOrphanedPods. // The deletion will be stored the next time a non-delete update is made. - return sc.cache.Delete(podUID, "") + return sc.cache.RemovePod(podUID) } func (sc *stateCheckpoint) RemoveOrphanedPods(remainingPods sets.Set[types.UID]) { @@ -177,7 +177,7 @@ func (sc *noopStateCheckpoint) SetPodResourceAllocation(_ types.UID, _ map[strin return nil } -func (sc *noopStateCheckpoint) Delete(_ types.UID, _ string) error { +func (sc *noopStateCheckpoint) RemovePod(_ types.UID) error { return nil } diff --git a/pkg/kubelet/allocation/state/state_mem.go b/pkg/kubelet/allocation/state/state_mem.go index 7c46cd36183..5ad0e57f53e 100644 --- a/pkg/kubelet/allocation/state/state_mem.go +++ b/pkg/kubelet/allocation/state/state_mem.go @@ -79,23 +79,11 @@ func (s *stateMemory) SetPodResourceAllocation(podUID types.UID, alloc map[strin return nil } -func (s *stateMemory) deleteContainer(podUID types.UID, containerName string) { - delete(s.podAllocation[podUID], containerName) - if len(s.podAllocation[podUID]) == 0 { - delete(s.podAllocation, podUID) - } - klog.V(3).InfoS("Deleted pod resource allocation", "podUID", podUID, "containerName", containerName) -} - -func (s *stateMemory) Delete(podUID types.UID, containerName string) error { +func (s *stateMemory) RemovePod(podUID types.UID) error { s.Lock() defer s.Unlock() - if len(containerName) == 0 { - delete(s.podAllocation, podUID) - klog.V(3).InfoS("Deleted pod resource allocation and resize state", "podUID", podUID) - return nil - } - s.deleteContainer(podUID, containerName) + delete(s.podAllocation, podUID) + klog.V(3).InfoS("Deleted pod resource allocation", "podUID", podUID) return nil }