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

Add support for "tanzu plugin delete all --target" #537

Merged

Conversation

marckhouzam
Copy link
Contributor

@marckhouzam marckhouzam commented Oct 11, 2023

What this PR does / why we need it

This commit allows a user to delete all plugins for a specified target.
The commit teaches the CLI to accept the all argument for the tanzu plugin delete command. When the all argument is used however, the --target flag must be used.

Which issue(s) this PR fixes

Fixes # N/A

Describe testing done for PR

# Start with plugins for different targets
$ tz plugin list
Standalone Plugins
  NAME       DESCRIPTION                                                 TARGET  VERSION  STATUS
  telemetry  configure cluster-wide settings for vmware tanzu telemetry  global  v1.1.0   installed

Plugins from Context:  tkg1
  NAME                DESCRIPTION                           TARGET      VERSION  STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.30.1  installed
  feature             Operate on features and featuregates  kubernetes  v0.30.1  installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.30.1  installed

Plugins from Context:  tmc
  NAME                  DESCRIPTION                                                     TARGET           VERSION  STATUS
  account               Account for tmc resources                                       mission-control  v0.1.10  installed
  agentartifacts        helm for tmc resources                                          mission-control  v0.1.9   installed
  aks-cluster           Manage and unmanage tmc aks clusters                            mission-control  v0.2.0   not installed
  apply                 Create/Update a resource with a resource file                   mission-control  v0.3.6   installed
  audit                 Run an audit request on an org                                  mission-control  v0.1.9   installed
  cluster                                                                               mission-control  v0.2.4   installed
  clustergroup          A group of Kubernetes clusters                                  mission-control  v0.1.9   installed
  continuousdelivery    Continuousdelivery for tmc resources                            mission-control  v0.1.9   installed
  data-protection       Data protection for tmc resources                               mission-control  v0.1.9   installed
  ekscluster                                                                            mission-control  v0.1.9   installed
  events                Events for any meaningful user activity or system state change  mission-control  v0.1.9   installed
  helm                  helm for tmc resources                                          mission-control  v0.1.9   installed
  iam                   IAM Policies for tmc resources                                  mission-control  v0.1.9   installed
  inspection            Inspection for tmc resources                                    mission-control  v0.1.9   installed
  integration           Get available integrations and their information from registry  mission-control  v0.1.9   installed
  management-cluster    A TMC registered Management cluster                             mission-control  v0.2.9   installed
  policy                Policy for tmc resources                                        mission-control  v0.1.9   installed
  provider-aks-cluster  Manage and unmanage tmc provider aks clusters                   mission-control  v0.1.10  installed
  provider-eks-cluster                                                                  mission-control  v0.1.9   installed
  secret                secret for tmc resources                                        mission-control  v0.1.9   installed
  setting               Setting plugin for tmc resources                                mission-control  v0.2.7   installed
  tanzupackage          Tanzupackage for tmc resources                                  mission-control  v0.2.8   installed
  workspace             A group of Kubernetes namespaces                                mission-control  v0.1.11  installed

[!] As shown above, some recommended plugins have not been installed or are outdated. To install them please run 'tanzu plugin sync'.

# Check the new help for the 'delete' command
$ tz plugin delete -h
Uninstall the specified plugin or specify 'all' to uninstall all plugins of a target

Usage:
tanzu plugin delete PLUGIN_NAME [flags]

Flags:
  -h, --help            help for delete
  -t, --target string   target of the plugin (kubernetes[k8s]/mission-control[tmc]/global)
  -y, --yes             delete the plugin without asking for confirmation

# Make sure 'all' cannot be used without '--target'
$ tz plugin delete all
[x] : the 'all' argument can only be used with the '--target' flag
$ tz plugin delete all --target ''
[x] : the 'all' argument can only be used with the '--target' flag

# Try to delete a single plugin (like before)
$ tz plugin delete cluster
[x] : unable to uniquely identify plugin 'cluster'. Please specify the target (kubernetes[k8s]/mission-control[tmc]/global) of the plugin using the `--target` flag

