...

Source file src/github.com/redhat-developer/odo/pkg/dev/common/run.go

Documentation: github.com/redhat-developer/odo/pkg/dev/common

     1  package common
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/redhat-developer/odo/pkg/component"
     8  	"github.com/redhat-developer/odo/pkg/configAutomount"
     9  	"github.com/redhat-developer/odo/pkg/devfile/image"
    10  	"github.com/redhat-developer/odo/pkg/exec"
    11  	"github.com/redhat-developer/odo/pkg/libdevfile"
    12  	odocontext "github.com/redhat-developer/odo/pkg/odo/context"
    13  	"github.com/redhat-developer/odo/pkg/platform"
    14  	"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
    15  )
    16  
    17  func Run(
    18  	ctx context.Context,
    19  	commandName string,
    20  	platformClient platform.Client,
    21  	execClient exec.Client,
    22  	configAutomountClient configAutomount.Client,
    23  	filesystem filesystem.Filesystem,
    24  ) error {
    25  	var (
    26  		componentName = odocontext.GetComponentName(ctx)
    27  		devfileObj    = odocontext.GetEffectiveDevfileObj(ctx)
    28  		devfilePath   = odocontext.GetDevfilePath(ctx)
    29  	)
    30  
    31  	pod, err := platformClient.GetPodUsingComponentName(componentName)
    32  	if err != nil {
    33  		return fmt.Errorf("unable to get pod for component %s: %w. Please check the command 'odo dev' is running", componentName, err)
    34  	}
    35  
    36  	handler := component.NewRunHandler(
    37  		ctx,
    38  		platformClient,
    39  		execClient,
    40  		configAutomountClient,
    41  		filesystem,
    42  		image.SelectBackend(ctx),
    43  		component.HandlerOptions{
    44  			PodName:           pod.Name,
    45  			ContainersRunning: component.GetContainersNames(pod),
    46  			Msg:               "Executing command in container",
    47  			DirectRun:         true,
    48  			Devfile:           *devfileObj,
    49  			Path:              devfilePath,
    50  		},
    51  	)
    52  
    53  	return libdevfile.ExecuteCommandByName(ctx, *devfileObj, commandName, handler, false)
    54  }
    55  

View as plain text