mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Document current implementations of command handlers * Add unit tests for execHAndler * Refactor pkg/devfile/image to inject Backend as dependency * Use same handler for kubedev/podmandev * Fail after SelectBackend==nil only if backend is needed * Move runHandler to dev/common * Unit tests for runHandler * Create a component.ExecuteTerminatingCommand * ExecuteTerminatingCommand/ExecuteNonTerminatingCommand for Handler * Fix calling other command types * Consider parent group to determine if a command is terminating * Replace component.execHandler by common.runHandler * Remove execHandler * Make runHandler and most of fields private and pass containersRunning to handler * Pass containersRunning value * deploy using common Handler * Fix tests * Use specific Dev/Deploy mode for Apply * Fix cmdline for job * Fix unit tests * Pass appName and componentName with ctx to handler * Move handler to pkg/component package * Update doc * Unit tests Deploy * Unit tests Build * Unit tests Run * Unit tests PostStart * Unit tests PreStop * Update doc * Fix Podman tests * Fix hotReload on podman * Change podman version timeout to 30s for tests * Cleanup + fix doc
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package libdevfile
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
|
|
"github.com/devfile/library/v2/pkg/devfile/parser"
|
|
)
|
|
|
|
// execCommand is a command implementation for exec commands
|
|
type execCommand struct {
|
|
command v1alpha2.Command
|
|
devfileObj parser.DevfileObj
|
|
}
|
|
|
|
var _ command = (*execCommand)(nil)
|
|
|
|
// newExecCommand creates a new execCommand instance, adapting the devfile-defined command to run in the target component's
|
|
// container, modifying it to add environment variables or adapting the path as needed.
|
|
func newExecCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *execCommand {
|
|
return &execCommand{
|
|
command: command,
|
|
devfileObj: devfileObj,
|
|
}
|
|
}
|
|
|
|
func (o *execCommand) CheckValidity() error {
|
|
return nil
|
|
}
|
|
|
|
func (o *execCommand) Execute(ctx context.Context, handler Handler, parentGroup *v1alpha2.CommandGroup) error {
|
|
if o.isTerminating(parentGroup) {
|
|
return handler.ExecuteTerminatingCommand(ctx, o.command)
|
|
}
|
|
return handler.ExecuteNonTerminatingCommand(ctx, o.command)
|
|
}
|
|
|
|
// isTerminating returns true if not Run or Debug command
|
|
func (o *execCommand) isTerminating(parentGroup *v1alpha2.CommandGroup) bool {
|
|
if parentGroup != nil {
|
|
kind := parentGroup.Kind
|
|
return isTerminatingKind(kind)
|
|
}
|
|
if o.command.Exec.Group == nil {
|
|
return true
|
|
}
|
|
kind := o.command.Exec.Group.Kind
|
|
return isTerminatingKind(kind)
|
|
}
|
|
|
|
func isTerminatingKind(kind v1alpha2.CommandGroupKind) bool {
|
|
return kind != v1alpha2.RunCommandGroupKind && kind != v1alpha2.DebugCommandGroupKind
|
|
}
|