# Notice the new printout that specifies which plugin will be deleted.
# It was added because when using `all` it seemed a good thing to
# show the users all the plugins that were being uninstalled.
$ tz plugin delete cluster -t k8s
Deleting plugin 'cluster' for target 'kubernetes'. Are you sure? [y/N]: y
[i] Deleting plugin 'cluster' for target 'kubernetes'
[ok] successfully deleted plugin 'cluster'

# check the "cluster" plugin for the k8s target is no longer installed
$ tz plugin list
Standalone Plugins
  NAME       DESCRIPTION                                                 TARGET  VERSION  STATUS
  telemetry  configure cluster-wide settings for vmware tanzu telemetry  global  v1.1.0   installed

Plugins from Context:  tkg1
  NAME                DESCRIPTION                           TARGET      VERSION  STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.30.1  not installed
  feature             Operate on features and featuregates  kubernetes  v0.30.1  installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.30.1  installed

Plugins from Context:  tmc
  NAME                  DESCRIPTION                                                     TARGET           VERSION  STATUS
  account               Account for tmc resources                                       mission-control  v0.1.10  installed
  agentartifacts        helm for tmc resources                                          mission-control  v0.1.9   installed
  aks-cluster           Manage and unmanage tmc aks clusters                            mission-control  v0.2.0   not installed
  apply                 Create/Update a resource with a resource file                   mission-control  v0.3.6   installed
  audit                 Run an audit request on an org                                  mission-control  v0.1.9   installed
  cluster                                                                               mission-control  v0.2.4   installed
  clustergroup          A group of Kubernetes clusters                                  mission-control  v0.1.9   installed
  continuousdelivery    Continuousdelivery for tmc resources                            mission-control  v0.1.9   installed
  data-protection       Data protection for tmc resources                               mission-control  v0.1.9   installed
  ekscluster                                                                            mission-control  v0.1.9   installed
  events                Events for any meaningful user activity or system state change  mission-control  v0.1.9   installed
  helm                  helm for tmc resources                                          mission-control  v0.1.9   installed
  iam                   IAM Policies for tmc resources                                  mission-control  v0.1.9   installed
  inspection            Inspection for tmc resources                                    mission-control  v0.1.9   installed
  integration           Get available integrations and their information from registry  mission-control  v0.1.9   installed
  management-cluster    A TMC registered Management cluster                             mission-control  v0.2.9   installed
  policy                Policy for tmc resources                                        mission-control  v0.1.9   installed
  provider-aks-cluster  Manage and unmanage tmc provider aks clusters                   mission-control  v0.1.10  installed
  provider-eks-cluster                                                                  mission-control  v0.1.9   installed
  secret                secret for tmc resources                                        mission-control  v0.1.9   installed
  setting               Setting plugin for tmc resources                                mission-control  v0.2.7   installed
  tanzupackage          Tanzupackage for tmc resources                                  mission-control  v0.2.8   installed
  workspace             A group of Kubernetes namespaces                                mission-control  v0.1.11  installed

[!] As shown above, some recommended plugins have not been installed or are outdated. To install them please run 'tanzu plugin sync'.

# Delete all plugins for the k8s target
$ tz plugin delete all -t k8s
All plugins for target 'kubernetes' will be deleted. Are you sure? [y/N]: y
[i] Deleting plugin 'kubernetes-release' for target 'kubernetes'
[i] Deleting plugin 'feature' for target 'kubernetes'
[ok] successfully deleted all plugins of target 'kubernetes'

# Check the list of installed plugins
$ tz plugin list
Standalone Plugins
  NAME       DESCRIPTION                                                 TARGET  VERSION  STATUS
  telemetry  configure cluster-wide settings for vmware tanzu telemetry  global  v1.1.0   installed

Plugins from Context:  tkg1
  NAME                DESCRIPTION                           TARGET      VERSION  STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.30.1  not installed
  feature             Operate on features and featuregates  kubernetes  v0.30.1  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.30.1  not installed

