Skip to content

Commit

Permalink
add check clean task interval
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 committed Nov 6, 2023
1 parent 466d1d6 commit ff71bf1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
17 changes: 13 additions & 4 deletions pkg/controller/chaosblade/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
23 changes: 14 additions & 9 deletions pkg/runtime/chaosblade/chaosblade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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",
Expand All @@ -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")
}
Expand Down

0 comments on commit ff71bf1

Please sign in to comment.