delete stale code in kubelet volumemanager

This commit is contained in:
weizhichen 2022-08-23 23:36:09 +00:00
parent a1128e380c
commit f2e7211ab8
3 changed files with 20 additions and 43 deletions

View File

@ -90,7 +90,6 @@ type podStateProvider interface {
func NewDesiredStateOfWorldPopulator( func NewDesiredStateOfWorldPopulator(
kubeClient clientset.Interface, kubeClient clientset.Interface,
loopSleepDuration time.Duration, loopSleepDuration time.Duration,
getPodStatusRetryDuration time.Duration,
podManager pod.Manager, podManager pod.Manager,
podStateProvider podStateProvider, podStateProvider podStateProvider,
desiredStateOfWorld cache.DesiredStateOfWorld, desiredStateOfWorld cache.DesiredStateOfWorld,
@ -101,13 +100,12 @@ func NewDesiredStateOfWorldPopulator(
intreeToCSITranslator csimigration.InTreeToCSITranslator, intreeToCSITranslator csimigration.InTreeToCSITranslator,
volumePluginMgr *volume.VolumePluginMgr) DesiredStateOfWorldPopulator { volumePluginMgr *volume.VolumePluginMgr) DesiredStateOfWorldPopulator {
return &desiredStateOfWorldPopulator{ return &desiredStateOfWorldPopulator{
kubeClient: kubeClient, kubeClient: kubeClient,
loopSleepDuration: loopSleepDuration, loopSleepDuration: loopSleepDuration,
getPodStatusRetryDuration: getPodStatusRetryDuration, podManager: podManager,
podManager: podManager, podStateProvider: podStateProvider,
podStateProvider: podStateProvider, desiredStateOfWorld: desiredStateOfWorld,
desiredStateOfWorld: desiredStateOfWorld, actualStateOfWorld: actualStateOfWorld,
actualStateOfWorld: actualStateOfWorld,
pods: processedPods{ pods: processedPods{
processedPods: make(map[volumetypes.UniquePodName]bool)}, processedPods: make(map[volumetypes.UniquePodName]bool)},
kubeContainerRuntime: kubeContainerRuntime, kubeContainerRuntime: kubeContainerRuntime,
@ -121,22 +119,20 @@ func NewDesiredStateOfWorldPopulator(
} }
type desiredStateOfWorldPopulator struct { type desiredStateOfWorldPopulator struct {
kubeClient clientset.Interface kubeClient clientset.Interface
loopSleepDuration time.Duration loopSleepDuration time.Duration
getPodStatusRetryDuration time.Duration podManager pod.Manager
podManager pod.Manager podStateProvider podStateProvider
podStateProvider podStateProvider desiredStateOfWorld cache.DesiredStateOfWorld
desiredStateOfWorld cache.DesiredStateOfWorld actualStateOfWorld cache.ActualStateOfWorld
actualStateOfWorld cache.ActualStateOfWorld pods processedPods
pods processedPods kubeContainerRuntime kubecontainer.Runtime
kubeContainerRuntime kubecontainer.Runtime keepTerminatedPodVolumes bool
timeOfLastGetPodStatus time.Time hasAddedPods bool
keepTerminatedPodVolumes bool hasAddedPodsLock sync.RWMutex
hasAddedPods bool csiMigratedPluginManager csimigration.PluginManager
hasAddedPodsLock sync.RWMutex intreeToCSITranslator csimigration.InTreeToCSITranslator
csiMigratedPluginManager csimigration.PluginManager volumePluginMgr *volume.VolumePluginMgr
intreeToCSITranslator csimigration.InTreeToCSITranslator
volumePluginMgr *volume.VolumePluginMgr
} }
type processedPods struct { type processedPods struct {
@ -171,17 +167,6 @@ func (dswp *desiredStateOfWorldPopulator) HasAddedPods() bool {
func (dswp *desiredStateOfWorldPopulator) populatorLoop() { func (dswp *desiredStateOfWorldPopulator) populatorLoop() {
dswp.findAndAddNewPods() dswp.findAndAddNewPods()
// findAndRemoveDeletedPods() calls out to the container runtime to
// determine if the containers for a given pod are terminated. This is
// an expensive operation, therefore we limit the rate that
// findAndRemoveDeletedPods() is called independently of the main
// populator loop.
if time.Since(dswp.timeOfLastGetPodStatus) < dswp.getPodStatusRetryDuration {
klog.V(5).InfoS("Skipping findAndRemoveDeletedPods(). ", "nextRetryTime", dswp.timeOfLastGetPodStatus.Add(dswp.getPodStatusRetryDuration), "retryDuration", dswp.getPodStatusRetryDuration)
return
}
dswp.findAndRemoveDeletedPods() dswp.findAndRemoveDeletedPods()
} }

View File

@ -1509,7 +1509,6 @@ func createDswpWithVolumeWithCustomPluginMgr(t *testing.T, pv *v1.PersistentVolu
dswp := &desiredStateOfWorldPopulator{ dswp := &desiredStateOfWorldPopulator{
kubeClient: fakeClient, kubeClient: fakeClient,
loopSleepDuration: 100 * time.Millisecond, loopSleepDuration: 100 * time.Millisecond,
getPodStatusRetryDuration: 2 * time.Second,
podManager: fakePodManager, podManager: fakePodManager,
podStateProvider: fakeStateProvider, podStateProvider: fakeStateProvider,
desiredStateOfWorld: fakesDSW, desiredStateOfWorld: fakesDSW,

View File

@ -61,12 +61,6 @@ const (
// DesiredStateOfWorldPopulator loop waits between successive executions // DesiredStateOfWorldPopulator loop waits between successive executions
desiredStateOfWorldPopulatorLoopSleepPeriod = 100 * time.Millisecond desiredStateOfWorldPopulatorLoopSleepPeriod = 100 * time.Millisecond
// desiredStateOfWorldPopulatorGetPodStatusRetryDuration is the amount of
// time the DesiredStateOfWorldPopulator loop waits between successive pod
// cleanup calls (to prevent calling containerruntime.GetPodStatus too
// frequently).
desiredStateOfWorldPopulatorGetPodStatusRetryDuration = 2 * time.Second
// podAttachAndMountTimeout is the maximum amount of time the // podAttachAndMountTimeout is the maximum amount of time the
// WaitForAttachAndMount call will wait for all volumes in the specified pod // WaitForAttachAndMount call will wait for all volumes in the specified pod
// to be attached and mounted. Even though cloud operations can take several // to be attached and mounted. Even though cloud operations can take several
@ -207,7 +201,6 @@ func NewVolumeManager(
vm.desiredStateOfWorldPopulator = populator.NewDesiredStateOfWorldPopulator( vm.desiredStateOfWorldPopulator = populator.NewDesiredStateOfWorldPopulator(
kubeClient, kubeClient,
desiredStateOfWorldPopulatorLoopSleepPeriod, desiredStateOfWorldPopulatorLoopSleepPeriod,
desiredStateOfWorldPopulatorGetPodStatusRetryDuration,
podManager, podManager,
podStateProvider, podStateProvider,
vm.desiredStateOfWorld, vm.desiredStateOfWorld,