Plugins from Context:  tmc
  NAME                  DESCRIPTION                                                     TARGET           VERSION  STATUS
  account               Account for tmc resources                                       mission-control  v0.1.10  installed
  agentartifacts        helm for tmc resources                                          mission-control  v0.1.9   installed
  aks-cluster           Manage and unmanage tmc aks clusters                            mission-control  v0.2.0   not installed
  apply                 Create/Update a resource with a resource file                   mission-control  v0.3.6   installed
  audit                 Run an audit request on an org                                  mission-control  v0.1.9   installed
  cluster                                                                               mission-control  v0.2.4   installed
  clustergroup          A group of Kubernetes clusters                                  mission-control  v0.1.9   installed
  continuousdelivery    Continuousdelivery for tmc resources                            mission-control  v0.1.9   installed
  data-protection       Data protection for tmc resources                               mission-control  v0.1.9   installed
  ekscluster                                                                            mission-control  v0.1.9   installed
  events                Events for any meaningful user activity or system state change  mission-control  v0.1.9   installed
  helm                  helm for tmc resources                                          mission-control  v0.1.9   installed
  iam                   IAM Policies for tmc resources                                  mission-control  v0.1.9   installed
  inspection            Inspection for tmc resources                                    mission-control  v0.1.9   installed
  integration           Get available integrations and their information from registry  mission-control  v0.1.9   installed
  management-cluster    A TMC registered Management cluster                             mission-control  v0.2.9   installed
  policy                Policy for tmc resources                                        mission-control  v0.1.9   installed
  provider-aks-cluster  Manage and unmanage tmc provider aks clusters                   mission-control  v0.1.10  installed
  provider-eks-cluster                                                                  mission-control  v0.1.9   installed
  secret                secret for tmc resources                                        mission-control  v0.1.9   installed
  setting               Setting plugin for tmc resources                                mission-control  v0.2.7   installed
  tanzupackage          Tanzupackage for tmc resources                                  mission-control  v0.2.8   installed
  workspace             A group of Kubernetes namespaces                                mission-control  v0.1.11  installed

[!] As shown above, some recommended plugins have not been installed or are outdated. To install them please run 'tanzu plugin sync'.

# Delete all plugins for the global target
$ tz plugin delete all -t global
All plugins for target 'global' will be deleted. Are you sure? [y/N]: y
[i] Deleting plugin 'telemetry' for target 'global'
[ok] successfully deleted all plugins of target 'global'

# Delete all plugins for the tmc target
$ tz plugin delete all -t tmc
[i] The tanzu cli essential plugins have not been installed and are being installed now. The install may take a few seconds.

All plugins for target 'mission-control' will be deleted. Are you sure? [y/N]: y
[i] Deleting plugin 'secret' for target 'mission-control'
[i] Deleting plugin 'provider-aks-cluster' for target 'mission-control'
[i] Deleting plugin 'workspace' for target 'mission-control'
[i] Deleting plugin 'account' for target 'mission-control'
[i] Deleting plugin 'agentartifacts' for target 'mission-control'
[i] Deleting plugin 'clustergroup' for target 'mission-control'
[i] Deleting plugin 'helm' for target 'mission-control'
[i] Deleting plugin 'iam' for target 'mission-control'
[i] Deleting plugin 'inspection' for target 'mission-control'
[i] Deleting plugin 'integration' for target 'mission-control'
[i] Deleting plugin 'policy' for target 'mission-control'
[i] Deleting plugin 'audit' for target 'mission-control'
[i] Deleting plugin 'cluster' for target 'mission-control'
[i] Deleting plugin 'continuousdelivery' for target 'mission-control'
[i] Deleting plugin 'events' for target 'mission-control'
[i] Deleting plugin 'provider-eks-cluster' for target 'mission-control'
[i] Deleting plugin 'setting' for target 'mission-control'
[i] Deleting plugin 'tanzupackage' for target 'mission-control'
[i] Deleting plugin 'apply' for target 'mission-control'
[i] Deleting plugin 'data-protection' for target 'mission-control'
[i] Deleting plugin 'ekscluster' for target 'mission-control'
[i] Deleting plugin 'management-cluster' for target 'mission-control'
[ok] successfully deleted all plugins of target 'mission-control'

