Skip to content

Commit

Permalink
removed debug hardcoded flag
Browse files Browse the repository at this point in the history
Signed-off-by: Tullio Sebastiani <[email protected]>
  • Loading branch information
tsebastiani committed Dec 13, 2024
1 parent b350af6 commit 1103653
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 45 deletions.
4 changes: 1 addition & 3 deletions cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 3 additions & 8 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
8 changes: 4 additions & 4 deletions pkg/scenario_orchestrator/common_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}()

}
Expand All @@ -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
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/scenario_orchestrator/docker/scenario_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 5 additions & 8 deletions pkg/scenario_orchestrator/podman/scenario_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/scenario_orchestrator/scenario_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 9 additions & 9 deletions pkg/scenario_orchestrator/test/common_test_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1103653

Please sign in to comment.