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
jenting
left a comment
There was a problem hiding this comment.
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.
@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. | |||
pkg/cmd/cli/uninstall/uninstall.go
Outdated
| return err | ||
| } | ||
|
|
||
| crb := install.ClusterRoleBinding(veleroNs) |
There was a problem hiding this comment.
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.
@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
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.
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.
Yeah. Will make the change then.
There was a problem hiding this comment.
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.
@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.
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 |
dsu-igeek
left a comment
There was a problem hiding this comment.
Looks good, can you change VeleroUninstall to call uninstall.Uninstall. Then we can change it to call the CLI later. Thanks!
| // Uninstall Velero | ||
| if installVelero { | ||
| err = VeleroUninstall(ctx, client, extensionsClient, veleroNamespace) | ||
| err = uninstall.Uninstall(ctx, client, extensionsClient, veleroNamespace) |
There was a problem hiding this comment.
Same here, let's continue to call VeleroUninstall.
| return nil | ||
| } | ||
|
|
||
| func VeleroUninstall(ctx context.Context, client *kubernetes.Clientset, extensionsClient *apiextensionsclient.Clientset, |
There was a problem hiding this comment.
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.
@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.