@@ -666,14 +666,13 @@ func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containe
666
666
return true
667
667
}
668
668
669
- func (m * kubeGenericRuntimeManager ) doPodResizeAction (ctx context.Context , pod * v1.Pod , podStatus * kubecontainer.PodStatus , podContainerChanges podActions ) (result kubecontainer.PodSyncResult ) {
670
- updatePodResult := kubecontainer .NewSyncResult (kubecontainer .UpdatePodSandbox , pod .UID )
671
- result .AddSyncResult (updatePodResult )
669
+ func (m * kubeGenericRuntimeManager ) doPodResizeAction (pod * v1.Pod , podStatus * kubecontainer.PodStatus , podContainerChanges podActions , result kubecontainer.PodSyncResult ) {
672
670
pcm := m .containerManager .NewPodContainerManager ()
673
671
//TODO(vinaykul,InPlacePodVerticalScaling): Figure out best way to get enforceMemoryQoS value (parameter #4 below) in platform-agnostic way
674
672
podResources := cm .ResourceConfigForPod (pod , m .cpuCFSQuota , uint64 ((m .cpuCFSQuotaPeriod .Duration )/ time .Microsecond ), false )
675
673
if podResources == nil {
676
- result .Fail (fmt .Errorf ("unable to get resource configuration processing resize for pod %s" , format .Pod (pod )))
674
+ klog .ErrorS (nil , "Unable to get resource configuration" , "pod" , pod .Name )
675
+ result .Fail (fmt .Errorf ("unable to get resource configuration processing resize for pod %s" , pod .Name ))
677
676
return
678
677
}
679
678
setPodCgroupConfig := func (rName v1.ResourceName , setLimitValue bool ) error {
@@ -691,7 +690,10 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(ctx context.Context, pod *
691
690
case v1 .ResourceMemory :
692
691
err = pcm .SetPodCgroupConfig (pod , podResources )
693
692
}
694
- return fmt .Errorf ("failed to set cgroup config for %s of pod %s: %w" , rName , format .Pod (pod ), err )
693
+ if err != nil {
694
+ klog .ErrorS (err , "Failed to set cgroup config" , "resource" , rName , "pod" , pod .Name )
695
+ }
696
+ return err
695
697
}
696
698
// Memory and CPU are updated separately because memory resizes may be ordered differently than CPU resizes.
697
699
// If resize results in net pod resource increase, set pod cgroup config before resizing containers.
@@ -711,12 +713,9 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(ctx context.Context, pod *
711
713
}
712
714
}
713
715
if len (podContainerChanges .ContainersToUpdate [rName ]) > 0 {
714
- updateContainerResults , errUpdate := m .updatePodContainerResources (ctx , pod , rName , podContainerChanges .ContainersToUpdate [rName ])
715
- for _ , containerResult := range updateContainerResults {
716
- result .AddSyncResult (containerResult )
717
- }
718
- if errUpdate != nil {
719
- return errUpdate
716
+ if err = m .updatePodContainerResources (pod , rName , podContainerChanges .ContainersToUpdate [rName ]); err != nil {
717
+ klog .ErrorS (err , "updatePodContainerResources failed" , "pod" , format .Pod (pod ), "resource" , rName )
718
+ return err
720
719
}
721
720
}
722
721
// At downsizing, requests should shrink prior to limits in order to keep "requests <= limits".
@@ -734,21 +733,25 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(ctx context.Context, pod *
734
733
}
735
734
if len (podContainerChanges .ContainersToUpdate [v1 .ResourceMemory ]) > 0 || podContainerChanges .UpdatePodResources {
736
735
if podResources .Memory == nil {
737
- result .Fail (fmt .Errorf ("podResources.Memory is nil for pod %s" , format .Pod (pod )))
736
+ klog .ErrorS (nil , "podResources.Memory is nil" , "pod" , pod .Name )
737
+ result .Fail (fmt .Errorf ("podResources.Memory is nil for pod %s" , pod .Name ))
738
738
return
739
739
}
740
740
currentPodMemoryConfig , err := pcm .GetPodCgroupConfig (pod , v1 .ResourceMemory )
741
741
if err != nil {
742
- result .Fail (fmt .Errorf ("GetPodCgroupConfig for memory failed for pod %s: %w" , format .Pod (pod ), err ))
742
+ klog .ErrorS (err , "GetPodCgroupConfig for memory failed" , "pod" , pod .Name )
743
+ result .Fail (err )
743
744
return
744
745
}
745
746
currentPodMemoryUsage , err := pcm .GetPodCgroupMemoryUsage (pod )
746
747
if err != nil {
747
- result .Fail (fmt .Errorf ("GetPodCgroupMemoryUsage failed for pod %s" , format .Pod (pod )))
748
+ klog .ErrorS (err , "GetPodCgroupMemoryUsage failed" , "pod" , pod .Name )
749
+ result .Fail (err )
748
750
return
749
751
}
750
752
if currentPodMemoryUsage >= uint64 (* podResources .Memory ) {
751
- result .Fail (fmt .Errorf ("aborting attempt to set pod memory limit less than current memory usage for pod %s" , format .Pod (pod )))
753
+ klog .ErrorS (nil , "Aborting attempt to set pod memory limit less than current memory usage" , "pod" , pod .Name )
754
+ result .Fail (fmt .Errorf ("aborting attempt to set pod memory limit less than current memory usage for pod %s" , pod .Name ))
752
755
return
753
756
}
754
757
if errResize := resizeContainers (v1 .ResourceMemory , int64 (* currentPodMemoryConfig .Memory ), * podResources .Memory , 0 , 0 ); errResize != nil {
@@ -758,12 +761,14 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(ctx context.Context, pod *
758
761
}
759
762
if len (podContainerChanges .ContainersToUpdate [v1 .ResourceCPU ]) > 0 || podContainerChanges .UpdatePodResources {
760
763
if podResources .CPUQuota == nil || podResources .CPUShares == nil {
761
- result .Fail (fmt .Errorf ("podResources.CPUQuota or podResources.CPUShares is nil for pod %s" , format .Pod (pod )))
764
+ klog .ErrorS (nil , "podResources.CPUQuota or podResources.CPUShares is nil" , "pod" , pod .Name )
765
+ result .Fail (fmt .Errorf ("podResources.CPUQuota or podResources.CPUShares is nil for pod %s" , pod .Name ))
762
766
return
763
767
}
764
768
currentPodCpuConfig , err := pcm .GetPodCgroupConfig (pod , v1 .ResourceCPU )
765
769
if err != nil {
766
- result .Fail (fmt .Errorf ("GetPodCgroupConfig for CPU failed for pod %s" , format .Pod (pod )))
770
+ klog .ErrorS (err , "GetPodCgroupConfig for CPU failed" , "pod" , pod .Name )
771
+ result .Fail (err )
767
772
return
768
773
}
769
774
if errResize := resizeContainers (v1 .ResourceCPU , * currentPodCpuConfig .CPUQuota , * podResources .CPUQuota ,
@@ -772,20 +777,17 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(ctx context.Context, pod *
772
777
return
773
778
}
774
779
}
775
- return
776
780
}
777
781
778
- func (m * kubeGenericRuntimeManager ) updatePodContainerResources (ctx context. Context , pod * v1.Pod , resourceName v1.ResourceName , containersToUpdate []containerToUpdateInfo ) ( updateResults [] * kubecontainer. SyncResult , err error ) {
782
+ func (m * kubeGenericRuntimeManager ) updatePodContainerResources (pod * v1.Pod , resourceName v1.ResourceName , containersToUpdate []containerToUpdateInfo ) error {
779
783
klog .V (5 ).InfoS ("Updating container resources" , "pod" , klog .KObj (pod ))
780
784
781
785
for _ , cInfo := range containersToUpdate {
782
- var updateContainerResult * kubecontainer.SyncResult
783
786
container := pod .Spec .Containers [cInfo .apiContainerIdx ].DeepCopy ()
784
787
// If updating memory limit, use most recently configured CPU request and limit values.
785
788
// If updating CPU request and limit, use most recently configured memory request and limit values.
786
789
switch resourceName {
787
790
case v1 .ResourceMemory :
788
- updateContainerResult = kubecontainer .NewSyncResult (kubecontainer .UpdateContainerMemory , container .Name )
789
791
container .Resources .Limits = v1.ResourceList {
790
792
v1 .ResourceCPU : * resource .NewMilliQuantity (cInfo .currentContainerResources .cpuLimit , resource .DecimalSI ),
791
793
v1 .ResourceMemory : * resource .NewQuantity (cInfo .desiredContainerResources .memoryLimit , resource .BinarySI ),
@@ -795,7 +797,6 @@ func (m *kubeGenericRuntimeManager) updatePodContainerResources(ctx context.Cont
795
797
v1 .ResourceMemory : * resource .NewQuantity (cInfo .desiredContainerResources .memoryRequest , resource .BinarySI ),
796
798
}
797
799
case v1 .ResourceCPU :
798
- updateContainerResult = kubecontainer .NewSyncResult (kubecontainer .UpdateContainerCPU , container .Name )
799
800
container .Resources .Limits = v1.ResourceList {
800
801
v1 .ResourceCPU : * resource .NewMilliQuantity (cInfo .desiredContainerResources .cpuLimit , resource .DecimalSI ),
801
802
v1 .ResourceMemory : * resource .NewQuantity (cInfo .currentContainerResources .memoryLimit , resource .BinarySI ),
@@ -805,19 +806,12 @@ func (m *kubeGenericRuntimeManager) updatePodContainerResources(ctx context.Cont
805
806
v1 .ResourceMemory : * resource .NewQuantity (cInfo .currentContainerResources .memoryRequest , resource .BinarySI ),
806
807
}
807
808
}
808
- updateResults = append (updateResults , updateContainerResult )
809
- if err = m .updateContainerResources (ctx , pod , container , cInfo .kubeContainerID ); err != nil {
809
+ if err := m .updateContainerResources (pod , container , cInfo .kubeContainerID ); err != nil {
810
810
// Log error and abort as container updates need to succeed in the order determined by computePodResizeAction.
811
811
// The recovery path is for SyncPod to keep retrying at later times until it succeeds.
812
812
klog .ErrorS (err , "updateContainerResources failed" , "container" , container .Name , "cID" , cInfo .kubeContainerID ,
813
813
"pod" , format .Pod (pod ), "resourceName" , resourceName )
814
- switch resourceName {
815
- case v1 .ResourceMemory :
816
- updateContainerResult .Fail (kubecontainer .ErrUpdateContainerMemory , err .Error ())
817
- case v1 .ResourceCPU :
818
- updateContainerResult .Fail (kubecontainer .ErrUpdateContainerCPU , err .Error ())
819
- }
820
- return
814
+ return err
821
815
}
822
816
resizeKey := fmt .Sprintf ("%s:resize:%s" , container .Name , resourceName )
823
817
@@ -857,7 +851,7 @@ func (m *kubeGenericRuntimeManager) updatePodContainerResources(ctx context.Cont
857
851
cInfo .currentContainerResources .cpuRequest = cInfo .desiredContainerResources .cpuRequest
858
852
}
859
853
}
860
- return
854
+ return nil
861
855
}
862
856
863
857
// computePodActions checks whether the pod spec has changed and returns the changes if true.
@@ -1357,11 +1351,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(ctx context.Context, pod *v1.Pod, po
1357
1351
// Step 7: For containers in podContainerChanges.ContainersToUpdate[CPU,Memory] list, invoke UpdateContainerResources
1358
1352
if IsInPlacePodVerticalScalingAllowed (pod ) {
1359
1353
if len (podContainerChanges .ContainersToUpdate ) > 0 || podContainerChanges .UpdatePodResources {
1360
- resizeResult := m .doPodResizeAction (ctx , pod , podStatus , podContainerChanges )
1361
- result .AddPodSyncResult (resizeResult )
1362
- if resizeResult .Error () != nil {
1363
- klog .ErrorS (resizeResult .Error (), "doPodResizeAction failed" )
1364
- }
1354
+ m .doPodResizeAction (pod , podStatus , podContainerChanges , result )
1365
1355
}
1366
1356
}
1367
1357
0 commit comments