Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky kubeexec unit test case with env vars #5845

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/devfile/adapters/kubernetes/component/commandhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func devfileCommandToRemoteCmdDefinition(devfileCmd devfilev1.Command) (remotecm
return remotecmd.CommandDefinition{}, errors.New(" only Exec commands are supported")
}

envVars := make(map[string]string, len(devfileCmd.Exec.Env))
envVars := make([]remotecmd.CommandEnvVar, 0, len(devfileCmd.Exec.Env))
for _, e := range devfileCmd.Exec.Env {
envVars[e.Name] = e.Value
envVars = append(envVars, remotecmd.CommandEnvVar{Key: e.Name, Value: e.Value})
}

return remotecmd.CommandDefinition{
Expand Down
4 changes: 2 additions & 2 deletions pkg/remotecmd/kubeexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (k *kubeExecProcessHandler) StartProcessForCommand(
// deal with environment variables
cmdLine := def.CmdLine
envCommands := make([]string, 0, len(def.EnvVars))
for key, val := range def.EnvVars {
envCommands = append(envCommands, fmt.Sprintf("%s='%s'", key, val))
for _, envVar := range def.EnvVars {
envCommands = append(envCommands, fmt.Sprintf("%s='%s'", envVar.Key, envVar.Value))
}
var setEnvCmd string
if len(envCommands) != 0 {
Expand Down
12 changes: 9 additions & 3 deletions pkg/remotecmd/kubexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ func TestKubeExecProcessHandler_StartProcessForCommand(t *testing.T) {
Id: "my-exec-cmd",
CmdLine: "tail -f /path/to/a/file",
WorkingDir: "/path/to/working/dir",
EnvVars: map[string]string{
"ENV_VAR1": "value1",
"ENV_VAR2": "value2",
EnvVars: []CommandEnvVar{
{
Key: "ENV_VAR1",
Value: "value1",
},
{
Key: "ENV_VAR2",
Value: "value2",
},
},
}
for _, tt := range []struct {
Expand Down
14 changes: 10 additions & 4 deletions pkg/remotecmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ type CommandDefinition struct {
WorkingDir string

// EnvVars are environment variables to set.
EnvVars map[string]string
EnvVars []CommandEnvVar

// CmdLine is the command-line that will get executed.
CmdLine string
}

// CommandEnvVar represents an environment variable used as part of running any CommandDefinition.
type CommandEnvVar struct {

// Key of the environment variable.
Key string

//// RedirectOutputToMain indicates whether to redirect this command output streams to the main (PID 1) one.
//// This can be useful to have the output of this command show up in `odo logs` or `kubectl logs`.
//RedirectOutputToMain bool
// Value of the environment variable.
Value string
}

// CommandOutputHandler is a function that is expected to handle the output and error returned by a command executed.
Expand Down