Skip to content

Commit e8547d8

Browse files
committed
Cleanup unused container parameter from allocation state Delete
1 parent 05a9c06 commit e8547d8

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

pkg/kubelet/allocation/allocation_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func allocationFromPod(pod *v1.Pod) map[string]v1.ResourceRequirements {
176176
}
177177

178178
func (m *manager) RemovePod(uid types.UID) {
179-
if err := m.allocated.Delete(uid, ""); err != nil {
179+
if err := m.allocated.RemovePod(uid); err != nil {
180180
// If the deletion fails, it will be retried by RemoveOrphanedPods, so we can safely ignore the error.
181181
klog.V(3).ErrorS(err, "Failed to delete pod allocation", "podUID", uid)
182182
}
183183

184-
if err := m.actuated.Delete(uid, ""); err != nil {
184+
if err := m.actuated.RemovePod(uid); err != nil {
185185
// If the deletion fails, it will be retried by RemoveOrphanedPods, so we can safely ignore the error.
186186
klog.V(3).ErrorS(err, "Failed to delete pod allocation", "podUID", uid)
187187
}

pkg/kubelet/allocation/state/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Reader interface {
4646
type writer interface {
4747
SetContainerResourceAllocation(podUID types.UID, containerName string, alloc v1.ResourceRequirements) error
4848
SetPodResourceAllocation(podUID types.UID, alloc map[string]v1.ResourceRequirements) error
49-
Delete(podUID types.UID, containerName string) error
49+
RemovePod(podUID types.UID) error
5050
// RemoveOrphanedPods removes the stored state for any pods not included in the set of remaining pods.
5151
RemoveOrphanedPods(remainingPods sets.Set[types.UID])
5252
}

pkg/kubelet/allocation/state/state_checkpoint.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ func (sc *stateCheckpoint) SetPodResourceAllocation(podUID types.UID, alloc map[
139139
}
140140

141141
// Delete deletes allocations for specified pod
142-
func (sc *stateCheckpoint) Delete(podUID types.UID, containerName string) error {
142+
func (sc *stateCheckpoint) RemovePod(podUID types.UID) error {
143143
sc.mux.Lock()
144144
defer sc.mux.Unlock()
145145
// Skip writing the checkpoint for pod deletion, since there is no side effect to
146146
// keeping a deleted pod. Deleted pods will eventually be cleaned up by RemoveOrphanedPods.
147147
// The deletion will be stored the next time a non-delete update is made.
148-
return sc.cache.Delete(podUID, "")
148+
return sc.cache.RemovePod(podUID)
149149
}
150150

151151
func (sc *stateCheckpoint) RemoveOrphanedPods(remainingPods sets.Set[types.UID]) {
@@ -177,7 +177,7 @@ func (sc *noopStateCheckpoint) SetPodResourceAllocation(_ types.UID, _ map[strin
177177
return nil
178178
}
179179

180-
func (sc *noopStateCheckpoint) Delete(_ types.UID, _ string) error {
180+
func (sc *noopStateCheckpoint) RemovePod(_ types.UID) error {
181181
return nil
182182
}
183183

pkg/kubelet/allocation/state/state_mem.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,11 @@ func (s *stateMemory) SetPodResourceAllocation(podUID types.UID, alloc map[strin
7979
return nil
8080
}
8181

82-
func (s *stateMemory) deleteContainer(podUID types.UID, containerName string) {
83-
delete(s.podAllocation[podUID], containerName)
84-
if len(s.podAllocation[podUID]) == 0 {
85-
delete(s.podAllocation, podUID)
86-
}
87-
klog.V(3).InfoS("Deleted pod resource allocation", "podUID", podUID, "containerName", containerName)
88-
}
89-
90-
func (s *stateMemory) Delete(podUID types.UID, containerName string) error {
82+
func (s *stateMemory) RemovePod(podUID types.UID) error {
9183
s.Lock()
9284
defer s.Unlock()
93-
if len(containerName) == 0 {
94-
delete(s.podAllocation, podUID)
95-
klog.V(3).InfoS("Deleted pod resource allocation and resize state", "podUID", podUID)
96-
return nil
97-
}
98-
s.deleteContainer(podUID, containerName)
85+
delete(s.podAllocation, podUID)
86+
klog.V(3).InfoS("Deleted pod resource allocation", "podUID", podUID)
9987
return nil
10088
}
10189

0 commit comments

Comments
 (0)