From 039b695e29ecd49e5245ac7db4ee7ea8ae43391e Mon Sep 17 00:00:00 2001 From: jiaxuanzhou Date: Tue, 20 Feb 2018 14:02:03 +0800 Subject: [PATCH] Disable image GC when high threshold is set to 100 --- cmd/kubelet/app/options/options.go | 4 ++-- pkg/kubelet/images/image_gc_manager.go | 5 ----- pkg/kubelet/kubelet.go | 10 +++++++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index 02a82b87ab1..238208c30d0 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -486,8 +486,8 @@ func AddKubeletConfigFlags(fs *pflag.FlagSet, c *kubeletconfig.KubeletConfigurat fs.DurationVar(&c.StreamingConnectionIdleTimeout.Duration, "streaming-connection-idle-timeout", c.StreamingConnectionIdleTimeout.Duration, "Maximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: '5m'") fs.DurationVar(&c.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", c.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller.") fs.DurationVar(&c.ImageMinimumGCAge.Duration, "minimum-image-ttl-duration", c.ImageMinimumGCAge.Duration, "Minimum age for an unused image before it is garbage collected. Examples: '300ms', '10s' or '2h45m'.") - fs.Int32Var(&c.ImageGCHighThresholdPercent, "image-gc-high-threshold", c.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run.Values must be winthin the range [0, 100], To disable image garbage collection, set to 0. ") - fs.Int32Var(&c.ImageGCLowThresholdPercent, "image-gc-low-threshold", c.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to.Values must be winthin the range [0, 100] and should not be larger than that of --image-gc-high-threshold.") + fs.Int32Var(&c.ImageGCHighThresholdPercent, "image-gc-high-threshold", c.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Values must be winthin the range [0, 100], To disable image garbage collection, set to 100. ") + fs.Int32Var(&c.ImageGCLowThresholdPercent, "image-gc-low-threshold", c.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Values must be winthin the range [0, 100] and should not be larger than that of --image-gc-high-threshold.") fs.DurationVar(&c.VolumeStatsAggPeriod.Duration, "volume-stats-agg-period", c.VolumeStatsAggPeriod.Duration, "Specifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0.") fs.Var(flag.NewMapStringBool(&c.FeatureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+ "Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n")) diff --git a/pkg/kubelet/images/image_gc_manager.go b/pkg/kubelet/images/image_gc_manager.go index 8de7afb5e99..15b8780bd86 100644 --- a/pkg/kubelet/images/image_gc_manager.go +++ b/pkg/kubelet/images/image_gc_manager.go @@ -290,11 +290,6 @@ func (im *realImageGCManager) GarbageCollect() error { // If over the max threshold, free enough to place us at the lower threshold. usagePercent := 100 - int(available*100/capacity) - if im.policy.HighThresholdPercent == 0 { - glog.Warningf("Disk usage percent is %d, the high threshold is 0, will not image GC on device %q at mount point %q", usagePercent, fsInfo.Device, fsInfo.Mountpoint) - return nil - } - if usagePercent >= im.policy.HighThresholdPercent { amountToFree := capacity*int64(100-im.policy.LowThresholdPercent)/100 - available glog.Infof("[imageGCManager]: Disk usage on image filesystem is at %d%% which is over the high threshold (%d%%). Trying to free %d bytes", usagePercent, im.policy.HighThresholdPercent, amountToFree) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 51a6964b75d..e7ab4174775 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1245,6 +1245,14 @@ func (kl *Kubelet) StartGarbageCollection() { } }, ContainerGCPeriod, wait.NeverStop) + stopChan := make(chan struct{}) + defer close(stopChan) + // when the high threshold is set to 100, stub the image GC manager + if kl.kubeletConfiguration.ImageGCHighThresholdPercent == 100 { + glog.V(2).Infof("ImageGCHighThresholdPercent is set 100, Disable image GC") + go func() { stopChan <- struct{}{} }() + } + prevImageGCFailed := false go wait.Until(func() { if err := kl.imageManager.GarbageCollect(); err != nil { @@ -1265,7 +1273,7 @@ func (kl *Kubelet) StartGarbageCollection() { glog.V(vLevel).Infof("Image garbage collection succeeded") } - }, ImageGCPeriod, wait.NeverStop) + }, ImageGCPeriod, stopChan) } // initializeModules will initialize internal modules that do not require the container runtime to be up.