vmware-tanzu / tanzu-cli

The Tanzu Core CLI project provides the core functionality of the Tanzu CLI. The CLI is based on a plugin architecture where CLI command functionality can be delivered through independently developed plugin binaries
Apache License 2.0
33 stars 21 forks source link

Conditionally enable active context type check for plugin override #753

Closed vuil closed 4 months ago

vuil commented 4 months ago

Unless features.global.plugin-override-on-active-context-type is set to true, and plugin-level mapping is performed unconditionally, possibly overriding some other existing CLI command group.

However, when said flag is set, mapping that would override an existing command is only be allowed if the active context's type matches one of the types that this mapping supports.

What this PR does / why we need it

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

See updated unit tests.

Manual testing:

  # appsv2 has plugin level mapping to tanzu app
  > tz plugin list | grep Appli | grep app
    appsv2        Applications on Kubernetes for TAP (SaaS distribution)  kubernetes       v0.1.0-beta.2-dev-1b714668  installed

  # mapping is in place
  > tz  | grep Appli | grep app
      app                     Applications on Kubernetes for TAP (SaaS distribution)

  # feature flag is not set
  > tanzu config get | grep override
              plugin-override-on-active-context-type: "false"

  # install apps plugin
  > tz plugin install apps
  [i] Installed plugin 'apps:v0.13.0' with target 'kubernetes' (from cache)
  [ok] successfully installed 'apps' plugin

  # both plugins installed
  > tz plugin list | grep Appli | grep app
    apps          Applications on Kubernetes                              kubernetes       v0.13.0                     installed
    appsv2        Applications on Kubernetes for TAP (SaaS distribution)  kubernetes       v0.1.0-beta.2-dev-1b714668  installed

  # mapping still in place
  > tz  | grep Appli | grep app
      app                     Applications on Kubernetes for TAP (SaaS distribution)

  # active context type is tanzu
  > tz context list --current
    NAME                  ISACTIVE  TYPE   PROJECT           SPACE
    tanzu_test_env        true      tanzu  mytanzu-project

  # unset context
  > tz context unset tanzu_test_env
  The context 'tanzu_test_env' of type 'tanzu' has been set as inactive

  # mapping still unconditionally applied...
  > tz  | grep Appli | grep app
      app                     Applications on Kubernetes for TAP (SaaS distribution)
  # despite no matching context type
  > tz context list --current
    NAME  ISACTIVE  TYPE

  # however, when feature flag is set
  > tz config set features.global.plugin-override-on-active-context-type true
  > tanzu config get | grep override
              plugin-override-on-active-context-type: "true"

  # the mapping is suppressed, because active context type is checked
  > tz  | grep Appli | grep app
      apps                    Applications on Kubernetes

  # set a tanzu context as active again
  > tz context use tanzu_test_env
  [i] Successfully activated context 'tanzu_test_env' (Type: tanzu, Project: mytanzu-project (2d59a92e-1694-4123-b89a-809e241e53f6))
  > tz context list --current
    NAME                  ISACTIVE  TYPE   PROJECT           SPACE
    tanzu_test_env        true      tanzu  mytanzu-project

  # now the mapping is reapplied
  > tz  | grep Appli | grep app
      app                     Applications on Kubernetes for TAP (SaaS distribution)

Release note

Unless features.global.plugin-override-on-active-context-type is set to true, and plugin-level mapping is performed unconditionally, possibly overriding some other existing CLI command group. However, when said flag is set, mapping that would override an existing command is only be allowed if the active context's type matches one of the types that this mapping supports.

Additional information

Special notes for your reviewer