# Check that only the essential plugin is installed
$ tz plugin list
Standalone Plugins
  NAME       DESCRIPTION                                                 TARGET  VERSION  STATUS
  telemetry  configure cluster-wide settings for vmware tanzu telemetry  global  v1.1.0   installed

Plugins from Context:  tkg1
  NAME                DESCRIPTION                           TARGET      VERSION  STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.30.1  not installed
  feature             Operate on features and featuregates  kubernetes  v0.30.1  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.30.1  not installed

Plugins from Context:  tmc
  NAME                  DESCRIPTION                                                     TARGET           VERSION  STATUS
  account               Account for tmc resources                                       mission-control  v0.1.10  not installed
  agentartifacts        helm for tmc resources                                          mission-control  v0.1.9   not installed
  aks-cluster           Manage and unmanage tmc aks clusters                            mission-control  v0.2.0   not installed
  apply                 Create/Update a resource with a resource file                   mission-control  v0.3.6   not installed
  audit                 Run an audit request on an org                                  mission-control  v0.1.9   not installed
  cluster                                                                               mission-control  v0.2.4   not installed
  clustergroup          A group of Kubernetes clusters                                  mission-control  v0.1.9   not installed
  continuousdelivery    Continuousdelivery for tmc resources                            mission-control  v0.1.9   not installed
  data-protection       Data protection for tmc resources                               mission-control  v0.1.9   not installed
  ekscluster                                                                            mission-control  v0.1.9   not installed
  events                Events for any meaningful user activity or system state change  mission-control  v0.1.9   not installed
  helm                  helm for tmc resources                                          mission-control  v0.1.9   not installed
  iam                   IAM Policies for tmc resources                                  mission-control  v0.1.9   not installed
  inspection            Inspection for tmc resources                                    mission-control  v0.1.9   not installed
  integration           Get available integrations and their information from registry  mission-control  v0.1.9   not installed
  management-cluster    A TMC registered Management cluster                             mission-control  v0.2.9   not installed
  policy                Policy for tmc resources                                        mission-control  v0.1.9   not installed
  provider-aks-cluster  Manage and unmanage tmc provider aks clusters                   mission-control  v0.1.10  not installed
  provider-eks-cluster                                                                  mission-control  v0.1.9   not installed
  secret                secret for tmc resources                                        mission-control  v0.1.9   not installed
  setting               Setting plugin for tmc resources                                mission-control  v0.2.7   not installed
  tanzupackage          Tanzupackage for tmc resources                                  mission-control  v0.2.8   not installed
  workspace             A group of Kubernetes namespaces                                mission-control  v0.1.11  not installed

[!] As shown above, some recommended plugins have not been installed or are outdated. To install them please run 'tanzu plugin sync'.

Shell completion changes:

# Notice the 'all' completion as (always) the first one
$ tz plugin delete <TAB>
all                   -- All plugins for a target. You will need to use the --target flag.
account               -- Target: mission-control for account
aks-cluster           -- Target: mission-control for aks-cluster
apply                 -- Target: mission-control for apply
builder               -- Target: global for builder
cluster               -- Target: mission-control for cluster
continuousdelivery    -- Target: mission-control for continuousdelivery
iam                   -- Target: mission-control for iam
integration           -- Target: mission-control for integration
management-cluster    -- Target: mission-control for management-cluster
policy                -- Target: mission-control for policy
provider-eks-cluster  -- Target: mission-control for provider-eks-cluster
setting               -- Target: mission-control for setting
telemetry             -- Target: global for telemetry
workspace             -- Target: mission-control for workspace

$ tz plugin delete -t global <TAB>
all        -- All plugins of target global
builder    -- Target: global for builder
telemetry  -- Target: global for telemetry

# Automatically complete '--target' when using 'all'...
$ tz plugin delete all <TAB>
$ tz plugin delete all --target

