@@ -693,7 +693,8 @@ func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containe
693
693
return true
694
694
}
695
695
696
- func (m * kubeGenericRuntimeManager ) doPodResizeAction (pod * v1.Pod , podContainerChanges podActions , result * kubecontainer.PodSyncResult ) {
696
+ func (m * kubeGenericRuntimeManager ) doPodResizeAction (pod * v1.Pod , podContainerChanges podActions ) * kubecontainer.SyncResult {
697
+ resizeResult := kubecontainer .NewSyncResult (kubecontainer .ResizePodInPlace , format .Pod (pod ))
697
698
pcm := m .containerManager .NewPodContainerManager ()
698
699
//TODO(vinaykul,InPlacePodVerticalScaling): Figure out best way to get enforceMemoryQoS value (parameter #4 below) in platform-agnostic way
699
700
enforceCPULimits := m .cpuCFSQuota
@@ -704,20 +705,20 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podContainerC
704
705
podResources := cm .ResourceConfigForPod (pod , enforceCPULimits , uint64 ((m .cpuCFSQuotaPeriod .Duration )/ time .Microsecond ), false )
705
706
if podResources == nil {
706
707
klog .ErrorS (nil , "Unable to get resource configuration" , "pod" , klog .KObj (pod ))
707
- result .Fail (fmt .Errorf ("unable to get resource configuration processing resize for pod %s" , pod .Name ))
708
- return
708
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , fmt .Sprintf ("unable to get resource configuration processing resize for pod %s" , pod .Name ))
709
+ return resizeResult
709
710
}
710
711
currentPodMemoryConfig , err := pcm .GetPodCgroupConfig (pod , v1 .ResourceMemory )
711
712
if err != nil {
712
713
klog .ErrorS (nil , "Unable to get pod cgroup memory config" , "pod" , klog .KObj (pod ))
713
- result .Fail (fmt .Errorf ("unable to get pod cgroup memory config for pod %s" , pod .Name ))
714
- return
714
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , fmt .Sprintf ("unable to get pod cgroup memory config for pod %s" , pod .Name ))
715
+ return resizeResult
715
716
}
716
717
currentPodCPUConfig , err := pcm .GetPodCgroupConfig (pod , v1 .ResourceCPU )
717
718
if err != nil {
718
719
klog .ErrorS (nil , "Unable to get pod cgroup cpu config" , "pod" , klog .KObj (pod ))
719
- result .Fail (fmt .Errorf ("unable to get pod cgroup cpu config for pod %s" , pod .Name ))
720
- return
720
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , fmt .Sprintf ("unable to get pod cgroup cpu config for pod %s" , pod .Name ))
721
+ return resizeResult
721
722
}
722
723
723
724
currentPodResources := podResources
@@ -800,30 +801,30 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podContainerC
800
801
currentPodMemoryUsage , err := pcm .GetPodCgroupMemoryUsage (pod )
801
802
if err != nil {
802
803
klog .ErrorS (err , "GetPodCgroupMemoryUsage failed" , "pod" , pod .Name )
803
- result .Fail (err )
804
- return
804
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , err . Error () )
805
+ return resizeResult
805
806
}
806
807
if currentPodMemoryUsage >= uint64 (* podResources .Memory ) {
807
808
klog .ErrorS (nil , "Aborting attempt to set pod memory limit less than current memory usage" , "pod" , pod .Name )
808
- result .Fail (fmt .Errorf ("aborting attempt to set pod memory limit less than current memory usage for pod %s" , pod .Name ))
809
- return
809
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , fmt .Sprintf ("aborting attempt to set pod memory limit less than current memory usage for pod %s" , pod .Name ))
810
+ return resizeResult
810
811
}
811
812
} else {
812
813
// Default pod memory limit to the current memory limit if unset to prevent it from updating.
813
814
// TODO(#128675): This does not support removing limits.
814
815
podResources .Memory = currentPodMemoryConfig .Memory
815
816
}
816
817
if errResize := resizeContainers (v1 .ResourceMemory , int64 (* currentPodMemoryConfig .Memory ), * podResources .Memory , 0 , 0 ); errResize != nil {
817
- result .Fail (errResize )
818
- return
818
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , errResize . Error () )
819
+ return resizeResult
819
820
}
820
821
}
821
822
if len (podContainerChanges .ContainersToUpdate [v1 .ResourceCPU ]) > 0 || podContainerChanges .UpdatePodResources {
822
823
if podResources .CPUShares == nil {
823
824
// This shouldn't happen: ResourceConfigForPod always returns a non-nil value for CPUShares.
824
825
klog .ErrorS (nil , "podResources.CPUShares is nil" , "pod" , pod .Name )
825
- result .Fail (fmt .Errorf ("podResources.CPUShares is nil for pod %s" , pod .Name ))
826
- return
826
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , fmt .Sprintf ("podResources.CPUShares is nil for pod %s" , pod .Name ))
827
+ return resizeResult
827
828
}
828
829
829
830
// Default pod CPUQuota to the current CPUQuota if no limit is set to prevent the pod limit
@@ -834,10 +835,11 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podContainerC
834
835
}
835
836
if errResize := resizeContainers (v1 .ResourceCPU , * currentPodCPUConfig .CPUQuota , * podResources .CPUQuota ,
836
837
int64 (* currentPodCPUConfig .CPUShares ), int64 (* podResources .CPUShares )); errResize != nil {
837
- result .Fail (errResize )
838
- return
838
+ resizeResult .Fail (kubecontainer . ErrResizePodInPlace , errResize . Error () )
839
+ return resizeResult
839
840
}
840
841
}
842
+ return resizeResult
841
843
}
842
844
843
845
func (m * kubeGenericRuntimeManager ) updatePodContainerResources (pod * v1.Pod , resourceName v1.ResourceName , containersToUpdate []containerToUpdateInfo ) error {
@@ -1401,7 +1403,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(ctx context.Context, pod *v1.Pod, po
1401
1403
// Step 7: For containers in podContainerChanges.ContainersToUpdate[CPU,Memory] list, invoke UpdateContainerResources
1402
1404
if resizable , _ := IsInPlacePodVerticalScalingAllowed (pod ); resizable {
1403
1405
if len (podContainerChanges .ContainersToUpdate ) > 0 || podContainerChanges .UpdatePodResources {
1404
- m .doPodResizeAction (pod , podContainerChanges , & result )
1406
+ result . SyncResults = append ( result . SyncResults , m .doPodResizeAction (pod , podContainerChanges ) )
1405
1407
}
1406
1408
}
1407
1409
0 commit comments