-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Devfile v2 command group impl + Odo catalog list components #3291
Devfile v2 command group impl + Odo catalog list components #3291
Conversation
Skipping CI for Draft Pull Request. |
Codecov Report
@@ Coverage Diff @@
## master #3291 +/- ##
==========================================
+ Coverage 46.39% 46.49% +0.10%
==========================================
Files 112 112
Lines 11233 11227 -6
==========================================
+ Hits 5211 5220 +9
+ Misses 5517 5506 -11
+ Partials 505 501 -4
Continue to review full report at Codecov.
|
👋 @adisky could you pls help review the command group code? @GeekArthur could you pls help review the catalog and create code? thx! |
return command, validateCommand(data, command) | ||
} else if reflect.DeepEqual(firstMatchedCommand, common.DevfileCommand{}) { | ||
// store the first matched command in case there is no default command | ||
firstMatchedCommand = command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rename it to onlyCommand
or singleCommand
? IIUC we are throwing error if more than one command of a grouptype is present and none of them is default and if only one command is present without any default value we are allowing it. So it should be that one command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we can rename it.
Actually there is a case where multiple defaults can be present ie when we use odo push --build-command="mybuild1"
. mybuild1
and mybuild2
can be default or have no defaults at all and this is fine since we're explicitly using a flag and saying what command to run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that case we are already covering above if commandName != "" , IIUC that case would not fallback here, also can we update the comment // store the first matched command in case there is no default command
to return the only remaining command for the group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary to do in this PR, but should we separate the flag command and devfile command function for better code readability?
getCommandFromFlags
getCommandfromDevfile
and in the GetRunCommand
, GetBuildCommand
functions includes the check for command name?
IMO this one(what i had written also) is difficult to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that case we are already covering above if commandName != "" , IIUC that case would not fallback here, also can we update the comment // store the first matched command in case there is no default command to return the only remaining command for the group
you're right, i have updated the comment to
// return the only remaining command for the group if there is no default command
// NOTE: we return outside the for loop since the next iteration can have a default command
Not necessary to do in this PR, but should we separate the flag command and devfile command function for better code readability?
yeah i think it makes sense to have different funcs and separate out their logic for better readability. I think anyone else reading it will be confused in the first few attempts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the getCommand() func. Broken down into getCommandFromFlag() and getCommandfromDevfile() and moved their specific logic to these funcs.
getCommand() does the check for commandName and splits into either of the above two function calls. This way we can just use getCommand() from anywhere instead of doing this check everywhere when we need a command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maysunfaisal Thanks for doing this, now it is much easier to understand :)
if commandName == "" { | ||
// if default command is not found return the first command found for the matching type. | ||
for _, command := range commands { | ||
|
||
if command.Exec.Group != nil && command.Exec.Group.Kind == groupType { | ||
supportedCommand = command | ||
return supportedCommand, nil | ||
} | ||
if !reflect.DeepEqual(firstMatchedCommand, common.DevfileCommand{}) { | ||
return firstMatchedCommand, validateCommand(data, firstMatchedCommand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is not required now, this block could be removed and we can return from above else if
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this. Prior to this PR, we used two for loops to get the default command and the first command of group type.
But now we're checking for both in the same for loop..
For example if a devfile has two build commands in order
- devbuild1
- devbuild2 {default:true}
if we removed the if condition and returned in else if
, it will incorrectly return devbuild1 even tho in the next iteration there is a default command.
But with this if block it solves the two cases ie multiple commands of same group in any order and also one command of a group kind.
@@ -109,6 +109,18 @@ func GetSupportedComponents(data data.DevfileData) []common.DevfileComponent { | |||
return components | |||
} | |||
|
|||
func getCommandsForGroup(data data.DevfileData, groupType common.DevfileCommandGroupType) []common.DevfileCommand { | |||
var commands []common.DevfileCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/getCommandsForGroup/getCommandsByGroup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
var commands []common.DevfileCommand | ||
|
||
for _, command := range d.Commands { | ||
command.Exec.Id = strings.ToLower(command.Exec.Id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need this? Please add comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
|
||
if defaultCommandCount != 1 { | ||
return fmt.Errorf("there should be one default command for command group %v", groupType) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be only one default command for command group
there should be one default command for command group
signifying that no default command is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this condition checks for both missing and multiple defaults if there is more than one command of same group.
I'll update to there should be at most one default command for command group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we could return different error for defaultCommandCount=0
& defaultCommandCount >1
or
there should be exactly one default command for command group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah makes sense, updated the err statements based on the default command count
@maysunfaisal Overall looks good to me, tested for command scenarios working well. |
f193ab0
to
2653ae1
Compare
pkg/catalog/catalog.go
Outdated
// 3. Add devfile component types to the catalog devfile list | ||
retrieveDevfiles := util.NewConcurrentTasks(len(registryIndices)) | ||
devfileMutex := &sync.Mutex{} | ||
// Add stacks to the catalog devfile list | ||
for _, index := range registryIndices { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the code block of downloading the devfile for getting information of devfile support criterias, we don't need this for loop either. DevfileComponentType
population step can be done inside function getDevfileIndexEntries
when we download the index file. With this for loop removal, we can increase the performance a lot as we don't need to iterate through the all index entries again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, updated
pkg/odo/cli/component/create.go
Outdated
var componentType string | ||
var componentName string | ||
var componentNamespace string | ||
isDevfileRegistryPresent := true // defaulted to true since odo ships with a default registry set | ||
|
||
// Component type: We provide devfile component list to let user choose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make the function catalog.ListDevfileComponents
global because we have the case where creating devfile component from existing devfile, that case doesn't need this function so that make this function global can reduce the performance. This function only use by creating devfile component from registry (either interactive or direct mode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
pkg/odo/cli/component/create.go
Outdated
co.devfileMetadata.componentType = componentType | ||
co.devfileMetadata.componentName = strings.ToLower(componentName) | ||
co.devfileMetadata.componentNamespace = strings.ToLower(componentNamespace) | ||
if isDevfileRegistryPresent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isDevfileRegistryPresent
flag should only apply to the case where creating devfile component from registry, which means if the registry list is empty user still can use the existing devfile to create devfile component. So isDevfileRegistryPresent
flag should be used here https://github.com/openshift/odo/pull/3291/files#diff-58fe314b4e3f9120402717ab8c2b3049L512 instead of the whole code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it doesnt matter because isDevfileRegistryPresent
is true by default but i moved it because local devfile is not devfile registry. So later when ppl comes to read the code they dont get confused,
But I had to move the header Validation
to inside the if blocks to keep interactive mode clean.
The PR looks good, request some changes for performance improvement as Also leave couple of comments below:
|
pkg/catalog/catalog.go
Outdated
// 3. Add devfile component types to the catalog devfile list | ||
retrieveDevfiles := util.NewConcurrentTasks(len(registryIndices)) | ||
devfileMutex := &sync.Mutex{} | ||
// Add stacks to the catalog devfile list | ||
for _, index := range registryIndices { | ||
// Load the devfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we can remove this comment as we don't download/load the devfile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
I don't think that we need to deal with backward compatibility in this case. All this is still done in the experimental mode. The main reason to introduce experimental mode was to allow us to experiment and break thinks if needed without dealing with backward compatibility issues.
I don't think that we need to check for support criteria before Erroring out in /approve |
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Add |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest |
@maysunfaisal Trying out your branch, it seems interactive mode is broken (but with a different issue than #3436): |
@johnmcollier you need to delete |
@maysunfaisal Ah, good catch. Yeah, that fixed things. We should maybe send a note out on #odo-dev then, if |
Signed-off-by: Maysun J Faisal maysun.j.faisal@ibm.com
What type of PR is this?
/kind feature
What does does this PR do / why we need it:
SUPPORTED
column for devfile catalog, see discussion at Improve performance forodo catalog list components
. #3249 (comment) 065f19b 9da66e9Which issue(s) this PR fixes:
Fixes #2938 #3271 #3249 #3280 #3436
How to test changes / Special notes to the reviewer:
odo catalog list components
(now lists new v2 devfiles)odo create springBoot mondayspringboot
odo url create
odo push
To test out the various push scenarios:
odo push --build-command --run-command
should succeedodo push --build-command="a run command of group run"