Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

refactor(cmd/cli): update uninstall cmd #4664

Merged
merged 3 commits into from
May 9, 2022

Conversation

shalier
Copy link
Contributor

@shalier shalier commented Apr 19, 2022

Description:
Updates uninstall mesh command so that user is prompted on whether they want to uninstall an existing mesh. Also, adds a warning for delete-cluster-wide-resources if there are remaining meshes in the cluster, before deleting cluster resources. Resolves #4613

Signed-off-by: Shalier Xia [email protected]

Testing done:
Uninstall mesh now prompts with existing mesh:
prompts_existing_mesh
Can also uninstall specific mesh with mesh-name flag:
specify_mesh_with_mesh_name
Informs when mesh doesn't exist (including when trying to force uninstall):
doesntExist_plus_force_flag
delete-namespace flag:
delete_namespace_flag
delete-cluster-wide-resources flag:
delete_cluster_wide_resources
warning when deleting cluster resources and there are still meshes in the cluster (updated):
uninstallCmd_cluster_wide_resources
force flag uninstalls existing mesh [only one mesh in cluster]:
single_mesh_force
force flag uninstalls the default mesh+namespace (osm+osm-system) unless mesh-name and osm-namespace are specified [multiple meshes]:
multi_mesh_force

Affected area:

Functional Area
New Functionality [ ]
CI System [ ]
CLI Tool [ x]

