From ff71bf1e430cceff40e91d981c987090962459a9 Mon Sep 17 00:00:00 2001 From: binbin0325 Date: Mon, 6 Nov 2023 20:19:36 +0800 Subject: [PATCH] add check clean task interval --- pkg/controller/chaosblade/controller.go | 17 +++++++++++++---- pkg/runtime/chaosblade/chaosblade.go | 23 ++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pkg/controller/chaosblade/controller.go b/pkg/controller/chaosblade/controller.go index 084e8ea..8a08109 100644 --- a/pkg/controller/chaosblade/controller.go +++ b/pkg/controller/chaosblade/controller.go @@ -116,19 +116,28 @@ func startPeriodicallyCleanUpBlade(mgr manager.Manager) { cli := mgr.GetClient() duration, err := time.ParseDuration(chaosblade.RemoveBladeInterval) if err != nil { - logrus.Errorf("parse interval error: %v, use default interval: %s", err, chaosblade.DefaultRemoveBladeInterval) + logrus.Errorf("parse remove blade interval error: %v, use default interval: %s", err, chaosblade.DefaultRemoveBladeInterval) duration, err = time.ParseDuration(chaosblade.DefaultRemoveBladeInterval) chaosblade.RemoveBladeInterval = chaosblade.DefaultRemoveBladeInterval if err != nil { - logrus.Fatalf("start periodically clean up blade, ticker error: %v", err) + logrus.Fatalf("parse remove blade interval error: %v", err) } } // first clean up periodicallyCleanUpBlade(cli, duration) + checkDuration, err := time.ParseDuration(chaosblade.CheckCleanTaskInterval) + if err != nil { + logrus.Errorf("parse clean task interval error: %v, use default interval: %s", err, chaosblade.DefaultCheckCleanTaskInterval) + checkDuration, err = time.ParseDuration(chaosblade.DefaultCheckCleanTaskInterval) + chaosblade.CheckCleanTaskInterval = chaosblade.DefaultCheckCleanTaskInterval + if err != nil { + logrus.Fatalf("start periodically clean up blade, ticker error: %v", err) + } + } // ticker clean up - ticker := time.NewTicker(time.Second * time.Duration(duration.Seconds())) - logrus.Infof("start periodically clean up blade ticker, interval: %s", chaosblade.RemoveBladeInterval) + ticker := time.NewTicker(checkDuration) + logrus.Infof("start periodically clean up blade ticker,check interval: %s,retention interval:%s", chaosblade.CheckCleanTaskInterval, chaosblade.RemoveBladeInterval) for range ticker.C { periodicallyCleanUpBlade(cli, duration) } diff --git a/pkg/runtime/chaosblade/chaosblade.go b/pkg/runtime/chaosblade/chaosblade.go index 6ff33d8..4ea2e72 100644 --- a/pkg/runtime/chaosblade/chaosblade.go +++ b/pkg/runtime/chaosblade/chaosblade.go @@ -23,12 +23,13 @@ import ( ) var ( - ImageRepository string - Version string - PullPolicy string - DaemonsetEnable bool - RemoveBladeInterval string - DownloadUrl string + ImageRepository string + Version string + PullPolicy string + DaemonsetEnable bool + RemoveBladeInterval string + CheckCleanTaskInterval string + DownloadUrl string ) const ( @@ -39,8 +40,11 @@ const ( OperatorChaosBladeBlade = "/opt/chaosblade/blade" ) -const DaemonsetPodName = "chaosblade-tool" -const DefaultRemoveBladeInterval = "72h" +const ( + DaemonsetPodName = "chaosblade-tool" + DefaultRemoveBladeInterval = "72h" + DefaultCheckCleanTaskInterval = "3s" +) var DaemonsetPodLabels = map[string]string{ "app": "chaosblade-tool", @@ -67,7 +71,8 @@ func init() { f.StringVar(&ImageRepository, "chaosblade-image-repository", "chaosbladeio/chaosblade-tool", "Image repository of chaosblade tool") f.StringVar(&PullPolicy, "chaosblade-image-pull-policy", "IfNotPresent", "Pulling policy of chaosblade image, default value is IfNotPresent.") f.BoolVar(&DaemonsetEnable, "daemonset-enable", false, "Deploy chaosblade daemonset to resolve chaos experiment environment of network, default value is false.") - f.StringVar(&RemoveBladeInterval, "remove-blade-interval", DefaultRemoveBladeInterval, "Periodically clean up blade state is destroying, default value is 24h.") + f.StringVar(&RemoveBladeInterval, "remove-blade-interval", DefaultRemoveBladeInterval, "Periodically clean up blade state is destroying, default value is 72h.") + f.StringVar(&RemoveBladeInterval, "clean-task-interval", DefaultCheckCleanTaskInterval, "Periodically check clean up blade task, default value is 3s.") f.StringVar(&DownloadUrl, "chaosblade-download-url", "", "The chaosblade downloaded address which works when the chaosblade is deployed in download mode.") f.StringVar(&DaemonsetPodNamespace, "chaosblade-namespace", "chaosblade", "The chaosblade deployment namespace") }