-
Notifications
You must be signed in to change notification settings - Fork 276
refactor(cmd/cli): update uninstall cmd #4664
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
cmd/cli/uninstall_mesh.go
Outdated
_, 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 | ||
} |
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.
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.
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.
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
}
24dc218
to
b64eb97
Compare
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") |
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.
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"?
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.
@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.go
Outdated
// Searches for the mesh specified by the mesh-name flag if specified | ||
if d.meshName != defaultMeshName { |
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.
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 { |
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.
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.
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]>
b64eb97
to
a50e1bc
Compare
cmd/cli/uninstall_mesh_test.go
Outdated
@@ -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()) |
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 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]>
Description:
Updates
uninstall mesh
command so that user is prompted on whether they want to uninstall an existing mesh. Also, adds a warning fordelete-cluster-wide-resources
if there are remaining meshes in the cluster, before deleting cluster resources. Resolves #4613Signed-off-by: Shalier Xia [email protected]
Testing done:
Uninstall mesh now prompts with existing mesh:
Can also uninstall specific mesh with
mesh-name
flag:Informs when mesh doesn't exist (including when trying to force uninstall):
delete-namespace
flag:delete-cluster-wide-resources
flag:warning when deleting cluster resources and there are still meshes in the cluster (updated):
force
flag uninstalls existing mesh [only one mesh in cluster]:force
flag uninstalls the default mesh+namespace (osm+osm-system) unlessmesh-name
andosm-namespace
are specified [multiple meshes]:Affected area:
Please answer the following questions with yes/no.
Does this change contain code from or inspired by another project? no
Is this a breaking change? no
Has documentation corresponding to this change been updated in the [osm-docs] (https://github.com/openservicemesh/osm-docs) repo (if applicable)?