-
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
Add odo storage list --all command feature #568
Conversation
5b6f979
to
1ad4999
Compare
cmd/storage.go
Outdated
fmt.Println("Invalid arguments. component name is not needed") | ||
os.Exit(1) | ||
} | ||
componentList := getComponentList(client, applicationName, projectName) |
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 guess we can directly use component.List here instead of creating a new function in cmdutils
cmd/cmdutils.go
Outdated
@@ -60,6 +62,13 @@ func getComponent(client *occlient.Client, inputComponent, applicationName, proj | |||
return inputComponent | |||
} | |||
|
|||
// getComponentList returns the list of all components in current application and project | |||
func getComponentList(client *occlient.Client, applicationName, projectName string) []component.ComponentInfo { |
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 guess we can directly use component.List instead of using this function
The output looks like
The |
cmd/cmdutils.go
Outdated
@@ -60,6 +62,13 @@ func getComponent(client *occlient.Client, inputComponent, applicationName, proj | |||
return inputComponent | |||
} | |||
|
|||
// getComponentList returns the list of all components in current application and project |
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.
in the current application and project
cmd/cmdutils.go
Outdated
@@ -60,6 +62,13 @@ func getComponent(client *occlient.Client, inputComponent, applicationName, proj | |||
return inputComponent | |||
} | |||
|
|||
// getComponentList returns the list of all components in current application and project | |||
func getComponentList(client *occlient.Client, applicationName, projectName string) []component.ComponentInfo { |
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 be string for applicationName: applicationName string
cmd/cmdutils.go
Outdated
fmt.Fprintln(tabWriterMounted, "NAME", "\t", "SIZE", "\t", "PATH") | ||
fmt.Fprintln(tabWriterUnmounted, "NAME", "\t", "SIZE") | ||
|
||
for _, storage := range storageList { |
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.
need to add comments all here descripting what's going on. explaining that this is creating a table, etc.
} else { | ||
fmt.Printf("The component '%v' has no storage attached\n", componentName) | ||
} | ||
fmt.Println("") |
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 is kind of odd.. maybe remove the newline being adding and add newline to the other fmt.Printf
functions below?
cmd/storage.go
Outdated
fmt.Fprintln(tabWriterUnmounted, storage.Name, "\t", storage.Size) | ||
if storageAllListflag { | ||
if storageComponent != "" { | ||
fmt.Println("Invalid arguments. component name is not needed") |
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.
capitalize "Component"
Expect(storList).To(ContainSubstring("pv2")) | ||
}) | ||
|
||
// TODO: Verify if the storage removed using odo deletes pvc |
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.
does this need to removed?
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.
@cdrage It's not the part of my PR, not aware
Storage that is not mounted should be grouped together at the end of the output.
|
b2a6a34
to
edd9d4e
Compare
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.
Tested this PR, LGTM
only this small change
cmd/cmdutils.go
Outdated
} | ||
//print all mounted storages of the given component | ||
if hasMounted { | ||
fmt.Printf("The component '%v' has the following storage attached -\n", componentName) |
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.
put :
instead of -
@surajnarwade Fixed |
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.
The printStoragesInAllComponent needs a fix
cmd/cmdutils.go
Outdated
if !hasUnmounted { | ||
hasUnmounted = true | ||
} | ||
fmt.Fprintln(tabWriterUnmounted, storage.Name, "\t", storage.Size) |
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.
Storage.List() returns the unmounted storage in the same application. So if there are two or more components in the same application and one or more unmounted storage in the application, then this will display the same unmounted storage more than once as the unmounted storage are getting written to the tabWriterUnmounted more than once
[mdas@localhost odo]$ ./odo storage list --all
The component 'nodejs' has the following storage attached -
NAME SIZE PATH
backend-nodejs 100M /data-1
The component 'wildfly' has no storage attached
Storages that are not mounted to any component -
NAME SIZE
backend 100M
backend-wild 100M
backend 100M
backend-wild 100M
@cdrage Can you please review it again? |
cmd/storage.go
Outdated
fmt.Printf("No unmounted storage exists to mount to '%v' \n", componentName) | ||
//storageComponent is the input component name | ||
componentName := getComponent(client, storageComponent, applicationName, projectName) | ||
if componentName == "" { |
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 check is not required as getComponent() does the same thing
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.
LGTM :)
@ashetty1 Does E2E test change look good to you? |
@piyush1594 yes, tests LGTM |
Wouldn't it be better and easier to modify |
@cdrage can you please check if your comments were addressed? I think that we can merge it after that. (even though it could be solved a bit more elegant way 😇 ) |
d9ac235
to
2028bdb
Compare
@cdrage Thanks a lot for the review. Changes addressed |
be2f7c3
to
e98e5ab
Compare
pkg/storage/storage.go
Outdated
@@ -61,7 +61,7 @@ func Create(client *occlient.Client, name string, size string, path string, comp | |||
} | |||
|
|||
// Unmount unmounts the given storage from the given component | |||
func Unmount(client *occlient.Client, storageName string, componentName string, applicationName string) error { | |||
func Unmount(client *occlient.Client, storageName string, componentName string, applicationName string, updateLabels bool) error { |
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 a comment that will explain what updateLabels
does
} | ||
var storageList []StorageInfo | ||
for _, pvc := range pvcs { | ||
pvcComponentName, ok := pvc.Labels[componentlabels.ComponentLabel] | ||
pvcAppName, okApp := pvc.Labels[applabels.ApplicationLabel] | ||
// first check if storage label does not exists indicating that the storage is not mounted in any component | ||
// if the storage label exists, then check if the component is the current active component | ||
// first check if component label does not exists indicating that the storage is not mounted in any component |
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.
wasn't it correct before? It is checking labels on storage not on component
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.
it is checking the component label on storage so changed that way @kadel
@cdrage Can you please take a look again? TIA |
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.
LGTM :)
cmd/cmdutils.go
Outdated
|
||
//iterating over all the components in the given aplication and project | ||
for _, component := range componentList { | ||
componentName := component.Name |
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.
Can we reuse printStorageInComponent() here? Maybe by adding a flag in printStorageInComponent() called printUnmounted to print the unmounted storage part for the component
cmd/cmdutils.go
Outdated
storageListMounted, err := storage.ListMounted(client, componentName, applicationName) | ||
checkError(err, "Could not get mounted storage list") | ||
|
||
//iterating over all mounted storage and put in the mount storage table |
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.
Please add a space before all the comments like "// iterating ....."
cmd/cmdutils.go
Outdated
fmt.Fprintln(tabWriterUnmounted, "NAME", "\t", "SIZE") | ||
|
||
storageListMounted, err := storage.ListMounted(client, componentName, applicationName) | ||
checkError(err, "Could not get mounted storage list") |
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.
please start the error messages with a small letter
This will list all the storages in all the components in a current application and project Syntax will be odo storage list --all on execution of odo storage list --all componentName it will fail Fixes redhat-developer#507 Add e2e test related to feature Refactored the output format for --all flag Add comments about code flow Fix semicolon comment Fix issue of unmounted storage getting printed multiple times Add function for listing mounted storage and unmounted storage Add spacing before lines Add a flag in unmount function Basically in case of deleting pvc, we are first unmounting and then deleting. Then unmounting function is updating the labels So if we are deleting the pvc then updating call is not required Added a flag to update Labels or not, when delete function is called its set to false and when unmount is called it is set to true Add comments about updateLabels Made the code resuable and more simpler Address other indentation and format changes Make print format look good
cmd/cmdutils.go
Outdated
@@ -103,3 +105,68 @@ func validateStoragePath(client *occlient.Client, storagePath, componentName, ap | |||
} | |||
return nil | |||
} | |||
|
|||
// printMountedStorageInComponent prints all the mounted storage in a given component of the application | |||
func printMountedStorageInComponent(client *occlient.Client, applicationName string, componentName string) { |
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.
Please move componentName before applicationName
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.
LGTM :)
@cdrage Can we merge this? |
Yeah, this LGTM. Thanks for addressing my comments! |
Thanks @cdrage @mik-dass @kadel @surajnarwade |
This will list all the storages in all the components in a
current application and project
Syntax will be odo storage list --all
on execution of odo storage list --all componentName it will fail
Fixes #507