|
| 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", componentName, err) |
| 34 | + } |
| 35 | + |
| 36 | + handler := component.NewRunHandler( |
| 37 | + ctx, |
| 38 | + platformClient, |
| 39 | + execClient, |
| 40 | + configAutomountClient, |
| 41 | + pod.Name, |
| 42 | + false, |
| 43 | + component.GetContainersNames(pod), |
| 44 | + "Executing command in container", |
| 45 | + |
| 46 | + filesystem, |
| 47 | + image.SelectBackend(ctx), |
| 48 | + *devfileObj, |
| 49 | + devfilePath, |
| 50 | + ) |
| 51 | + |
| 52 | + return libdevfile.ExecuteCommandByName(ctx, *devfileObj, commandName, handler, false) |
| 53 | +} |
0 commit comments