# ... but not if --target is already on the command-line
$ tz plugin delete -t global all <TAB>

Release note

Allow a user to delete all plugins of a single target using `tanzu plugin delete all --target ...`

Additional information

Special notes for your reviewer

The shell completion aspect of the tanzu plugin delete command will need to be adapted depending on which PR gets merged first, this PR or #513 Done

@marckhouzam marckhouzam requested a review from a team as a code owner October 11, 2023 19:00
@marckhouzam marckhouzam force-pushed the feat/deletePluginsByTarget branch 2 times, most recently from 584cfa7 to 2a988fa Compare October 13, 2023 14:07
Copy link
Contributor

@mpanchajanya mpanchajanya 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! nice feature to delete all plugins specific to target

Copy link
Contributor

@vuil vuil 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, and a really nice set of tests!

nit: I find the the autocomplete text for each plugin item a little confusing in the first few viewings, probably because it does not match up with the text for all (which I totally understand is different), with the main difference being that the former mentions target before anything else. Let me think a little more and see if I can propose any alternative

This commit allows a user to delete all plugins for a specified target.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
@marckhouzam
Copy link
Contributor Author

marckhouzam commented Oct 17, 2023

nit: I find the the autocomplete text for each plugin item a little confusing

Yeah, this was not one I am happy with. In #513 I started by using the description of the plugin; but then I thought that a user will familiar with the plugin since it is already installed, so I wondered what would the user want to know when preparing to delete a plugin? And I came up with showing the target, so the user would notice in case they were deleting a plugin for the wrong target.

The actual printout is not very pretty.
Also, most users will not be running two targets at the same time, so I'm not sure how useful that info would be.
I'll also keep thinking about it.

@marckhouzam
Copy link
Contributor Author

Since shell completion descriptions can be changed later (not subject to backwards-compatibility), I will go ahead and merge this and we can see how to improve the completion descriptions as we start using them.

@marckhouzam marckhouzam merged commit 5dbc0d9 into vmware-tanzu:main Oct 18, 2023
6 checks passed
@marckhouzam marckhouzam deleted the feat/deletePluginsByTarget branch October 18, 2023 13:09
@vuil
Copy link
Contributor

vuil commented Oct 18, 2023

nit: I find the the autocomplete text for each plugin item a little confusing

Yeah, this was not one I am happy with. In #513 I started by using the description of the plugin; but then I thought that a user will familiar with the plugin since it is already installed, so I wondered what would the user want to know when preparing to delete a plugin? And I came up with showing the target, so the user would notice in case they were deleting a plugin for the wrong target.

The actual printout is not very pretty. Also, most users will not be running two targets at the same time, so I'm not sure how useful that info would be. I'll also keep thinking about it.

Some suggestions:

  1. put the plugin name before the target name, to be more aligned with the 'all' case.
  2. the Target: bit is useful because there are times when --target is necessary. In that case perhaps specify that fact similar to the 'all' case (as in reference --target) would be more useful.
  3. even better would be to only conditionally show --target when there is a need (but we need to assess value-over-cost here)

chandrareddyp pushed a commit that referenced this pull request Oct 19, 2023
This commit allows a user to delete all plugins for a specified target.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
@marckhouzam marckhouzam added this to the 1.1.0 milestone Oct 20, 2023
@marckhouzam marckhouzam added the docs-impact issues with documentation impact label Oct 24, 2023
mpanchajanya pushed a commit that referenced this pull request Oct 24, 2023
This commit allows a user to delete all plugins for a specified target.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
(cherry picked from commit 5dbc0d9)
mpanchajanya pushed a commit that referenced this pull request Oct 24, 2023
This commit allows a user to delete all plugins for a specified target.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
(cherry picked from commit 5dbc0d9)
mpanchajanya pushed a commit that referenced this pull request Oct 24, 2023
This commit allows a user to delete all plugins for a specified target.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
(cherry picked from commit 5dbc0d9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required docs-impact issues with documentation impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants