mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Make sure to run parallel commands part of a composite command in parallel * Display warnings in case there are errors when executing pre-stop events * Fix the command_composite_parallel.go implementation by lowering the case of the sub-command names Since this passed the Devfile validation logic, we should use the same logic as in command_composite.go
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package libdevfile
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"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/v2/common"
|
|
|
|
"github.com/redhat-developer/odo/pkg/util"
|
|
)
|
|
|
|
type command interface {
|
|
CheckValidity() error
|
|
Execute(ctx context.Context, handler Handler, parentGroup *v1alpha2.CommandGroup) error
|
|
}
|
|
|
|
// newCommand returns a command implementation, depending on the type of the command
|
|
func newCommand(devfileObj parser.DevfileObj, devfileCmd v1alpha2.Command) (command, error) {
|
|
var cmd command
|
|
|
|
commandType, err := common.GetCommandType(devfileCmd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
switch commandType {
|
|
|
|
case v1alpha2.ApplyCommandType:
|
|
cmd = newApplyCommand(devfileObj, devfileCmd)
|
|
|
|
case v1alpha2.CompositeCommandType:
|
|
if util.SafeGetBool(devfileCmd.Composite.Parallel) {
|
|
cmd = newParallelCompositeCommand(devfileObj, devfileCmd)
|
|
} else {
|
|
cmd = newCompositeCommand(devfileObj, devfileCmd)
|
|
}
|
|
|
|
case v1alpha2.ExecCommandType:
|
|
cmd = newExecCommand(devfileObj, devfileCmd)
|
|
}
|
|
|
|
if err = cmd.CheckValidity(); err != nil {
|
|
return nil, err
|
|
}
|
|
return cmd, nil
|
|
}
|
|
|
|
// allCommandsMap returns a map of all commands in the devfile, indexed by Id
|
|
func allCommandsMap(devfileObj parser.DevfileObj) (map[string]v1alpha2.Command, error) {
|
|
commands, err := devfileObj.Data.GetCommands(common.DevfileOptions{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
commandMap := make(map[string]v1alpha2.Command, len(commands))
|
|
for _, command := range commands {
|
|
commandMap[strings.ToLower(command.Id)] = command
|
|
}
|
|
|
|
return commandMap, nil
|
|
}
|