Skip to content

Commit

Permalink
Updated Logs for V2 (#3208)
Browse files Browse the repository at this point in the history
Fixed interface implementation for v2
Updated logs
refactored commands.go
  • Loading branch information
Aditi Sharma authored May 19, 2020
1 parent 773cdae commit ef55201
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
41 changes: 17 additions & 24 deletions pkg/devfile/adapters/common/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// GetCommand iterates through the devfile commands and returns the associated devfile command
func getCommand(data data.DevfileData, commandName string, groupType common.DevfileCommandGroupType, required bool) (supportedCommand common.DevfileCommand, err error) {
func getCommand(data data.DevfileData, commandName string, groupType common.DevfileCommandGroupType) (supportedCommand common.DevfileCommand, err error) {

for _, command := range data.GetCommands() {
// validate command
Expand Down Expand Up @@ -62,14 +62,18 @@ func getCommand(data data.DevfileData, commandName string, groupType common.Devf
}
}

// The command was not found
msg := fmt.Sprintf("The command \"%v\" was not found in the devfile", commandName)
if required {
// Not found and required, return an error
err = fmt.Errorf(msg)
// if any command specified via flag is not found in devfile then it is an error.
if commandName != "" {
err = fmt.Errorf("The command \"%v\" is not found in the devfile", commandName)
} else {
// Not found and optional, so just log it
klog.V(3).Info(msg)
msg := fmt.Sprintf("The command type \"%v\" is not found in the devfile", groupType)
// if run command is not found in devfile then it is an error
if groupType == common.RunCommandGroupType {
err = fmt.Errorf(msg)
} else {
klog.V(3).Info(msg)

}
}

return
Expand Down Expand Up @@ -115,30 +119,19 @@ func validateCommand(data data.DevfileData, command common.DevfileCommand) (err
// GetInitCommand iterates through the components in the devfile and returns the init command
func GetInitCommand(data data.DevfileData, devfileInitCmd string) (initCommand common.DevfileCommand, err error) {

if devfileInitCmd != "" {
// a init command was specified so if it is not found then it is an error
return getCommand(data, devfileInitCmd, common.InitCommandGroupType, true)
}
// a init command was not specified so if it is not found then it is not an error
return getCommand(data, "", common.InitCommandGroupType, false)
return getCommand(data, devfileInitCmd, common.InitCommandGroupType)
}

// GetBuildCommand iterates through the components in the devfile and returns the build command
func GetBuildCommand(data data.DevfileData, devfileBuildCmd string) (buildCommand common.DevfileCommand, err error) {
if devfileBuildCmd != "" {
// a build command was specified so if it is not found then it is an error
return getCommand(data, devfileBuildCmd, common.BuildCommandGroupType, true)
}
// a build command was not specified so if it is not found then it is not an error
return getCommand(data, "", common.BuildCommandGroupType, false)

return getCommand(data, devfileBuildCmd, common.BuildCommandGroupType)
}

// GetRunCommand iterates through the components in the devfile and returns the run command
func GetRunCommand(data data.DevfileData, devfileRunCmd string) (runCommand common.DevfileCommand, err error) {
if devfileRunCmd != "" {
return getCommand(data, devfileRunCmd, common.RunCommandGroupType, true)
}
return getCommand(data, "", common.RunCommandGroupType, true)

return getCommand(data, devfileRunCmd, common.RunCommandGroupType)
}

// ValidateAndGetPushDevfileCommands validates the build and the run command,
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type CommandNames struct {
func isComponentSupported(component common.DevfileComponent) bool {
// Currently odo only uses devfile components of type container, since most of the Che registry devfiles use it
if component.Container != nil {
klog.V(3).Infof("Found component \"%v\" with name \"%v\"\n", common.ContainerComponentType, component.Container.Name)
return true
}
return false
Expand All @@ -102,7 +103,6 @@ func GetSupportedComponents(data data.DevfileData) []common.DevfileComponent {
// Only components with aliases are considered because without an alias commands cannot reference them
for _, comp := range data.GetAliasedComponents() {
if isComponentSupported(comp) {
klog.V(3).Infof("Found component \"%v\" with alias \"%v\"\n", comp.Type, comp.Container.Name)
components = append(components, comp)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/devfile/parser/data/2.0.0/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (d *Devfile200) GetParent() common.DevfileParent {
return d.Parent
}

// GetProject returns the DevfileProject Object parsed from devfile
func (d *Devfile200) GetProject() []common.DevfileProject {
// GetProjects returns the DevfileProject Object parsed from devfile
func (d *Devfile200) GetProjects() []common.DevfileProject {
return d.Projects
}

Expand Down

0 comments on commit ef55201

Please sign in to comment.