Skip to content

Commit c38aad0

Browse files
authored
Merge pull request kubernetes#130186 from tallclair/resize-status-cache
Move PodResizeStatus cache out of allocated state
2 parents 821bc2e + 3f4ef42 commit c38aad0

File tree

5 files changed

+19
-58
lines changed

5 files changed

+19
-58
lines changed

pkg/kubelet/status/fake_status_manager.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import (
2828
)
2929

3030
type fakeManager struct {
31-
state state.State
31+
state state.State
32+
podResizeStatuses map[types.UID]v1.PodResizeStatus
3233
}
3334

3435
func (m *fakeManager) Start() {
@@ -72,7 +73,7 @@ func (m *fakeManager) GetContainerResourceAllocation(podUID string, containerNam
7273
}
7374

7475
func (m *fakeManager) GetPodResizeStatus(podUID types.UID) v1.PodResizeStatus {
75-
return m.state.GetPodResizeStatus(string(podUID))
76+
return m.podResizeStatuses[podUID]
7677
}
7778

7879
func (m *fakeManager) UpdatePodFromAllocation(pod *v1.Pod) (*v1.Pod, bool) {
@@ -102,12 +103,13 @@ func (m *fakeManager) SetPodAllocation(pod *v1.Pod) error {
102103
}
103104

104105
func (m *fakeManager) SetPodResizeStatus(podUID types.UID, resizeStatus v1.PodResizeStatus) {
105-
m.state.SetPodResizeStatus(string(podUID), resizeStatus)
106+
m.podResizeStatuses[podUID] = resizeStatus
106107
}
107108

108109
// NewFakeManager creates empty/fake memory manager
109110
func NewFakeManager() Manager {
110111
return &fakeManager{
111-
state: state.NewStateMemory(state.PodResourceAllocation{}),
112+
state: state.NewStateMemory(state.PodResourceAllocation{}),
113+
podResizeStatuses: make(map[types.UID]v1.PodResizeStatus),
112114
}
113115
}

pkg/kubelet/status/state/state.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ func (pr PodResourceAllocation) Clone() PodResourceAllocation {
4242
type Reader interface {
4343
GetContainerResourceAllocation(podUID string, containerName string) (v1.ResourceRequirements, bool)
4444
GetPodResourceAllocation() PodResourceAllocation
45-
GetPodResizeStatus(podUID string) v1.PodResizeStatus
4645
}
4746

4847
type writer interface {
4948
SetContainerResourceAllocation(podUID string, containerName string, alloc v1.ResourceRequirements) error
5049
SetPodResourceAllocation(podUID string, alloc map[string]v1.ResourceRequirements) error
51-
SetPodResizeStatus(podUID string, resizeStatus v1.PodResizeStatus)
5250
Delete(podUID string, containerName string) error
5351
}
5452

pkg/kubelet/status/state/state_checkpoint.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ func (sc *stateCheckpoint) GetPodResourceAllocation() PodResourceAllocation {
112112
return sc.cache.GetPodResourceAllocation()
113113
}
114114

115-
// GetPodResizeStatus returns the last resize decision for a pod
116-
func (sc *stateCheckpoint) GetPodResizeStatus(podUID string) v1.PodResizeStatus {
117-
sc.mux.RLock()
118-
defer sc.mux.RUnlock()
119-
return sc.cache.GetPodResizeStatus(podUID)
120-
}
121-
122115
// SetContainerResourceAllocation sets resources allocated to a pod's container
123116
func (sc *stateCheckpoint) SetContainerResourceAllocation(podUID string, containerName string, alloc v1.ResourceRequirements) error {
124117
sc.mux.Lock()
@@ -138,13 +131,6 @@ func (sc *stateCheckpoint) SetPodResourceAllocation(podUID string, alloc map[str
138131
return sc.storeState()
139132
}
140133

141-
// SetPodResizeStatus sets the last resize decision for a pod
142-
func (sc *stateCheckpoint) SetPodResizeStatus(podUID string, resizeStatus v1.PodResizeStatus) {
143-
sc.mux.Lock()
144-
defer sc.mux.Unlock()
145-
sc.cache.SetPodResizeStatus(podUID, resizeStatus)
146-
}
147-
148134
// Delete deletes allocations for specified pod
149135
func (sc *stateCheckpoint) Delete(podUID string, containerName string) error {
150136
sc.mux.Lock()
@@ -168,10 +154,6 @@ func (sc *noopStateCheckpoint) GetPodResourceAllocation() PodResourceAllocation
168154
return nil
169155
}
170156

171-
func (sc *noopStateCheckpoint) GetPodResizeStatus(_ string) v1.PodResizeStatus {
172-
return ""
173-
}
174-
175157
func (sc *noopStateCheckpoint) SetContainerResourceAllocation(_ string, _ string, _ v1.ResourceRequirements) error {
176158
return nil
177159
}
@@ -180,8 +162,6 @@ func (sc *noopStateCheckpoint) SetPodResourceAllocation(_ string, _ map[string]v
180162
return nil
181163
}
182164

183-
func (sc *noopStateCheckpoint) SetPodResizeStatus(_ string, _ v1.PodResizeStatus) {}
184-
185165
func (sc *noopStateCheckpoint) Delete(_ string, _ string) error {
186166
return nil
187167
}

pkg/kubelet/status/state/state_mem.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import (
2525

2626
type stateMemory struct {
2727
sync.RWMutex
28-
podAllocation PodResourceAllocation
29-
podResizeStatus PodResizeStatus
28+
podAllocation PodResourceAllocation
3029
}
3130

3231
var _ State = &stateMemory{}
@@ -38,8 +37,7 @@ func NewStateMemory(alloc PodResourceAllocation) State {
3837
}
3938
klog.V(2).InfoS("Initialized new in-memory state store for pod resource allocation tracking")
4039
return &stateMemory{
41-
podAllocation: alloc,
42-
podResizeStatus: PodResizeStatus{},
40+
podAllocation: alloc,
4341
}
4442
}
4543

@@ -57,13 +55,6 @@ func (s *stateMemory) GetPodResourceAllocation() PodResourceAllocation {
5755
return s.podAllocation.Clone()
5856
}
5957

60-
func (s *stateMemory) GetPodResizeStatus(podUID string) v1.PodResizeStatus {
61-
s.RLock()
62-
defer s.RUnlock()
63-
64-
return s.podResizeStatus[podUID]
65-
}
66-
6758
func (s *stateMemory) SetContainerResourceAllocation(podUID string, containerName string, alloc v1.ResourceRequirements) error {
6859
s.Lock()
6960
defer s.Unlock()
@@ -86,23 +77,10 @@ func (s *stateMemory) SetPodResourceAllocation(podUID string, alloc map[string]v
8677
return nil
8778
}
8879

89-
func (s *stateMemory) SetPodResizeStatus(podUID string, resizeStatus v1.PodResizeStatus) {
90-
s.Lock()
91-
defer s.Unlock()
92-
93-
if resizeStatus != "" {
94-
s.podResizeStatus[podUID] = resizeStatus
95-
} else {
96-
delete(s.podResizeStatus, podUID)
97-
}
98-
klog.V(3).InfoS("Updated pod resize state", "podUID", podUID, "resizeStatus", resizeStatus)
99-
}
100-
10180
func (s *stateMemory) deleteContainer(podUID string, containerName string) {
10281
delete(s.podAllocation[podUID], containerName)
10382
if len(s.podAllocation[podUID]) == 0 {
10483
delete(s.podAllocation, podUID)
105-
delete(s.podResizeStatus, podUID)
10684
}
10785
klog.V(3).InfoS("Deleted pod resource allocation", "podUID", podUID, "containerName", containerName)
10886
}
@@ -112,7 +90,6 @@ func (s *stateMemory) Delete(podUID string, containerName string) error {
11290
defer s.Unlock()
11391
if len(containerName) == 0 {
11492
delete(s.podAllocation, podUID)
115-
delete(s.podResizeStatus, podUID)
11693
klog.V(3).InfoS("Deleted pod resource allocation and resize state", "podUID", podUID)
11794
return nil
11895
}

pkg/kubelet/status/status_manager.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ type manager struct {
7272
kubeClient clientset.Interface
7373
podManager PodManager
7474
// Map from pod UID to sync status of the corresponding pod.
75-
podStatuses map[types.UID]versionedPodStatus
76-
podStatusesLock sync.RWMutex
77-
podStatusChannel chan struct{}
75+
podStatuses map[types.UID]versionedPodStatus
76+
podResizeStatuses map[types.UID]v1.PodResizeStatus
77+
podStatusesLock sync.RWMutex
78+
podStatusChannel chan struct{}
7879
// Map from (mirror) pod UID to latest status version successfully sent to the API server.
7980
// apiStatusVersions must only be accessed from the sync thread.
8081
apiStatusVersions map[kubetypes.MirrorPodUID]uint64
@@ -174,6 +175,7 @@ func NewManager(kubeClient clientset.Interface, podManager PodManager, podDeleti
174175
kubeClient: kubeClient,
175176
podManager: podManager,
176177
podStatuses: make(map[types.UID]versionedPodStatus),
178+
podResizeStatuses: make(map[types.UID]v1.PodResizeStatus),
177179
podStatusChannel: make(chan struct{}, 1),
178180
apiStatusVersions: make(map[kubetypes.MirrorPodUID]uint64),
179181
podDeletionSafety: podDeletionSafety,
@@ -303,7 +305,7 @@ func updatePodFromAllocation(pod *v1.Pod, allocs state.PodResourceAllocation) (*
303305
func (m *manager) GetPodResizeStatus(podUID types.UID) v1.PodResizeStatus {
304306
m.podStatusesLock.RLock()
305307
defer m.podStatusesLock.RUnlock()
306-
return m.state.GetPodResizeStatus(string(podUID))
308+
return m.podResizeStatuses[podUID]
307309
}
308310

309311
// SetPodAllocation checkpoints the resources allocated to a pod's containers
@@ -331,9 +333,9 @@ func (m *manager) SetPodAllocation(pod *v1.Pod) error {
331333

332334
// SetPodResizeStatus checkpoints the last resizing decision for the pod.
333335
func (m *manager) SetPodResizeStatus(podUID types.UID, resizeStatus v1.PodResizeStatus) {
334-
m.podStatusesLock.RLock()
335-
defer m.podStatusesLock.RUnlock()
336-
m.state.SetPodResizeStatus(string(podUID), resizeStatus)
336+
m.podStatusesLock.Lock()
337+
defer m.podStatusesLock.Unlock()
338+
m.podResizeStatuses[podUID] = resizeStatus
337339
}
338340

339341
func (m *manager) GetPodStatus(uid types.UID) (v1.PodStatus, bool) {
@@ -803,6 +805,7 @@ func (m *manager) deletePodStatus(uid types.UID) {
803805
delete(m.podStatuses, uid)
804806
m.podStartupLatencyHelper.DeletePodStartupState(uid)
805807
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
808+
delete(m.podResizeStatuses, uid)
806809
m.state.Delete(string(uid), "")
807810
}
808811
}
@@ -816,6 +819,7 @@ func (m *manager) RemoveOrphanedStatuses(podUIDs map[types.UID]bool) {
816819
klog.V(5).InfoS("Removing pod from status map.", "podUID", key)
817820
delete(m.podStatuses, key)
818821
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
822+
delete(m.podResizeStatuses, key)
819823
m.state.Delete(string(key), "")
820824
}
821825
}

0 commit comments

Comments
 (0)