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

Support cli uninstall #3399

Merged
merged 4 commits into from
Mar 4, 2021
Merged

Conversation

vadasambar
Copy link
Contributor

@vadasambar vadasambar commented Feb 3, 2021

Attempts to fix #3291.

@vadasambar
Copy link
Contributor Author

Will add the ChangeLog and DCO once I am done with my changes.

@vadasambar
Copy link
Contributor Author

I've re-used parts from install package which adds a dependency on the install package. It'd be great if someone could review this approach. Some of the work that still needs to be done

  1. Use the namespace provided in the cmd
  2. Remove hardcoding to velero
  3. Logs to stdout mentioning which resource is being deleted

The uninstallation deletes resource in the reverse order of their installation.

@vadasambar vadasambar force-pushed the support-cli-uninstall branch 2 times, most recently from eaac135 to 827bad0 Compare February 10, 2021 06:44
@vadasambar vadasambar marked this pull request as ready for review February 10, 2021 06:51
Copy link
Contributor

@jenting jenting left a 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.

@nrb
Copy link
Contributor

nrb commented Feb 11, 2021

@jenting I think we'll take this as it's not that major. velero install may be going away, but I like having the the easy command.

@vadasambar This code looks good, but it could be simplified. Take a look at https://velero.io/docs/v1.5/uninstalling/

Copy link
Contributor

@nrb nrb left a 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.

@@ -0,0 +1,117 @@
/*
Copyright 2020 the Velero contributors.
Copy link
Contributor

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

return err
}

crb := install.ClusterRoleBinding(veleroNs)
Copy link
Contributor

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

Copy link
Contributor Author

@vadasambar vadasambar Feb 15, 2021

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

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@vadasambar vadasambar Feb 25, 2021

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

Copy link
Contributor

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.

Suraj Banakar added 2 commits March 2, 2021 12:01
- 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>
Signed-off-by: Suraj Banakar <suraj@infracloud.io>
@vadasambar
Copy link
Contributor Author

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?
Also,
https://github.com/vmware-tanzu/velero/pull/3399/files#diff-3ef9006b53436d6a87171de888d0ead4022b7e30b6fc4f29d30e36a1e24643bbR86

@jenting
Copy link
Contributor

jenting commented Mar 2, 2021

Please run make update

Copy link
Contributor

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

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

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.

Copy link
Contributor Author

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>
@github-actions github-actions bot requested a review from dsu-igeek March 4, 2021 06:49
@dsu-igeek dsu-igeek added this to the v1.6.0 milestone Mar 4, 2021
@dsu-igeek dsu-igeek added the kind/release-blocker Must fix issues for the coming release (milestone) label Mar 4, 2021
@nrb nrb merged commit ff1a31d into vmware-tanzu:main Mar 4, 2021
dharmab pushed a commit to dharmab/velero that referenced this pull request May 25, 2021
* 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>
ywk253100 pushed a commit to ywk253100/velero that referenced this pull request Jun 29, 2021
* 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>
gyaozhou pushed a commit to gyaozhou/velero-read that referenced this pull request May 14, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-changelog has-e2e-tests kind/release-blocker Must fix issues for the coming release (milestone)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support uninstalling velero using velero cli
4 participants