@@ -40,17 +40,17 @@ type stateCheckpoint struct {
40
40
lastChecksum checksum.Checksum
41
41
}
42
42
43
- // NewStateCheckpoint creates new State for keeping track of pod resource allocations with checkpoint backend
43
+ // NewStateCheckpoint creates new State for keeping track of pod resource information with checkpoint backend
44
44
func NewStateCheckpoint (stateDir , checkpointName string ) (State , error ) {
45
45
checkpointManager , err := checkpointmanager .NewCheckpointManager (stateDir )
46
46
if err != nil {
47
- return nil , fmt .Errorf ("failed to initialize checkpoint manager for pod allocation tracking: %v " , err )
47
+ return nil , fmt .Errorf ("failed to initialize checkpoint manager for pod resource information tracking: %w " , err )
48
48
}
49
49
50
50
pra , checksum , err := restoreState (checkpointManager , checkpointName )
51
51
if err != nil {
52
52
//lint:ignore ST1005 user-facing error message
53
- return nil , fmt .Errorf ("could not restore state from checkpoint: %w, please drain this node and delete pod allocation checkpoint file %q before restarting Kubelet" ,
53
+ return nil , fmt .Errorf ("could not restore state from checkpoint: %w, please drain this node and delete pod resource information checkpoint file %q before restarting Kubelet" ,
54
54
err , path .Join (stateDir , checkpointName ))
55
55
}
56
56
@@ -64,7 +64,7 @@ func NewStateCheckpoint(stateDir, checkpointName string) (State, error) {
64
64
}
65
65
66
66
// restores state from a checkpoint and creates it if it doesn't exist
67
- func restoreState (checkpointManager checkpointmanager.CheckpointManager , checkpointName string ) (PodResourceAllocation , checksum.Checksum , error ) {
67
+ func restoreState (checkpointManager checkpointmanager.CheckpointManager , checkpointName string ) (PodResourceInfoMap , checksum.Checksum , error ) {
68
68
checkpoint := & Checkpoint {}
69
69
if err := checkpointManager .GetCheckpoint (checkpointName , checkpoint ); err != nil {
70
70
if err == errors .ErrCheckpointNotFound {
@@ -73,21 +73,21 @@ func restoreState(checkpointManager checkpointmanager.CheckpointManager, checkpo
73
73
return nil , 0 , err
74
74
}
75
75
76
- praInfo , err := checkpoint .GetPodResourceAllocationInfo ()
76
+ praInfo , err := checkpoint .GetPodResourceCheckpointInfo ()
77
77
if err != nil {
78
- return nil , 0 , fmt .Errorf ("failed to get pod resource allocation info : %w" , err )
78
+ return nil , 0 , fmt .Errorf ("failed to get pod resource information : %w" , err )
79
79
}
80
80
81
- klog .V (2 ).InfoS ("State checkpoint: restored pod resource allocation state from checkpoint" )
82
- return praInfo .AllocationEntries , checkpoint .Checksum , nil
81
+ klog .V (2 ).InfoS ("State checkpoint: restored pod resource state from checkpoint" )
82
+ return praInfo .Entries , checkpoint .Checksum , nil
83
83
}
84
84
85
85
// saves state to a checkpoint, caller is responsible for locking
86
86
func (sc * stateCheckpoint ) storeState () error {
87
- podAllocation := sc .cache .GetPodResourceAllocation ()
87
+ resourceInfo := sc .cache .GetPodResourceInfoMap ()
88
88
89
- checkpoint , err := NewCheckpoint (& PodResourceAllocationInfo {
90
- AllocationEntries : podAllocation ,
89
+ checkpoint , err := NewCheckpoint (& PodResourceCheckpointInfo {
90
+ Entries : resourceInfo ,
91
91
})
92
92
if err != nil {
93
93
return fmt .Errorf ("failed to create checkpoint: %w" , err )
@@ -98,47 +98,50 @@ func (sc *stateCheckpoint) storeState() error {
98
98
}
99
99
err = sc .checkpointManager .CreateCheckpoint (sc .checkpointName , checkpoint )
100
100
if err != nil {
101
- klog .ErrorS (err , "Failed to save pod allocation checkpoint" )
101
+ klog .ErrorS (err , "Failed to save pod resource information checkpoint" )
102
102
return err
103
103
}
104
104
sc .lastChecksum = checkpoint .Checksum
105
105
return nil
106
106
}
107
107
108
- // GetContainerResourceAllocation returns current resources allocated to a pod's container
109
- func (sc * stateCheckpoint ) GetContainerResourceAllocation (podUID types.UID , containerName string ) (v1.ResourceRequirements , bool ) {
108
+ // GetContainerResources returns current resources information to a pod's container
109
+ func (sc * stateCheckpoint ) GetContainerResources (podUID types.UID , containerName string ) (v1.ResourceRequirements , bool ) {
110
110
sc .mux .RLock ()
111
111
defer sc .mux .RUnlock ()
112
- return sc .cache .GetContainerResourceAllocation (podUID , containerName )
112
+ return sc .cache .GetContainerResources (podUID , containerName )
113
113
}
114
114
115
- // GetPodResourceAllocation returns current pod resource allocation
116
- func (sc * stateCheckpoint ) GetPodResourceAllocation () PodResourceAllocation {
115
+ // GetPodResourceInfoMap returns current pod resource information
116
+ func (sc * stateCheckpoint ) GetPodResourceInfoMap () PodResourceInfoMap {
117
117
sc .mux .RLock ()
118
118
defer sc .mux .RUnlock ()
119
- return sc .cache .GetPodResourceAllocation ()
119
+ return sc .cache .GetPodResourceInfoMap ()
120
120
}
121
121
122
- // SetContainerResourceAllocation sets resources allocated to a pod's container
123
- func (sc * stateCheckpoint ) SetContainerResourceAllocation (podUID types.UID , containerName string , alloc v1.ResourceRequirements ) error {
122
+ // SetContainerResoruces sets resources information for a pod's container
123
+ func (sc * stateCheckpoint ) SetContainerResources (podUID types.UID , containerName string , resources v1.ResourceRequirements ) error {
124
124
sc .mux .Lock ()
125
125
defer sc .mux .Unlock ()
126
- sc .cache .SetContainerResourceAllocation (podUID , containerName , alloc )
126
+ err := sc .cache .SetContainerResources (podUID , containerName , resources )
127
+ if err != nil {
128
+ return err
129
+ }
127
130
return sc .storeState ()
128
131
}
129
132
130
- // SetPodResourceAllocation sets pod resource allocation
131
- func (sc * stateCheckpoint ) SetPodResourceAllocation (podUID types.UID , alloc map [ string ]v1. ResourceRequirements ) error {
133
+ // SetPodResourceInfo sets pod resource information
134
+ func (sc * stateCheckpoint ) SetPodResourceInfo (podUID types.UID , resourceInfo PodResourceInfo ) error {
132
135
sc .mux .Lock ()
133
136
defer sc .mux .Unlock ()
134
- err := sc .cache .SetPodResourceAllocation (podUID , alloc )
137
+ err := sc .cache .SetPodResourceInfo (podUID , resourceInfo )
135
138
if err != nil {
136
139
return err
137
140
}
138
141
return sc .storeState ()
139
142
}
140
143
141
- // Delete deletes allocations for specified pod
144
+ // Delete deletes resource information for specified pod
142
145
func (sc * stateCheckpoint ) RemovePod (podUID types.UID ) error {
143
146
sc .mux .Lock ()
144
147
defer sc .mux .Unlock ()
@@ -161,19 +164,19 @@ func NewNoopStateCheckpoint() State {
161
164
return & noopStateCheckpoint {}
162
165
}
163
166
164
- func (sc * noopStateCheckpoint ) GetContainerResourceAllocation (_ types.UID , _ string ) (v1.ResourceRequirements , bool ) {
167
+ func (sc * noopStateCheckpoint ) GetContainerResources (_ types.UID , _ string ) (v1.ResourceRequirements , bool ) {
165
168
return v1.ResourceRequirements {}, false
166
169
}
167
170
168
- func (sc * noopStateCheckpoint ) GetPodResourceAllocation () PodResourceAllocation {
171
+ func (sc * noopStateCheckpoint ) GetPodResourceInfoMap () PodResourceInfoMap {
169
172
return nil
170
173
}
171
174
172
- func (sc * noopStateCheckpoint ) SetContainerResourceAllocation (_ types.UID , _ string , _ v1.ResourceRequirements ) error {
175
+ func (sc * noopStateCheckpoint ) SetContainerResources (_ types.UID , _ string , _ v1.ResourceRequirements ) error {
173
176
return nil
174
177
}
175
178
176
- func (sc * noopStateCheckpoint ) SetPodResourceAllocation (_ types.UID , _ map [ string ]v1. ResourceRequirements ) error {
179
+ func (sc * noopStateCheckpoint ) SetPodResourceInfo (_ types.UID , _ PodResourceInfo ) error {
177
180
return nil
178
181
}
179
182
0 commit comments