-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support cli uninstall #3399
Support cli uninstall #3399
Conversation
Will add the ChangeLog and DCO once I am done with my changes. |
I've re-used parts from
The uninstallation deletes resource in the reverse order of their installation. |
eaac135
to
827bad0
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.
Thank you for your contribution, I like the idea.
However, the "velero install" command is going to be deprecated, so I'm not sure is the uninstall command should be added.
@jenting I think we'll take this as it's not that major. @vadasambar This code looks good, but it could be simplified. Take a look at https://velero.io/docs/v1.5/uninstalling/ |
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.
@vadasambar A few changes that need to be made, but I think they're fairly simple.
pkg/cmd/cli/uninstall/uninstall.go
Outdated
@@ -0,0 +1,117 @@ | |||
/* | |||
Copyright 2020 the Velero contributors. |
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 leave out the year now
pkg/cmd/cli/uninstall/uninstall.go
Outdated
return err | ||
} | ||
|
||
crb := install.ClusterRoleBinding(veleroNs) |
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.
Everything above this line is unnecessary, as the namespaced resources will be deleted with the namespace.
Also, we need to add the CustomResourceDefinitions. You can select them similarly to this
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.
@nrb , makes sense. I am using an existing helper function to get all the CRDs
velero/pkg/cmd/cli/uninstall/uninstall.go
Line 36 in 827bad0
resources := install.AllCRDs() |
Do you think using labels would be a better approach?
PS: Actually, using labels sounds like a better approach. If we want to delete an older velero install with a newer velero cli and there's a skew in the number of CRDs between the old and the new install, we might face issues with the helper function but label based approach would still work.
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, the AllCRDs
function was really meant to be used on installation only, not necessarily re-used as a selector.
Like you said, version skew could make this inaccurate.
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. Will make the change then.
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 take a look at the VeleroUninstall in https://github.com/vmware-tanzu/velero/blob/main/test/e2e/velero_utils.go
We can expand on this as necessary, but it is pretty much a straight port of the existing hand uninstall process.
When "velero uninstall" is available in the CLI, the plan is to call that from the test code.
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.
@dsu-igeek , I think we can port the uninstall code directly for the uninstall command.
When "velero uninstall" is available in the CLI, the plan is to call that from the test code.
Is this so that we could test the cli or is it okay to directly call the uninstall function? Asking this because I see we are doing the latter for VeleroInstall
in test/e2e/velero_utils.go
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 should eventually call the CLI both for install and uninstall. That way we can test the CLI on those paths as part of the testing.
- init fn to uninstall velero - abstract dynamic client creation to a separate fn - creates a separate client per unstructured resource - add delete client for CRDs - export appendUnstructured - add uninstall command to main cmd - export `podTemplateOption` - uninstall resources in the reverse order of installation - fallback to `velero` if no ns is provided during uninstall - skip deletion if the resource doesn't exist - handle resource not found error - match log formatting with cli install logs - add Delete fn to fake client - fix import order - add changelog - add comment doc for CreateClient fn Signed-off-by: Suraj Banakar <suraj@infracloud.io>
- move helper functions out of test suite - this is to prevent cyclic imports - move uninstall helpers to uninstall cmd - call them from test suite - revert export of variables/fns from install code - because not required anymore Signed-off-by: Suraj Banakar <suraj@infracloud.io>
827bad0
to
a796590
Compare
Signed-off-by: Suraj Banakar <suraj@infracloud.io>
Made most of the requested changes. @dsu-igeek, I have ported uninstall code from the test suite. Can you please take a look at the code whenever you find time? |
Please 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.
Looks good, can you change VeleroUninstall to call uninstall.Uninstall. Then we can change it to call the CLI later. Thanks!
@@ -342,7 +344,7 @@ func RunEnableAPIGroupVersionsTests(ctx context.Context, resource, group string, | |||
|
|||
// Uninstall Velero | |||
if installVelero { | |||
err = VeleroUninstall(ctx, client, extensionsClient, veleroNamespace) | |||
err = uninstall.Uninstall(ctx, client, extensionsClient, veleroNamespace) |
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.
Same here, let's continue to call VeleroUninstall.
@@ -277,38 +271,6 @@ func VeleroInstall(ctx context.Context, veleroImage string, veleroNamespace stri | |||
return nil | |||
} | |||
|
|||
func VeleroUninstall(ctx context.Context, client *kubernetes.Clientset, extensionsClient *apiextensionsclient.Clientset, |
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.
Let's change VeleroUninstall to call uninstall.Uninstall for the moment and later we can have it run through the CLI.
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.
@dsu-igeek , not sure if this is the right place to ask this but I can take a look at using cli in Install and Uninstall in the test suite since I have some context on what needs to be done, might as well make that change as well. Do we have any ticket for this or should I create a new one?
- as a wrapper - fix import related errors in test suite Signed-off-by: Suraj Banakar <suraj@infracloud.io>
* Add uninstall cmd - init fn to uninstall velero - abstract dynamic client creation to a separate fn - creates a separate client per unstructured resource - add delete client for CRDs - export appendUnstructured - add uninstall command to main cmd - export `podTemplateOption` - uninstall resources in the reverse order of installation - fallback to `velero` if no ns is provided during uninstall - skip deletion if the resource doesn't exist - handle resource not found error - match log formatting with cli install logs - add Delete fn to fake client - fix import order - add changelog - add comment doc for CreateClient fn Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Re-use uninstall code from test suite - move helper functions out of test suite - this is to prevent cyclic imports - move uninstall helpers to uninstall cmd - call them from test suite - revert export of variables/fns from install code - because not required anymore Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Revert `PodTemplateOption` -> `podTemplateOption` Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Use uninstall helper under VeleroUninstall - as a wrapper - fix import related errors in test suite Signed-off-by: Suraj Banakar <suraj@infracloud.io>
* Add uninstall cmd - init fn to uninstall velero - abstract dynamic client creation to a separate fn - creates a separate client per unstructured resource - add delete client for CRDs - export appendUnstructured - add uninstall command to main cmd - export `podTemplateOption` - uninstall resources in the reverse order of installation - fallback to `velero` if no ns is provided during uninstall - skip deletion if the resource doesn't exist - handle resource not found error - match log formatting with cli install logs - add Delete fn to fake client - fix import order - add changelog - add comment doc for CreateClient fn Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Re-use uninstall code from test suite - move helper functions out of test suite - this is to prevent cyclic imports - move uninstall helpers to uninstall cmd - call them from test suite - revert export of variables/fns from install code - because not required anymore Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Revert `PodTemplateOption` -> `podTemplateOption` Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Use uninstall helper under VeleroUninstall - as a wrapper - fix import related errors in test suite Signed-off-by: Suraj Banakar <suraj@infracloud.io>
* Add uninstall cmd - init fn to uninstall velero - abstract dynamic client creation to a separate fn - creates a separate client per unstructured resource - add delete client for CRDs - export appendUnstructured - add uninstall command to main cmd - export `podTemplateOption` - uninstall resources in the reverse order of installation - fallback to `velero` if no ns is provided during uninstall - skip deletion if the resource doesn't exist - handle resource not found error - match log formatting with cli install logs - add Delete fn to fake client - fix import order - add changelog - add comment doc for CreateClient fn Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Re-use uninstall code from test suite - move helper functions out of test suite - this is to prevent cyclic imports - move uninstall helpers to uninstall cmd - call them from test suite - revert export of variables/fns from install code - because not required anymore Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Revert `PodTemplateOption` -> `podTemplateOption` Signed-off-by: Suraj Banakar <suraj@infracloud.io> * Use uninstall helper under VeleroUninstall - as a wrapper - fix import related errors in test suite Signed-off-by: Suraj Banakar <suraj@infracloud.io>
Attempts to fix #3291.