-
Notifications
You must be signed in to change notification settings - Fork 274
cli: NS removed from mesh when uninstalling mesh #4555
Conversation
"osm uninstall mesh" removes osm-related labels and annotations from the monitored namespace Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Added error check for removing the namespace within a mesh Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Codecov Report
@@ Coverage Diff @@
## main #4555 +/- ##
==========================================
+ Coverage 68.10% 68.13% +0.02%
==========================================
Files 195 195
Lines 15707 15718 +11
==========================================
+ Hits 10697 10709 +12
+ Misses 4957 4956 -1
Partials 53 53
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Added test for uninstalling osm when the mesh has a namespace added to it Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Added enableMetrics argument in function call Signed-off-by: mudit singh <mudit.singh@india.nec.com>
@snehachhabria @shashankram @jaellio @nojnhuh please suggest, if there are any changes for the PR. |
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.
@mudit-01 Thank you so much for helping with this project.
I left a small comment questioning the need to check whether namespaces is empty.
cmd/cli/uninstall_mesh.go
Outdated
|
||
// Unable to remove namespace in mesh | ||
if err != nil { | ||
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 wonder if it would be helpful to log the reason for the inability to remove namespaces with log.Error().Err(err).Msgf("Error removing namespaces: %+v", namespaces.Items)
OR we could assume that the caller would do that for us based on the err
they get.
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 believe caller one is good.
what do other people suggest?
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.
Can we mark this as resolved @draychev?
Removed one level of indentation Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Can we merge this PR? |
Hey @mudit-01, this PR has some conflicts with the version in |
Thanks @shashankram I will work on resolving asap |
Replaced spaces with tab Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Removed outdated test and checks Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Hi @shashankram need help in resolving the lint error(cyclomatic complexity). How can I remove that currently it's 32 just 2 more than the threshold? |
@@ -171,6 +171,17 @@ func (d *uninstallMeshCmd) run() error { | |||
} | |||
|
|||
if err == nil { | |||
namespaces, _ := selectNamespacesMonitoredByMesh(m.name, d.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.
@mudit-01 Could you add a unit test for the namespace cleanup on mesh uninstall? Thanks!
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.
Sure @jaellio I will do that thanks for the review
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.
@mudit-01 we are pending a updated unit test here.
osm/cmd/cli/uninstall_mesh_test.go
Line 631 in d2c37a6
assert.Equal(len(test.existingNamespaces), len(namespaces.Items)) |
You can check if the OSM related labels/annotations are removed from existing namespaces after uninstallation.
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.
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 see my above comments! Thank you!
As suggested Signed-off-by: mudit singh <mudit.singh@india.nec.com> Co-authored-by: Jackie Elliott <64559656+jaellio@users.noreply.github.com>
* chore(cmd/cli): Reduce cyclomatic complexity of uninstall command (#4825) * chore(cmd/cli): Reduce cyclomatic complexity of uninstall command Separate code into functions to reduce the cyclomatic complexity And adds unit tests to functions created Helps unblock #4555 Signed-off-by: Shalier Xia <shalierxia@microsoft.com> (cherry picked from commit d5d3a25) * Golang errors pkg (#4904) This PR partially resolves #4524 * Removes "github.com/pkg/errors" package from the repo * Wrap errors wherever possible rather than using the string format of the error as part of the message Signed-off-by: Allen Leigh <allenlsy@gmail.com> (cherry picked from commit 8030047) * fix golints and security scan issues (#4915) fix golints and security for: 1. G112 (ReadHeaderTimeout) 2. prometheus client_go version pinned to bad version Signed-off-by: Sean Teeling <seanteeling@microsoft.com> (cherry picked from commit f768f64) * Fix lints by removing superfluous var type from var instantiation (#4917) Remove unnecessary var types during instantiation to fix lints Signed-off-by: Sean Teeling <seanteeling@microsoft.com> (cherry picked from commit 9e9f712) Co-authored-by: Shalier Xia <69616256+shalier@users.noreply.github.com> Co-authored-by: allenlsy <allenlsy@gmail.com> Co-authored-by: steeling <seanteeling@microsoft.com>
Updated message for error Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Updated command for removing lint error Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Removed lint error Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Thanks! @allenlsy for the review :) |
Added test for checking removed label and annotation of removed namespace while uninstalling Signed-off-by: mudit singh <mudit.singh@india.nec.com>
cmd/cli/uninstall_mesh_test.go
Outdated
@@ -268,6 +286,16 @@ func TestUninstallCmd(t *testing.T) { | |||
|
|||
if test.userPromptsYes { | |||
if test.meshExists { | |||
if len(test.nsInMesh) != 0 { |
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.
Optional:
Using too many if...else is not preferred. Since removing these labels and annotation applies to the whole uninstall command, we can make the test case more general.
i.e.
tests := []struct {
...
workloadNamespaces []string
...
}
// when setting up test env
for workloadNs := range test.workloadNamespaces {
// create workload namespace
nsSpec := createNamespaceSpec(workloadNs, test.meshName, true, false, true)
_, err = fakeClientSet.CoreV1().Namespaces().Create(context.TODO(), nsSpec, metav1.CreateOptions{})
assert.Nil(err)
}
// verifying in test case (line 289)
for workloadNs := range test.workloadNamespaces {
// check if labels and annotations are removed for workloadNs, same as your implementation from L290-L298
}
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.
@allenlsy I have implemented the requested change, PTAL
Updated test to be more general Signed-off-by: mudit singh <mudit.singh@india.nec.com>
Thanks!! @jaellio @keithmattix for the review |
"osm uninstall mesh" removes osm-related labels and annotations from the monitored namespace, partially fixes #4444
Signed-off-by: mudit singh mudit.singh@india.nec.com
Description:
Testing done: yes(Manual) below are the screenshots


Affected area:
Please answer the following questions with yes/no.
Does this change contain code from or inspired by another project?
Is this a breaking change?
Has documentation corresponding to this change been updated in the osm-docs repo (if applicable)?