Please answer the following questions with yes/no.

  1. Does this change contain code from or inspired by another project? no

    • Did you notify the maintainers and provide attribution?
  2. Is this a breaking change? no

  3. Has documentation corresponding to this change been updated in the [osm-docs] (https://github.com/openservicemesh/osm-docs) repo (if applicable)?

@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2022

Codecov Report

Merging #4664 (a50e1bc) into main (a8330dc) will increase coverage by 0.00%.
The diff coverage is 72.80%.

@@           Coverage Diff           @@
##             main    #4664   +/-   ##
=======================================
  Coverage   69.34%   69.34%           
=======================================
  Files         219      219           
  Lines       15642    15711   +69     
=======================================
+ Hits        10847    10895   +48     
- Misses       4745     4766   +21     
  Partials       50       50           
Flag Coverage Δ
unittests 69.34% <72.80%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cmd/cli/uninstall_mesh.go 69.27% <72.80%> (+1.27%) ⬆️
pkg/messaging/workqueue.go 89.28% <0.00%> (-10.72%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8330dc...a50e1bc. Read the comment docs.

Comment on lines 167 to 179
_, err = d.client.Run(m.name)
if err != nil && errors.Cause(err) == helmStorage.ErrReleaseNotFound && !d.deleteClusterWideResources && !d.deleteNamespace {
fmt.Fprintf(d.out, "Did not find mesh [%s] in namespace [%s]\n", d.meshName, d.meshNamespace)
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think aligning logic more closely with how it was before is slightly better since then the error is still shown when users pass --delete-cluster-wide-resources or --delete-namespace.

Also, is there a reason why we've only been looking for "not found" errors here? Even with how it was before it looks like if uninstalling failed for any other reason, users would get zero feedback on what that reason was. e.g. I made the following changes to make the post-delete hook fail and print the error we get back from this:

diff --git a/charts/osm/templates/cleanup-hook.yaml b/charts/osm/templates/cleanup-hook.yaml
index 0760004f2..a4005b6e5 100644
--- a/charts/osm/templates/cleanup-hook.yaml
+++ b/charts/osm/templates/cleanup-hook.yaml
@@ -63,6 +63,7 @@ metadata:
     helm.sh/hook: post-delete
     helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
 spec:
+  backoffLimit: 0
   template:
     metadata:
       name: {{ .Release.Name }}-cleanup
@@ -81,6 +82,7 @@ spec:
             - sh
             - -c
             - >
+             exit 1;
              kubectl replace -f /osm-crds;
              kubectl delete --ignore-not-found meshconfig -n '{{ include "osm.namespace" . }}' osm-mesh-config;
              kubectl delete --ignore-not-found secret -n '{{ include "osm.namespace" . }}' {{ .Values.osm.caBundleSecretName }};
diff --git a/cmd/cli/uninstall_mesh.go b/cmd/cli/uninstall_mesh.go
index 2f42a4d1d..48f999131 100644
--- a/cmd/cli/uninstall_mesh.go
+++ b/cmd/cli/uninstall_mesh.go
@@ -171,6 +171,8 @@ func (d *uninstallMeshCmd) run() error {
 			}
 			if err == nil {
 				fmt.Fprintf(d.out, "OSM [mesh name: %s] in namespace [%s] uninstalled\n", m.name, m.namespace)
+			} else {
+				fmt.Fprintf(d.out, "swallowed error: %v\n", err)
 			}
 
 			if d.deleteNamespace {

The only output produced when the mesh is uninstalled is:

% bin/osm uninstall mesh -f
swallowed error: uninstallation completed with 1 error(s): job failed: BackoffLimitExceeded

which indicates there's no actual output at all currently even though it failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to:

if err != nil {
	if errors.Cause(err) == helmStorage.ErrReleaseNotFound {
		fmt.Fprintf(d.out, "No OSM control plane with mesh name [%s] found in namespace [%s]\n", m.name, m.namespace)
	}

	if !d.deleteClusterWideResources && !d.deleteNamespace {
		return err
	}

cmd/cli/uninstall_mesh.go Outdated Show resolved Hide resolved
cmd/cli/uninstall_mesh.go Outdated Show resolved Hide resolved
cmd/cli/uninstall_mesh.go Show resolved Hide resolved
cmd/cli/uninstall_mesh.go Outdated Show resolved Hide resolved
cmd/cli/uninstall_mesh_test.go Outdated Show resolved Hide resolved
cmd/cli/uninstall_mesh_test.go Show resolved Hide resolved
@shalier shalier force-pushed the updateUninstallCmd branch from 24dc218 to b64eb97 Compare April 25, 2022 19:38
@shalier shalier requested a review from nojnhuh April 25, 2022 19:46
if err != nil {
failedDeletions = append(failedDeletions, "Secrets")
if len(meshInfoList) != 0 {
fmt.Fprintf(d.out, "Deleting cluster resources will affect current mesh(es) in cluster:\n")
Copy link
Contributor

@jaellio jaellio May 2, 2022

Choose a reason for hiding this comment

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

Should the user be prompted to confirm deleting the cluster-wide resources if another mesh is present? Should we give them the option to abort unless they have set "force"?

Copy link
Contributor Author

@shalier shalier May 3, 2022

Choose a reason for hiding this comment

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

@jaellio atm, we don't support multiple meshes in the cluster, but if in the future we do choose to support multiple meshes then I think we should

cmd/cli/uninstall_mesh_test.go Outdated Show resolved Hide resolved
Comment on lines 122 to 123
// Searches for the mesh specified by the mesh-name flag if specified
if d.meshName != defaultMeshName {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we wouldn't also want to check that the mesh exists if the flags match the default mesh?

And should there be a difference between not passing --mesh-name at all and passing --mesh-name osm (the default)? This check deals with both the same way.

fmt.Fprintf(d.out, "No OSM control plane with mesh name [%s] found in namespace [%s]\n", d.meshName, d.meshNamespace)
_, err = d.client.Run(m.name)
if err != nil {
if errors.Cause(err) == helmStorage.ErrReleaseNotFound {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this is still silently passing over errors other than "not found" when the --delete-cluster-wide-resources or --delete-namespace flags are passed.

shalier added 2 commits May 6, 2022 14:22
Updates `uninstall mesh` command so that user is prompted on whether they want to
uninstall an existing mesh. Also, adds a warning for `delete-cluster-wide-resources` if there are
remaining meshes in the cluster, before deleting cluster resources.
Resolves openservicemesh#4613

Signed-off-by: Shalier Xia <[email protected]>
…able to uninstall mesh even if delete-cluster-wide-resources or delete-namespace flags are passed

Signed-off-by: Shalier Xia <[email protected]>
@shalier shalier force-pushed the updateUninstallCmd branch from b64eb97 to a50e1bc Compare May 6, 2022 21:22
@shalier shalier requested a review from nojnhuh May 6, 2022 21:23
@@ -542,6 +567,10 @@ func TestUninstallClusterWideResources(t *testing.T) {
Log: func(format string, v ...interface{}) {},
}

fakeClientSet := fake.NewSimpleClientset(existingKubeClientsetObjects...)
_, err = addDeployment(fakeClientSet, "osm-controller-1", testMeshName, testNamespace, osmTestVersion, true)
Expect(err).NotTo(HaveOccurred())
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 stick with any new checks in these tests using testify instead. Then the RegistryFailHandler line above can be removed too.

Signed-off-by: Shalier Xia <[email protected]>
@shalier shalier requested a review from nojnhuh May 6, 2022 22:49
@nojnhuh nojnhuh merged commit 76d177f into openservicemesh:main May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uninstall command should suggest existing mesh to uninstall
4 participants