From 8ac5c6e3625ac9df08c086e83bf06e675f50ba87 Mon Sep 17 00:00:00 2001 From: Valeriy Khorunzhin Date: Wed, 30 Oct 2024 16:01:49 +0300 Subject: [PATCH] test(api): add force interrupting flag to perfomance test tool (#484) Added forceInterruption param to config for perfomance test tool Shatal. Signed-off-by: Valeriy Khorunzhin Co-authored-by: Nikita Korolev <141920865+universal-itengineer@users.noreply.github.com> --------- Signed-off-by: Valeriy Khorunzhin Co-authored-by: Nikita Korolev <141920865+universal-itengineer@users.noreply.github.com> --- tests/performance/shatal/README.md | 4 ++++ tests/performance/shatal/config.yaml | 1 + .../shatal/internal/config/config.go | 23 ++++++++++--------- .../shatal/internal/shatal/shatal.go | 18 +++++++++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/performance/shatal/README.md b/tests/performance/shatal/README.md index 5552a7c75..021c0ca30 100644 --- a/tests/performance/shatal/README.md +++ b/tests/performance/shatal/README.md @@ -36,6 +36,10 @@ count: 100 # The flag to show debug level logs. # Corresponds to the DEBUG environment variable. debug: true +# Flag to enable forced interrupt mode +# If `true` - shatal stops immediately, all affected resources remain in the state at the moment of shatal interruption. +# If `false` - after shatal interruption all affected resources return to their initial state. +forceInterruption: false drainer: # The flag to enable node draining. # Corresponds to the DRAINER_ENABLED environment variable. diff --git a/tests/performance/shatal/config.yaml b/tests/performance/shatal/config.yaml index 1bd835355..48b07359c 100644 --- a/tests/performance/shatal/config.yaml +++ b/tests/performance/shatal/config.yaml @@ -4,6 +4,7 @@ namespace: "default" interval: "5s" count: 100 debug: true +forceInterruption: false drainer: enabled: true interval: "10s" diff --git a/tests/performance/shatal/internal/config/config.go b/tests/performance/shatal/internal/config/config.go index 6c0997364..e328dd1e9 100644 --- a/tests/performance/shatal/internal/config/config.go +++ b/tests/performance/shatal/internal/config/config.go @@ -23,17 +23,18 @@ import ( ) type Config struct { - Kubeconfig string `yaml:"kubeconfigBase64" env:"KUBECONFIG_BASE64" env-required:""` - ResourcesPrefix string `yaml:"resourcesPrefix" env:"RESOURCES_PREFIX" env-default:"performance"` - Namespace string `yaml:"namespace" env:"NAMESPACE" env-default:"default"` - Interval time.Duration `yaml:"interval" env:"INTERVAL" env-default:"5s"` - Count int `yaml:"count" env:"COUNT"` - Debug bool `yaml:"debug" env:"DEBUG" env-default:"false"` - Drainer DrainerFeature `yaml:"drainer"` - Creator CreatorFeature `yaml:"creator"` - Deleter DeleterFeature `yaml:"deleter"` - Modifier ModifierFeature `yaml:"modifier"` - Nothing NothingFeature `yaml:"nothing"` + Kubeconfig string `yaml:"kubeconfigBase64" env:"KUBECONFIG_BASE64" env-required:""` + ResourcesPrefix string `yaml:"resourcesPrefix" env:"RESOURCES_PREFIX" env-default:"performance"` + Namespace string `yaml:"namespace" env:"NAMESPACE" env-default:"default"` + Interval time.Duration `yaml:"interval" env:"INTERVAL" env-default:"5s"` + Count int `yaml:"count" env:"COUNT"` + Debug bool `yaml:"debug" env:"DEBUG" env-default:"false"` + Drainer DrainerFeature `yaml:"drainer"` + Creator CreatorFeature `yaml:"creator"` + Deleter DeleterFeature `yaml:"deleter"` + Modifier ModifierFeature `yaml:"modifier"` + Nothing NothingFeature `yaml:"nothing"` + ForceInterruption bool `yaml:"forceInterruption"` } type DrainerFeature struct { diff --git a/tests/performance/shatal/internal/shatal/shatal.go b/tests/performance/shatal/internal/shatal/shatal.go index a4ee04ec4..73a08db2e 100644 --- a/tests/performance/shatal/internal/shatal/shatal.go +++ b/tests/performance/shatal/internal/shatal/shatal.go @@ -19,7 +19,9 @@ package shatal import ( "context" "errors" + "fmt" "log/slog" + "os" "sync" "github.com/deckhouse/virtualization/shatal/internal/api" @@ -38,13 +40,16 @@ type Shatal struct { logger *slog.Logger exit chan struct{} wg sync.WaitGroup + + forceInterruption bool } func New(api *api.Client, conf config.Config, log *slog.Logger) (*Shatal, error) { shatal := Shatal{ - api: api, - logger: log, - exit: make(chan struct{}), + api: api, + logger: log, + exit: make(chan struct{}), + forceInterruption: conf.ForceInterruption, } nodes, err := api.GetNodes(context.Background(), conf.Drainer.LabelSelector) @@ -131,7 +136,12 @@ func (s *Shatal) Run() { select { case <-s.exit: s.logger.Info("Stop runners") - cancel() + if s.forceInterruption { + fmt.Println("Performing force interruption") + os.Exit(1) + } else { + cancel() + } case <-ctx.Done(): } }()