Skip to content

Commit

Permalink
Remove execHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed May 22, 2023
1 parent 02c9247 commit 5dd0879
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 114 deletions.
99 changes: 0 additions & 99 deletions pkg/component/exec_handler.go

This file was deleted.

41 changes: 41 additions & 0 deletions pkg/component/execute_terminating.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package component
import (
"context"
"fmt"
"io"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/redhat-developer/odo/pkg/exec"
"github.com/redhat-developer/odo/pkg/log"
Expand All @@ -14,6 +16,8 @@ import (
"k8s.io/utils/pointer"
)

const ShellExecutable string = "/bin/sh"

func ExecuteTerminatingCommand(ctx context.Context, execClient exec.Client, platformClient platform.Client, command devfilev1.Command, componentExists bool, podName string, appName string, componentName string, msg string, show bool) error {

if componentExists && command.Exec != nil && pointer.BoolDeref(command.Exec.HotReloadCapable, false) {
Expand Down Expand Up @@ -53,3 +57,40 @@ func ExecuteTerminatingCommand(ctx context.Context, execClient exec.Client, plat
}
return err
}

func getCmdline(command v1alpha2.Command) []string {
// deal with environment variables
var cmdLine string
setEnvVariable := util.GetCommandStringFromEnvs(command.Exec.Env)

if setEnvVariable == "" {
cmdLine = command.Exec.CommandLine
} else {
cmdLine = setEnvVariable + " && " + command.Exec.CommandLine
}

// Change to the workdir and execute the command
// Redirecting to /proc/1/fd/* allows to redirect the process output to the output streams of PID 1 process inside the container.
// This way, returning the container logs with 'odo logs' or 'kubectl logs' would work seamlessly.
// See https://stackoverflow.com/questions/58716574/where-exactly-do-the-logs-of-kubernetes-pods-come-from-at-the-container-level
redirectString := "1>>/proc/1/fd/1 2>>/proc/1/fd/2"
var cmd []string
if command.Exec.WorkingDir != "" {
// since we are using /bin/sh -c, the command needs to be within a single double quote instance, for example "cd /tmp && pwd"
cmd = []string{ShellExecutable, "-c", "cd " + command.Exec.WorkingDir + " && (" + cmdLine + ") " + redirectString}
} else {
cmd = []string{ShellExecutable, "-c", "(" + cmdLine + ") " + redirectString}
}
return cmd
}

func closeWriterAndWaitForAck(stdoutWriter *io.PipeWriter, stdoutChannel chan interface{}, stderrWriter *io.PipeWriter, stderrChannel chan interface{}) {
if stdoutWriter != nil {
_ = stdoutWriter.Close()
<-stdoutChannel
}
if stderrWriter != nil {
_ = stderrWriter.Close()
<-stderrChannel
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
package component

import (
"context"
"testing"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/v2/pkg/devfile/parser"
"github.com/devfile/library/v2/pkg/devfile/parser/data"
"github.com/golang/mock/gomock"
"github.com/redhat-developer/odo/pkg/exec"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/platform"
"k8s.io/utils/pointer"
)
package common

/*
var (
container1 = v1alpha2.Component{
Name: "my-container",
Expand Down Expand Up @@ -443,3 +430,4 @@ func TestExecute(t *testing.T) {
})
}
}
*/

0 comments on commit 5dd0879

Please sign in to comment.