From 11036536f0c3097e78e10c417d13a554c737cf3b Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Fri, 13 Dec 2024 09:51:06 +0100 Subject: [PATCH] removed debug hardcoded flag Signed-off-by: Tullio Sebastiani --- cmd/graph.go | 4 +--- cmd/run.go | 11 +++-------- pkg/config/config.go | 1 - pkg/config/config.json | 1 - pkg/scenario_orchestrator/common_functions.go | 8 ++++---- .../docker/scenario_orchestrator.go | 13 +++++-------- .../podman/scenario_orchestrator.go | 13 +++++-------- .../scenario_orchestrator.go | 6 +++--- .../test/common_test_functions.go | 18 +++++++++--------- 9 files changed, 30 insertions(+), 45 deletions(-) diff --git a/cmd/graph.go b/cmd/graph.go index d84a956..b0240dd 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -41,7 +41,6 @@ func NewGraphRunCommand(factory *providerfactory.ProviderFactory, scenarioOrches spinner := NewSpinnerWithSuffix("running graph based chaos plan...") volumes := make(map[string]string) environment := make(map[string]string) - debug := false kubeconfig, err := cmd.Flags().GetString("kubeconfig") if err != nil { return err @@ -64,7 +63,6 @@ func NewGraphRunCommand(factory *providerfactory.ProviderFactory, scenarioOrches return fmt.Errorf("file %s does not exist", metricsProfile) } - debug, err = cmd.Flags().GetBool("debug") if err != nil { return err } @@ -158,7 +156,7 @@ func NewGraphRunCommand(factory *providerfactory.ProviderFactory, scenarioOrches } go func() { - (*scenarioOrchestrator).RunGraph(nodes, executionPlan, environment, volumes, false, commChannel, ctx, debug) + (*scenarioOrchestrator).RunGraph(nodes, executionPlan, environment, volumes, false, commChannel, ctx) }() for { diff --git a/cmd/run.go b/cmd/run.go index 46e64b9..2b8ae8c 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -77,7 +77,7 @@ func NewRunCommand(factory *factory.ProviderFactory, scenarioOrchestrator *scena } } - //cmd.LocalFlags().AddFlagSet(globalFlags) + cmd.LocalFlags().AddFlagSet(globalFlags) cmd.LocalFlags().AddFlagSet(scenarioFlags) cmd.SetHelpFunc(func(command *cobra.Command, args []string) { @@ -119,7 +119,6 @@ func NewRunCommand(factory *factory.ProviderFactory, scenarioOrchestrator *scena spinner.Start() runDetached := false - debug := false provider := GetProvider(false, factory) scenarioDetail, err := provider.GetScenarioDetail(args[0]) @@ -173,10 +172,6 @@ func NewRunCommand(factory *factory.ProviderFactory, scenarioOrchestrator *scena runDetached = true } - if a == "--debug" { - debug = true - } - if a == "--help" { spinner.Stop() cmd.Help() @@ -259,7 +254,7 @@ func NewRunCommand(factory *factory.ProviderFactory, scenarioOrchestrator *scena spinner.Stop() }() - _, err = (*scenarioOrchestrator).RunAttached(quayImageUri+":"+scenarioDetail.Name, containerName, environment, false, volumes, os.Stdout, os.Stderr, &commChan, conn, debug) + _, err = (*scenarioOrchestrator).RunAttached(quayImageUri+":"+scenarioDetail.Name, containerName, environment, false, volumes, os.Stdout, os.Stderr, &commChan, conn) if err != nil { var staterr *utils.ExitError if errors.As(err, &staterr) { @@ -270,7 +265,7 @@ func NewRunCommand(factory *factory.ProviderFactory, scenarioOrchestrator *scena scenarioDuration := time.Since(startTime) fmt.Println(fmt.Sprintf("%s ran for %s", scenarioDetail.Name, scenarioDuration.String())) } else { - containerId, err := (*scenarioOrchestrator).Run(quayImageUri+":"+scenarioDetail.Name, containerName, environment, false, volumes, nil, conn, debug) + containerId, err := (*scenarioOrchestrator).Run(quayImageUri+":"+scenarioDetail.Name, containerName, environment, false, volumes, nil, conn) if err != nil { return err } diff --git a/pkg/config/config.go b/pkg/config/config.go index 765d4e9..b0dc037 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -32,7 +32,6 @@ type Config struct { LabelTitleRegex string `json:"label_title_regex"` LabelDescriptionRegex string `json:"label_description_regex"` LabelInputFieldsRegex string `json:"label_input_fields_regex"` - DebugEnvironmentVariable string `json:"debug_environment_variable"` } //go:embed config.json diff --git a/pkg/config/config.json b/pkg/config/config.json index cbd79c4..5496344 100644 --- a/pkg/config/config.json +++ b/pkg/config/config.json @@ -25,5 +25,4 @@ "label_title_regex": "LABEL krknctl\\.title=\\\"?(.*)\\\"?", "label_description_regex": "LABEL krknctl\\.description=\\\"?(.*)\\\"?", "label_input_fields_regex": "LABEL krknctl\\.input_fields=\\'?(\\[.*\\])\\'?", - "debug_environment_variable": "KRKN_DEBUG" } diff --git a/pkg/scenario_orchestrator/common_functions.go b/pkg/scenario_orchestrator/common_functions.go index f796179..6b54a62 100644 --- a/pkg/scenario_orchestrator/common_functions.go +++ b/pkg/scenario_orchestrator/common_functions.go @@ -15,7 +15,7 @@ import ( "syscall" ) -func CommonRunGraph(scenarios models.ScenarioSet, resolvedGraph models.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *models.GraphCommChannel, orchestrator ScenarioOrchestrator, config config.Config, ctx context.Context, debug bool) { +func CommonRunGraph(scenarios models.ScenarioSet, resolvedGraph models.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *models.GraphCommChannel, orchestrator ScenarioOrchestrator, config config.Config, ctx context.Context) { env := make(map[string]string) volumes := make(map[string]string) @@ -51,7 +51,7 @@ func CommonRunGraph(scenarios models.ScenarioSet, resolvedGraph models.ResolvedG go func() { defer wg.Done() - _, _ = orchestrator.RunAttached(scenario.Image, containerName, env, cache, volumes, file, file, nil, ctx, debug) + _, _ = orchestrator.RunAttached(scenario.Image, containerName, env, cache, volumes, file, file, nil, ctx) }() } @@ -60,9 +60,9 @@ func CommonRunGraph(scenarios models.ScenarioSet, resolvedGraph models.ResolvedG commChannel <- nil } -func CommonRunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, c ScenarioOrchestrator, commChan *chan *string, ctx context.Context, debug bool) (*string, error) { +func CommonRunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, c ScenarioOrchestrator, commChan *chan *string, ctx context.Context) (*string, error) { - containerId, err := c.Run(image, containerName, env, cache, volumeMounts, commChan, ctx, debug) + containerId, err := c.Run(image, containerName, env, cache, volumeMounts, commChan, ctx) if err != nil { return nil, err } diff --git a/pkg/scenario_orchestrator/docker/scenario_orchestrator.go b/pkg/scenario_orchestrator/docker/scenario_orchestrator.go index 6a155d3..9afdb98 100644 --- a/pkg/scenario_orchestrator/docker/scenario_orchestrator.go +++ b/pkg/scenario_orchestrator/docker/scenario_orchestrator.go @@ -30,7 +30,7 @@ type ScenarioOrchestrator struct { ContainerRuntime orchestratormodels.ContainerRuntime } -func (c *ScenarioOrchestrator) Run(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, commChan *chan *string, ctx context.Context, debug bool) (*string, error) { +func (c *ScenarioOrchestrator) Run(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, commChan *chan *string, ctx context.Context) (*string, error) { cli, err := dockerClientFromContext(ctx) if err != nil { @@ -49,9 +49,6 @@ func (c *ScenarioOrchestrator) Run(image string, containerName string, env map[s } var envVars []string - if debug == true { - envVars = append(envVars, fmt.Sprintf("%s='True'", c.GetConfig().DebugEnvironmentVariable)) - } for k, v := range env { envVars = append(envVars, fmt.Sprintf("%s=%s", k, v)) @@ -434,13 +431,13 @@ func (c *ScenarioOrchestrator) AttachWait(containerId *string, stdout io.Writer, return &interrupted, nil } -func (c *ScenarioOrchestrator) RunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, commChan *chan *string, ctx context.Context, debug bool) (*string, error) { - containerId, err := scenario_orchestrator.CommonRunAttached(image, containerName, env, cache, volumeMounts, stdout, stderr, c, commChan, ctx, debug) +func (c *ScenarioOrchestrator) RunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, commChan *chan *string, ctx context.Context) (*string, error) { + containerId, err := scenario_orchestrator.CommonRunAttached(image, containerName, env, cache, volumeMounts, stdout, stderr, c, commChan, ctx) return containerId, err } -func (c *ScenarioOrchestrator) RunGraph(scenarios orchestratormodels.ScenarioSet, resolvedGraph orchestratormodels.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *orchestratormodels.GraphCommChannel, ctx context.Context, debug bool) { - scenario_orchestrator.CommonRunGraph(scenarios, resolvedGraph, extraEnv, extraVolumeMounts, cache, commChannel, c, c.Config, ctx, false) +func (c *ScenarioOrchestrator) RunGraph(scenarios orchestratormodels.ScenarioSet, resolvedGraph orchestratormodels.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *orchestratormodels.GraphCommChannel, ctx context.Context) { + scenario_orchestrator.CommonRunGraph(scenarios, resolvedGraph, extraEnv, extraVolumeMounts, cache, commChannel, c, c.Config, ctx) } func (c *ScenarioOrchestrator) PrintContainerRuntime() { diff --git a/pkg/scenario_orchestrator/podman/scenario_orchestrator.go b/pkg/scenario_orchestrator/podman/scenario_orchestrator.go index fafcfcb..17956a5 100644 --- a/pkg/scenario_orchestrator/podman/scenario_orchestrator.go +++ b/pkg/scenario_orchestrator/podman/scenario_orchestrator.go @@ -51,7 +51,7 @@ func (w *progressWriter) Write(p []byte) (n int, err error) { return len(p), nil } -func (c *ScenarioOrchestrator) Run(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, commChan *chan *string, ctx context.Context, debug bool) (*string, error) { +func (c *ScenarioOrchestrator) Run(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, commChan *chan *string, ctx context.Context) (*string, error) { imageExists, err := images.Exists(ctx, image, nil) if cache == false || imageExists == false { @@ -95,9 +95,6 @@ func (c *ScenarioOrchestrator) Run(image string, containerName string, env map[s s.Name = containerName s.Env = env - if debug == true { - s.Env[c.GetConfig().DebugEnvironmentVariable] = "True" - } for k, v := range volumeMounts { containerMount := specs.Mount{ @@ -318,9 +315,9 @@ func (c *ScenarioOrchestrator) ResolveContainerName(containerName string, ctx co // common functions -func (c *ScenarioOrchestrator) RunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, commChan *chan *string, ctx context.Context, debug bool) (*string, error) { +func (c *ScenarioOrchestrator) RunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, commChan *chan *string, ctx context.Context) (*string, error) { time.Sleep(2) - return scenario_orchestrator.CommonRunAttached(image, containerName, env, cache, volumeMounts, stdout, stderr, c, commChan, ctx, debug) + return scenario_orchestrator.CommonRunAttached(image, containerName, env, cache, volumeMounts, stdout, stderr, c, commChan, ctx) } func (c *ScenarioOrchestrator) AttachWait(containerId *string, stdout io.Writer, stderr io.Writer, ctx context.Context) (*bool, error) { @@ -332,9 +329,9 @@ func (c *ScenarioOrchestrator) AttachWait(containerId *string, stdout io.Writer, return &interrupted, nil } -func (c *ScenarioOrchestrator) RunGraph(scenarios orchestratormodels.ScenarioSet, resolvedGraph orchestratormodels.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *orchestratormodels.GraphCommChannel, ctx context.Context, debug bool) { +func (c *ScenarioOrchestrator) RunGraph(scenarios orchestratormodels.ScenarioSet, resolvedGraph orchestratormodels.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *orchestratormodels.GraphCommChannel, ctx context.Context) { //TODO: add a getconfig method in scenarioOrchestrator - scenario_orchestrator.CommonRunGraph(scenarios, resolvedGraph, extraEnv, extraVolumeMounts, cache, commChannel, c, c.Config, ctx, debug) + scenario_orchestrator.CommonRunGraph(scenarios, resolvedGraph, extraEnv, extraVolumeMounts, cache, commChannel, c, c.Config, ctx) } func (c *ScenarioOrchestrator) PrintContainerRuntime() { diff --git a/pkg/scenario_orchestrator/scenario_orchestrator.go b/pkg/scenario_orchestrator/scenario_orchestrator.go index e17fb4b..11695ef 100644 --- a/pkg/scenario_orchestrator/scenario_orchestrator.go +++ b/pkg/scenario_orchestrator/scenario_orchestrator.go @@ -11,11 +11,11 @@ import ( type ScenarioOrchestrator interface { Connect(containerRuntimeUri string) (context.Context, error) - Run(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, commChan *chan *string, ctx context.Context, debug bool) (*string, error) + Run(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, commChan *chan *string, ctx context.Context) (*string, error) - RunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, commChan *chan *string, ctx context.Context, debug bool) (*string, error) + RunAttached(image string, containerName string, env map[string]string, cache bool, volumeMounts map[string]string, stdout io.Writer, stderr io.Writer, commChan *chan *string, ctx context.Context) (*string, error) - RunGraph(scenarios orchestrator_models.ScenarioSet, resolvedGraph orchestrator_models.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *orchestrator_models.GraphCommChannel, ctx context.Context, debug bool) + RunGraph(scenarios orchestrator_models.ScenarioSet, resolvedGraph orchestrator_models.ResolvedGraph, extraEnv map[string]string, extraVolumeMounts map[string]string, cache bool, commChannel chan *orchestrator_models.GraphCommChannel, ctx context.Context) CleanContainers(ctx context.Context) (*int, error) diff --git a/pkg/scenario_orchestrator/test/common_test_functions.go b/pkg/scenario_orchestrator/test/common_test_functions.go index 5cbd181..f6cf405 100644 --- a/pkg/scenario_orchestrator/test/common_test_functions.go +++ b/pkg/scenario_orchestrator/test/common_test_functions.go @@ -70,7 +70,7 @@ func CommonTestScenarioOrchestratorRun(t *testing.T, so scenario_orchestrator.Sc fmt.Println("CONTAINER SOCKET -> " + *socket) timestamp := time.Now().Unix() containerName := fmt.Sprintf("%s-%s-%d", conf.ContainerPrefix, scenario.Name, timestamp) - containerId, err := so.Run(registryUri+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx, false) + containerId, err := so.Run(registryUri+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx) assert.Nil(t, err) assert.NotNil(t, containerId) return *containerId @@ -113,7 +113,7 @@ func CommonTestScenarioOrchestratorRunAttached(t *testing.T, so scenario_orchest fmt.Println("CONTAINER SOCKET -> " + *socket) containerName1 := utils.GenerateContainerName(conf, scenario.Name, nil) - containerId, err := so.RunAttached(registryUri+":"+scenario.Name, containerName1, env, false, map[string]string{}, os.Stdout, os.Stderr, nil, ctx, false) + containerId, err := so.RunAttached(registryUri+":"+scenario.Name, containerName1, env, false, map[string]string{}, os.Stdout, os.Stderr, nil, ctx) if err != nil { fmt.Println("ERROR -> " + err.Error()) } @@ -125,7 +125,7 @@ func CommonTestScenarioOrchestratorRunAttached(t *testing.T, so scenario_orchest env["END"] = fmt.Sprintf("%d", duration) env["EXIT_STATUS"] = fmt.Sprintf("%d", exitStatus) containerName2 := utils.GenerateContainerName(conf, scenario.Name, nil) - containerId, err = so.RunAttached(registryUri+":"+scenario.Name, containerName2, env, false, map[string]string{}, os.Stdout, os.Stderr, nil, ctx, false) + containerId, err = so.RunAttached(registryUri+":"+scenario.Name, containerName2, env, false, map[string]string{}, os.Stdout, os.Stderr, nil, ctx) if err != nil { fmt.Println("ERROR -> " + err.Error()) } @@ -271,7 +271,7 @@ func CommonTestScenarioOrchestratorRunGraph(t *testing.T, so scenario_orchestrat commChannel := make(chan *models.GraphCommChannel) go func() { - so.RunGraph(nodes, executionPlan, map[string]string{}, map[string]string{}, false, commChannel, ctx, false) + so.RunGraph(nodes, executionPlan, map[string]string{}, map[string]string{}, false, commChannel, ctx) }() for { @@ -404,7 +404,7 @@ func CommonTestScenarioOrchestratorResolveContainerName(t *testing.T, so scenari fmt.Println("CONTAINER SOCKET -> " + *socket) containerName := utils.GenerateContainerName(conf, scenario.Name, nil) - containerId, err := so.RunAttached(registryUri+":"+scenario.Name, containerName, env, false, map[string]string{}, os.Stdout, os.Stderr, nil, ctx, false) + containerId, err := so.RunAttached(registryUri+":"+scenario.Name, containerName, env, false, map[string]string{}, os.Stdout, os.Stderr, nil, ctx) assert.Nil(t, err) assert.NotNil(t, containerId) @@ -456,7 +456,7 @@ func CommonTestScenarioOrchestratorKillContainers(t *testing.T, so scenario_orch fmt.Println("CONTAINER SOCKET -> " + *socket) timestamp := time.Now().Unix() containerName := fmt.Sprintf("%s-%s-kill-%d", conf.ContainerPrefix, scenario.Name, timestamp) - containerId, err := so.Run(registryUri+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx, false) + containerId, err := so.Run(registryUri+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx) time.Sleep(2 * time.Second) containers, err := so.ListRunningContainers(ctx) assert.Nil(t, err) @@ -526,8 +526,8 @@ func CommonTestScenarioOrchestratorListRunningScenarios(t *testing.T, so scenari //starting containers in inverted order to check if lisRunningScenarios returns them sorted sortedContainers := make(map[int]string) - _, err = so.Run(registryUri+":"+scenario.Name, containerName2, env, false, map[string]string{}, nil, ctx, false) - _, err = so.Run(registryUri+":"+scenario.Name, containerName1, env, false, map[string]string{}, nil, ctx, false) + _, err = so.Run(registryUri+":"+scenario.Name, containerName2, env, false, map[string]string{}, nil, ctx) + _, err = so.Run(registryUri+":"+scenario.Name, containerName1, env, false, map[string]string{}, nil, ctx) time.Sleep(1 * time.Second) assert.Nil(t, err) @@ -586,7 +586,7 @@ func CommonTestScenarioOrchestratorInspectRunningScenario(t *testing.T, so scena fmt.Println("CONTAINER SOCKET -> " + *socket) containerName1 := utils.GenerateContainerName(conf, scenario.Name, nil) - containerId1, err := so.Run(registryUri+":"+scenario.Name, containerName1, env, false, map[string]string{}, nil, ctx, false) + containerId1, err := so.Run(registryUri+":"+scenario.Name, containerName1, env, false, map[string]string{}, nil, ctx) assert.Nil(t, err) time.Sleep(1 * time.Second)