Skip to content

Commit

Permalink
updates to make it work with devfile/library v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kadel committed Oct 8, 2021
1 parent b4a4bff commit 8b87d85
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 96 deletions.
5 changes: 3 additions & 2 deletions pkg/devfile/adapters/common/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser/data"
parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
"k8s.io/klog"
)
Expand All @@ -34,7 +35,7 @@ func New(devfile devfilev1.Command, knowCommands map[string]devfilev1.Command, e
return nil, fmt.Errorf("composite command %q has command %v not found in devfile", cmd, devfile)
}
}
if composite.Parallel {
if util.SafeGetBool(composite.Parallel) {
return newParallelCompositeCommand(components...), nil
}
return newCompositeCommand(components...), nil
Expand Down Expand Up @@ -69,7 +70,7 @@ func getCommandFromDevfile(data data.DevfileData, groupType devfilev1.CommandGro
for _, command := range commands {
cmdGroup := parsercommon.GetGroup(command)
if cmdGroup != nil && cmdGroup.Kind == groupType {
if cmdGroup.IsDefault {
if util.SafeGetBool(cmdGroup.IsDefault) {
return command, nil
} else if reflect.DeepEqual(onlyCommand, devfilev1.Command{}) {
// return the only remaining command for the group if there is no default command
Expand Down
54 changes: 27 additions & 27 deletions pkg/devfile/adapters/common/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestGetCommand(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: commands[0],
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestGetCommand(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: false},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(false)},
},
},
CommandLine: commands[0],
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestGetCommand(t *testing.T) {
Composite: &devfilev1.CompositeCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(true)},
},
},
Commands: []string{"build", "run"},
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestGetCommandFromDevfile(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: commands[0],
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestGetCommandFromDevfile(t *testing.T) {
Composite: &devfilev1.CompositeCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(true)},
},
},
Commands: []string{"build1", "run"},
Expand All @@ -385,7 +385,7 @@ func TestGetCommandFromDevfile(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: false},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(false)},
},
},
CommandLine: commands[0],
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestGetCommandFromDevfile(t *testing.T) {
Composite: &devfilev1.CompositeCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(true)},
},
},
Commands: []string{"build", "run"},
Expand All @@ -428,7 +428,7 @@ func TestGetCommandFromDevfile(t *testing.T) {
Composite: &devfilev1.CompositeCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: false},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(false)},
},
},
Commands: []string{"build", "run"},
Expand Down Expand Up @@ -606,7 +606,7 @@ func TestGetCommandFromFlag(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: commands[0],
Expand All @@ -620,7 +620,7 @@ func TestGetCommandFromFlag(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: commands[0],
Expand Down Expand Up @@ -698,7 +698,7 @@ func TestGetCommandFromFlag(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: false},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(false)},
},
},
CommandLine: commands[0],
Expand Down Expand Up @@ -728,7 +728,7 @@ func TestGetCommandFromFlag(t *testing.T) {
Composite: &devfilev1.CompositeCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(true)},
},
},
Commands: []string{"build", "run"},
Expand All @@ -741,7 +741,7 @@ func TestGetCommandFromFlag(t *testing.T) {
Composite: &devfilev1.CompositeCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: false},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(false)},
},
},
Commands: []string{"build", "run"},
Expand Down Expand Up @@ -824,7 +824,7 @@ func TestGetBuildCommand(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: command,
Expand All @@ -839,7 +839,7 @@ func TestGetBuildCommand(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: command,
Expand Down Expand Up @@ -984,7 +984,7 @@ func TestGetDebugCommand(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
Kind: devfilev1.DebugCommandGroupKind,
},
},
Expand All @@ -1009,7 +1009,7 @@ func TestGetDebugCommand(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: false,
IsDefault: util.GetBoolPtr(false),
Kind: devfilev1.DebugCommandGroupKind,
},
},
Expand All @@ -1033,7 +1033,7 @@ func TestGetDebugCommand(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
Kind: devfilev1.BuildCommandGroupKind,
},
},
Expand Down Expand Up @@ -1109,7 +1109,7 @@ func TestGetTestCommand(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
Kind: devfilev1.TestCommandGroupKind,
},
},
Expand All @@ -1134,7 +1134,7 @@ func TestGetTestCommand(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: false,
IsDefault: util.GetBoolPtr(false),
Kind: devfilev1.TestCommandGroupKind,
},
},
Expand All @@ -1158,7 +1158,7 @@ func TestGetTestCommand(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
Kind: devfilev1.BuildCommandGroupKind,
},
},
Expand Down Expand Up @@ -1233,7 +1233,7 @@ func TestGetRunCommand(t *testing.T) {
Exec: &devfilev1.ExecCommand{
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: true},
Group: &devfilev1.CommandGroup{Kind: runGroup, IsDefault: util.GetBoolPtr(true)},
},
},
CommandLine: command,
Expand Down Expand Up @@ -1351,7 +1351,7 @@ func TestValidateAndGetDebugDevfileCommands(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
Kind: devfilev1.DebugCommandGroupKind,
},
},
Expand All @@ -1369,7 +1369,7 @@ func TestValidateAndGetDebugDevfileCommands(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: false,
IsDefault: util.GetBoolPtr(false),
Kind: devfilev1.DebugCommandGroupKind,
},
},
Expand Down Expand Up @@ -1465,7 +1465,7 @@ func TestValidateAndGetPushDevfileCommands(t *testing.T) {
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
Kind: runGroup,
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
},
},
},
Expand Down Expand Up @@ -1641,7 +1641,7 @@ func TestValidateAndGetTestDevfileCommands(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: true,
IsDefault: util.GetBoolPtr(true),
Kind: devfilev1.TestCommandGroupKind,
},
},
Expand All @@ -1659,7 +1659,7 @@ func TestValidateAndGetTestDevfileCommands(t *testing.T) {
LabeledCommand: devfilev1.LabeledCommand{
BaseCommand: devfilev1.BaseCommand{
Group: &devfilev1.CommandGroup{
IsDefault: false,
IsDefault: util.GetBoolPtr(false),
Kind: devfilev1.TestCommandGroupKind,
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/devfile/adapters/common/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/machineoutput"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
"k8s.io/klog"
)
Expand Down Expand Up @@ -145,7 +146,7 @@ func (a GenericAdapter) ExecDevfile(commandsMap PushCommandsMap, componentExists
}
}

restart := IsRestartRequired(command.Exec.HotReloadCapable, params.RunModeChanged)
restart := IsRestartRequired(util.SafeGetBool(command.Exec.HotReloadCapable), params.RunModeChanged)

// if we need to restart, issue supervisor command to stop all running commands first
// we do not need to restart Hot reload capable commands
Expand Down
Loading

0 comments on commit 8b87d85

Please sign in to comment.