@@ -77,6 +77,7 @@ import (
77
77
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
78
78
"k8s.io/kubernetes/pkg/api/v1/resource"
79
79
"k8s.io/kubernetes/pkg/features"
80
+ "k8s.io/kubernetes/pkg/kubelet/allocation"
80
81
kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"
81
82
"k8s.io/kubernetes/pkg/kubelet/apis/config/v1beta1"
82
83
"k8s.io/kubernetes/pkg/kubelet/apis/podresources"
@@ -662,7 +663,8 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
662
663
klet .mirrorPodClient = kubepod .NewBasicMirrorClient (klet .kubeClient , string (nodeName ), nodeLister )
663
664
klet .podManager = kubepod .NewBasicPodManager ()
664
665
665
- klet .statusManager = status .NewManager (klet .kubeClient , klet .podManager , klet , kubeDeps .PodStartupLatencyTracker , klet .getRootDir ())
666
+ klet .statusManager = status .NewManager (klet .kubeClient , klet .podManager , klet , kubeDeps .PodStartupLatencyTracker )
667
+ klet .allocationManager = allocation .NewManager (klet .getRootDir ())
666
668
667
669
klet .resourceAnalyzer = serverstats .NewResourceAnalyzer (klet , kubeCfg .VolumeStatsAggPeriod .Duration , kubeDeps .Recorder )
668
670
@@ -1147,6 +1149,9 @@ type Kubelet struct {
1147
1149
// consult the pod worker.
1148
1150
statusManager status.Manager
1149
1151
1152
+ // allocationManager manages allocated resources for pods.
1153
+ allocationManager allocation.Manager
1154
+
1150
1155
// resyncInterval is the interval between periodic full reconciliations of
1151
1156
// pods on this node.
1152
1157
resyncInterval time.Duration
@@ -2644,7 +2649,7 @@ func (kl *Kubelet) HandlePodAdditions(pods []*v1.Pod) {
2644
2649
if utilfeature .DefaultFeatureGate .Enabled (features .InPlacePodVerticalScaling ) {
2645
2650
// To handle kubelet restarts, test pod admissibility using AllocatedResources values
2646
2651
// (for cpu & memory) from checkpoint store. If found, that is the source of truth.
2647
- allocatedPod , _ := kl .statusManager .UpdatePodFromAllocation (pod )
2652
+ allocatedPod , _ := kl .allocationManager .UpdatePodFromAllocation (pod )
2648
2653
2649
2654
// Check if we can admit the pod; if not, reject it.
2650
2655
if ok , reason , message := kl .canAdmitPod (allocatedPods , allocatedPod ); ! ok {
@@ -2657,7 +2662,7 @@ func (kl *Kubelet) HandlePodAdditions(pods []*v1.Pod) {
2657
2662
continue
2658
2663
}
2659
2664
// For new pod, checkpoint the resource values at which the Pod has been admitted
2660
- if err := kl .statusManager .SetPodAllocation (allocatedPod ); err != nil {
2665
+ if err := kl .allocationManager .SetPodAllocation (allocatedPod ); err != nil {
2661
2666
//TODO(vinaykul,InPlacePodVerticalScaling): Can we recover from this in some way? Investigate
2662
2667
klog .ErrorS (err , "SetPodAllocation failed" , "pod" , klog .KObj (pod ))
2663
2668
}
@@ -2713,6 +2718,7 @@ func (kl *Kubelet) HandlePodRemoves(pods []*v1.Pod) {
2713
2718
start := kl .clock .Now ()
2714
2719
for _ , pod := range pods {
2715
2720
kl .podManager .RemovePod (pod )
2721
+ kl .allocationManager .DeletePodAllocation (pod .UID )
2716
2722
2717
2723
pod , mirrorPod , wasMirror := kl .podManager .GetPodAndMirrorPod (pod )
2718
2724
if wasMirror {
@@ -2876,7 +2882,7 @@ func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus, string)
2876
2882
// calculations after this function is called. It also updates the cached ResizeStatus according to
2877
2883
// the allocation decision and pod status.
2878
2884
func (kl * Kubelet ) handlePodResourcesResize (pod * v1.Pod , podStatus * kubecontainer.PodStatus ) (* v1.Pod , error ) {
2879
- allocatedPod , updated := kl .statusManager .UpdatePodFromAllocation (pod )
2885
+ allocatedPod , updated := kl .allocationManager .UpdatePodFromAllocation (pod )
2880
2886
if ! updated {
2881
2887
// Desired resources == allocated resources. Check whether a resize is in progress.
2882
2888
resizeInProgress := ! allocatedResourcesMatchStatus (allocatedPod , podStatus )
@@ -2897,7 +2903,7 @@ func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod, podStatus *kubecontaine
2897
2903
fit , resizeStatus , resizeMsg := kl .canResizePod (pod )
2898
2904
if fit {
2899
2905
// Update pod resource allocation checkpoint
2900
- if err := kl .statusManager .SetPodAllocation (pod ); err != nil {
2906
+ if err := kl .allocationManager .SetPodAllocation (pod ); err != nil {
2901
2907
return nil , err
2902
2908
}
2903
2909
for i , container := range pod .Spec .Containers {
0 commit comments