Skip to content
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

Merged
merged 2 commits into from
Aug 23, 2018

Conversation

piyush-garg
Copy link
Contributor

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

@piyush-garg piyush-garg force-pushed the iss_507 branch 3 times, most recently from 5b6f979 to 1ad4999 Compare July 8, 2018 05:42
cmd/storage.go Outdated
fmt.Println("Invalid arguments. component name is not needed")
os.Exit(1)
}
componentList := getComponentList(client, applicationName, projectName)
Copy link
Contributor

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 {
Copy link
Contributor

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

@mik-dass
Copy link
Contributor

The output looks like

The component 'nodejs' has the following storage attached -
NAME          SIZE     PATH
backend-1     100M     /data-1

No unmounted storage exists to mount to 'nodejs' 
The component 'wildfly' has the following storage attached -
NAME        SIZE     PATH
backend     100M     /data

No unmounted storage exists to mount to 'wildfly' 

The No unmounted storage exists part appears twice and I think it's unnecessary to display it more than once, so I guess we can have a different design layout for the --all case

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
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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("")
Copy link
Member

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")
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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

@kadel
Copy link
Member

kadel commented Jul 24, 2018

Storage that is not mounted should be grouped together at the end of the output.
How about something like this for output?

The component 'nodejs' has no storage attached.

The component 'wildfly' has the following storage attached:
NAME             SIZE     PATH
wildfly-alfa     1G       /data

The component 'php' has the following storage attached:
NAME             SIZE     PATH
php-asdf         1G       /www

Storage that is not mounted to any component:
NAME             SIZE
wildfly-vxgn     1G
mydata           1G

@piyush-garg piyush-garg force-pushed the iss_507 branch 5 times, most recently from b2a6a34 to edd9d4e Compare July 27, 2018 22:28
Copy link
Contributor

@surajnarwade surajnarwade left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put : instead of -

@piyush-garg
Copy link
Contributor Author

@surajnarwade Fixed

Copy link
Contributor

@mik-dass mik-dass left a 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)
Copy link
Contributor

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

@piyush-garg
Copy link
Contributor Author

@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 == "" {
Copy link
Contributor

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

mik-dass
mik-dass previously approved these changes Jul 30, 2018
Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@piyush-garg
Copy link
Contributor Author

@ashetty1 Does E2E test change look good to you?

@ashetty1
Copy link
Contributor

ashetty1 commented Aug 1, 2018

@piyush1594 yes, tests LGTM

@kadel
Copy link
Member

kadel commented Aug 1, 2018

Wouldn't it be better and easier to modify storage.List to list just mounted storage in the given component, and create new storage.ListUnmounte function that will list all unmounted volumes in the given application?

@kadel
Copy link
Member

kadel commented Aug 9, 2018

@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 😇 )

@piyush-garg
Copy link
Contributor Author

@kadel @mik-dass @cdrage Will update the PR in a day or two. Is it fine with you?

@kadel
Copy link
Member

kadel commented Aug 10, 2018

@kadel @mik-dass @cdrage Will update the PR in a day or two. Is it fine with you?

you don't really have to, If others are OK with that we can merge it, and improve it in separate PR.

@kadel kadel added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 13, 2018
@piyush-garg piyush-garg force-pushed the iss_507 branch 2 times, most recently from d9ac235 to 2028bdb Compare August 13, 2018 15:16
@piyush-garg
Copy link
Contributor Author

@cdrage Thanks a lot for the review. Changes addressed

@piyush-garg piyush-garg force-pushed the iss_507 branch 4 times, most recently from be2f7c3 to e98e5ab Compare August 16, 2018 13:47
@@ -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 {
Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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

@piyush-garg
Copy link
Contributor Author

@cdrage Can you please take a look again? TIA

Copy link
Contributor

@surajnarwade surajnarwade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@kadel kadel requested review from mik-dass and cdrage August 20, 2018 08:52
cmd/cmdutils.go Outdated

//iterating over all the components in the given aplication and project
for _, component := range componentList {
componentName := component.Name
Copy link
Contributor

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
Copy link
Contributor

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")
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@mik-dass
Copy link
Contributor

@cdrage Can we merge this?

@cdrage
Copy link
Member

cdrage commented Aug 23, 2018

Yeah, this LGTM. Thanks for addressing my comments!

@cdrage cdrage merged commit 7965a83 into redhat-developer:master Aug 23, 2018
@piyush-garg
Copy link
Contributor Author

Thanks @cdrage @mik-dass @kadel @surajnarwade

@surajnarwade surajnarwade mentioned this pull request Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants