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

Update "plugin list" to show missing context plugins #72

Merged
merged 2 commits into from
Feb 22, 2023

Conversation

marckhouzam
Copy link
Contributor

What this PR does / why we need it

We have agreed that it would be valuable for users if the output of plugin list included any missing context-scope plugins that for some reason where not installed. This PR does this.

The PR adds unit tests for the modifications to plugin list that were done for the Central Repository feature.

Which issue(s) this PR fixes

Part of #31

Describe testing done for PR

$ rm ~/.cache/_tanzu/catalog.yaml
$ rm ~/.config/tanzu/config*
$
$ make build
build darwin-amd64 CLI with version: v0.0.2-dev
mkdir -p bin
cp /Users/kmarc/git/tanzu-cli/artifacts/darwin/amd64/cli/core/v0.0.2-dev/tanzu-cli-darwin_amd64 ./bin/tanzu
$ tz config set features.global.central-repository true

# List when no plugin installed and no context created
$ tz plugin list
Installed Plugins
  NAME  DESCRIPTION  TARGET  VERSION  STATUS

# List when a plugin is installed but no context created
$ tz plugin install management-cluster --target k8s
ℹ  Installing plugin 'management-cluster:v0.28.0' with target 'kubernetes'
✔  successfully installed 'management-cluster' plugin
$ tz plugin list
Installed Plugins
  NAME                DESCRIPTION                               TARGET      VERSION  STATUS
  management-cluster  Kubernetes management cluster operations  kubernetes  v0.28.0  installed

# Create context BUT interrupt the plugin sync mid-way, then list
$ tz context create --name tmc-unstable --endpoint unstable.tmc-dev.cloud.vmware.com --staging

ℹ  If you don't have an API token, visit the VMware Cloud Services console, select your organization, and create an API token with the TMC service roles:
  https://console.cloud.vmware.com/csp/gateway/portal/#/user/tokens

? API Token ****************************************************************

✔  successfully created a TMC context
ℹ  Checking for required plugins...
ℹ  Installing plugin 'data-protection:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'clustergroup:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'secret:v0.0.1' with target 'kubernetes'
ℹ  Installing plugin 'inspection:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'cluster:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'integration:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'audit:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'apply:v0.0.1' with target 'mission-control'
^C
$ tz plugin list
Installed Plugins
  NAME                DESCRIPTION                                                      TARGET           VERSION  STATUS
  management-cluster  Kubernetes management cluster operations                         kubernetes       v0.28.0  installed
  audit               Run an audit request on an organization                          mission-control  v0.0.1   installed
  cluster             A TMC managed Kubernetes cluster                                 mission-control  v0.0.1   installed
  clustergroup        A group of Kubernetes clusters                                   mission-control  v0.0.1   installed
  data-protection     Backup, restore, or migrate cluster data.                        mission-control  v0.0.1   installed
  inspection          Run an inspection on a cluster                                   mission-control  v0.0.1   installed
  integration         Get available integrations and their information from registry.  mission-control  v0.0.1   installed

Missing Plugins from Context:  tmc-unstable
  NAME                DESCRIPTION                                                     TARGET           VERSION  STATUS
  account             Account for tmc resources                                       mission-control  v0.0.1   not installed
  apply               Create/Update a resource with a resource file                   mission-control  v0.0.1   not installed
  continuousdelivery  Continuousdelivery for tmc resources                            mission-control  v0.0.1   not installed
  ekscluster                                                                          mission-control  v0.0.1   not installed
  events              Events for any meaningful user activity or system state change  mission-control  v0.0.1   not installed
  helm                helm for tmc resources                                          mission-control  v0.0.1   not installed
  iam                 IAM Policies for tmc resources                                  mission-control  v0.0.1   not installed
  management-cluster  A TMC registered Management cluster                             mission-control  v0.0.1   not installed
  policy              Policy for tmc resources                                        mission-control  v0.0.1   not installed
  secret              secret for tmc resources                                        mission-control  v0.0.1   not installed
  tanzupackage        Tanzupackage for tmc resources                                  mission-control  v0.0.1   not installed
  workspace           A group of Kubernetes namespaces                                mission-control  v0.0.1   not installed

!  As shown above, some recommended plugins have not been installed. To install them please run 'tanzu plugin sync'.
$

# Notice the warning message at the end of the output

# Create another context and interrupt the plugin sync
$ tz context create --name k3d --kubecontext k3d-k3s-default --kubeconfig /Users/kmarc/.config/k3d/k3s-default/kubeconfig.yaml
✔  successfully created a kubernetes context using the kubeconfig /Users/kmarc/.config/k3d/k3s-default/kubeconfig.yaml
ℹ  Checking for required plugins...
ℹ  Installing plugin 'feature:v0.28.0-dev' with target 'kubernetes'
ℹ  Installing plugin 'kubernetes-release:v0.28.0-dev' with target 'kubernetes'
ℹ  Installing plugin 'cluster:v0.38.0-dev' with target 'kubernetes'
ℹ  Installing plugin 'integration:v0.0.1' with target 'mission-control'
ℹ  Installing plugin 'inspection:v0.0.1' with target 'mission-control'
^C
$ tz plugin list
Installed Plugins
  NAME                DESCRIPTION                                                      TARGET           VERSION  STATUS
  management-cluster  Kubernetes management cluster operations                         kubernetes       v0.28.0  installed
  audit               Run an audit request on an organization                          mission-control  v0.0.1   installed
  cluster             A TMC managed Kubernetes cluster                                 mission-control  v0.0.1   installed
  clustergroup        A group of Kubernetes clusters                                   mission-control  v0.0.1   installed
  data-protection     Backup, restore, or migrate cluster data.                        mission-control  v0.0.1   installed
  inspection          Run an inspection on a cluster                                   mission-control  v0.0.1   installed
  integration         Get available integrations and their information from registry.  mission-control  v0.0.1   installed

Missing Plugins from Context:  k3d
  NAME                DESCRIPTION                           TARGET      VERSION      STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.38.0-dev  not installed
  feature             Operate on features and featuregates  kubernetes  v0.28.0-dev  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.28.0-dev  not installed

Missing Plugins from Context:  tmc-unstable
  NAME                DESCRIPTION                                                     TARGET           VERSION  STATUS
  account             Account for tmc resources                                       mission-control  v0.0.1   not installed
  apply               Create/Update a resource with a resource file                   mission-control  v0.0.1   not installed
  continuousdelivery  Continuousdelivery for tmc resources                            mission-control  v0.0.1   not installed
  ekscluster                                                                          mission-control  v0.0.1   not installed
  events              Events for any meaningful user activity or system state change  mission-control  v0.0.1   not installed
  helm                helm for tmc resources                                          mission-control  v0.0.1   not installed
  iam                 IAM Policies for tmc resources                                  mission-control  v0.0.1   not installed
  management-cluster  A TMC registered Management cluster                             mission-control  v0.0.1   not installed
  policy              Policy for tmc resources                                        mission-control  v0.0.1   not installed
  secret              secret for tmc resources                                        mission-control  v0.0.1   not installed
  tanzupackage        Tanzupackage for tmc resources                                  mission-control  v0.0.1   not installed
  workspace           A group of Kubernetes namespaces                                mission-control  v0.0.1   not installed

!  As shown above, some recommended plugins have not been installed. To install them please run 'tanzu plugin sync'.
$

# Notice the different table output for each context above

# Delete a context plugin and see it appear in the list of missing plugins
$ tz plugin delete audit
Deleting Plugin 'audit'. Are you sure? [y/N]: y
✔  successfully deleted plugin 'audit'
$ tz plugin list
Installed Plugins
  NAME                DESCRIPTION                                                      TARGET           VERSION  STATUS
  management-cluster  Kubernetes management cluster operations                         kubernetes       v0.28.0  installed
  cluster             A TMC managed Kubernetes cluster                                 mission-control  v0.0.1   installed
  clustergroup        A group of Kubernetes clusters                                   mission-control  v0.0.1   installed
  data-protection     Backup, restore, or migrate cluster data.                        mission-control  v0.0.1   installed
  inspection          Run an inspection on a cluster                                   mission-control  v0.0.1   installed
  integration         Get available integrations and their information from registry.  mission-control  v0.0.1   installed

Missing Plugins from Context:  k3d
  NAME                DESCRIPTION                           TARGET      VERSION      STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.38.0-dev  not installed
  feature             Operate on features and featuregates  kubernetes  v0.28.0-dev  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.28.0-dev  not installed

Missing Plugins from Context:  tmc-unstable
  NAME                DESCRIPTION                                                     TARGET           VERSION  STATUS
  account             Account for tmc resources                                       mission-control  v0.0.1   not installed
  apply               Create/Update a resource with a resource file                   mission-control  v0.0.1   not installed
  audit               Run an audit request on an org                                  mission-control  v0.0.1   not installed
  continuousdelivery  Continuousdelivery for tmc resources                            mission-control  v0.0.1   not installed
  ekscluster                                                                          mission-control  v0.0.1   not installed
  events              Events for any meaningful user activity or system state change  mission-control  v0.0.1   not installed
  helm                helm for tmc resources                                          mission-control  v0.0.1   not installed
  iam                 IAM Policies for tmc resources                                  mission-control  v0.0.1   not installed
  management-cluster  A TMC registered Management cluster                             mission-control  v0.0.1   not installed
  policy              Policy for tmc resources                                        mission-control  v0.0.1   not installed
  secret              secret for tmc resources                                        mission-control  v0.0.1   not installed
  tanzupackage        Tanzupackage for tmc resources                                  mission-control  v0.0.1   not installed
  workspace           A group of Kubernetes namespaces                                mission-control  v0.0.1   not installed

!  As shown above, some recommended plugins have not been installed. To install them please run 'tanzu plugin sync'.
$

# Delete a standalone context and notice it is not in any output anymore, as expected
 tz plugin delete management-cluster
Deleting Plugin 'management-cluster'. Are you sure? [y/N]: y
✔  successfully deleted plugin 'management-cluster'
$ tz plugin list
Installed Plugins
  NAME             DESCRIPTION                                                      TARGET           VERSION  STATUS
  cluster          A TMC managed Kubernetes cluster                                 mission-control  v0.0.1   installed
  clustergroup     A group of Kubernetes clusters                                   mission-control  v0.0.1   installed
  data-protection  Backup, restore, or migrate cluster data.                        mission-control  v0.0.1   installed
  inspection       Run an inspection on a cluster                                   mission-control  v0.0.1   installed
  integration      Get available integrations and their information from registry.  mission-control  v0.0.1   installed

Missing Plugins from Context:  k3d
  NAME                DESCRIPTION                           TARGET      VERSION      STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.38.0-dev  not installed
  feature             Operate on features and featuregates  kubernetes  v0.28.0-dev  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.28.0-dev  not installed

Missing Plugins from Context:  tmc-unstable
  NAME                DESCRIPTION                                                     TARGET           VERSION  STATUS
  account             Account for tmc resources                                       mission-control  v0.0.1   not installed
  apply               Create/Update a resource with a resource file                   mission-control  v0.0.1   not installed
  audit               Run an audit request on an org                                  mission-control  v0.0.1   not installed
  continuousdelivery  Continuousdelivery for tmc resources                            mission-control  v0.0.1   not installed
  ekscluster                                                                          mission-control  v0.0.1   not installed
  events              Events for any meaningful user activity or system state change  mission-control  v0.0.1   not installed
  helm                helm for tmc resources                                          mission-control  v0.0.1   not installed
  iam                 IAM Policies for tmc resources                                  mission-control  v0.0.1   not installed
  management-cluster  A TMC registered Management cluster                             mission-control  v0.0.1   not installed
  policy              Policy for tmc resources                                        mission-control  v0.0.1   not installed
  secret              secret for tmc resources                                        mission-control  v0.0.1   not installed
  tanzupackage        Tanzupackage for tmc resources                                  mission-control  v0.0.1   not installed
  workspace           A group of Kubernetes namespaces                                mission-control  v0.0.1   not installed

!  As shown above, some recommended plugins have not been installed. To install them please run 'tanzu plugin sync'.
$

# Delete a context
$ tz context delete tmc-unstable
Deleting the context entry from the config will remove it from the list of tracked contexts. You will need to use `tanzu context create` to re-create this context. Are you sure you want to continue? [y/N]: y
ℹ  Deleting entry for cluster tmc-unstable
$ tz plugin list
Installed Plugins
  NAME             DESCRIPTION                                                      TARGET           VERSION  STATUS
  cluster          A TMC managed Kubernetes cluster                                 mission-control  v0.0.1   installed
  clustergroup     A group of Kubernetes clusters                                   mission-control  v0.0.1   installed
  data-protection  Backup, restore, or migrate cluster data.                        mission-control  v0.0.1   installed
  inspection       Run an inspection on a cluster                                   mission-control  v0.0.1   installed
  integration      Get available integrations and their information from registry.  mission-control  v0.0.1   installed

Missing Plugins from Context:  k3d
  NAME                DESCRIPTION                           TARGET      VERSION      STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.38.0-dev  not installed
  feature             Operate on features and featuregates  kubernetes  v0.28.0-dev  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.28.0-dev  not installed

!  As shown above, some recommended plugins have not been installed. To install them please run 'tanzu plugin sync'.
$

# Delete all context and see the missing ones listed
$ tz plugin clean
✔  successfully cleaned up all plugins
$ tz plugin list
Installed Plugins
  NAME  DESCRIPTION  TARGET  VERSION  STATUS

Missing Plugins from Context:  k3d
  NAME                DESCRIPTION                           TARGET      VERSION      STATUS
  cluster             Kubernetes cluster operations         kubernetes  v0.38.0-dev  not installed
  feature             Operate on features and featuregates  kubernetes  v0.28.0-dev  not installed
  kubernetes-release  Kubernetes release operations         kubernetes  v0.28.0-dev  not installed

!  As shown above, some recommended plugins have not been installed. To install them please run 'tanzu plugin sync'.
$

# Delete second context and see no plugins listed anymore
$ tz context delete k3d
Deleting the context entry from the config will remove it from the list of tracked contexts. You will need to use `tanzu context create` to re-create this context. Are you sure you want to continue? [y/N]: y
ℹ  Deleting entry for cluster k3d
$ tz plugin list
Installed Plugins
  NAME  DESCRIPTION  TARGET  VERSION  STATUS

Release note

The `tanzu plugin list` command now includes the list of any context-scope plugins that are not installed and warns the user that they should run `tanzu plugin sync`.

Special notes for your reviewer

  1. How do you feel about the warning message? It is output on stdout. Should it instead be on stderr? Other such warnings are on stdout for our CLI, so I did the same.
  2. Unit tests were added for the plugin list command with the Central Repo. The coverage for plugin.go increased by 13% to 54%. However, I wasn't able to test the listing of the missing plugins because, as pointed out in previous PRs, the pluginmanager's current implementation does not lend itself to unit tests.
  3. There is one part of the planned plugin list improvement that is still missing, which is the part about showing if an installed plugin was installed from a context. This will be done in a follow-up PR as it need more substantial changes.

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

anujc25 commented Feb 22, 2023

How do you feel about the warning message? It is output on stdout. Should it instead be on stderr? Other such warnings are on stdout for our CLI, so I did the same.

Any warning/error logs like this should be printed to stderr. Currently, the logger that we are using needs some changes to support this. So, for now, this seems reasonable. We can tackle all the logging-related stuff together.

Copy link
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

LGTM.

@marckhouzam marckhouzam merged commit 18ec26c into vmware-tanzu:main Feb 22, 2023
@marckhouzam marckhouzam deleted the feat/centralPluginList branch February 22, 2023 11:23
vuil pushed a commit that referenced this pull request Mar 20, 2023
* Have plugin list show uninstalled context plugins

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
@vuil vuil added the kind/feature Categorizes issue or PR as related to a new feature label Apr 7, 2023
@marckhouzam marckhouzam added this to the v0.90.0 milestone Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required kind/feature Categorizes issue or PR as related to a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants