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

Use a plugin source to find the central plugin discovery #232

Merged
merged 1 commit into from
Apr 27, 2023

Conversation

marckhouzam
Copy link
Contributor

@marckhouzam marckhouzam commented Apr 25, 2023

What this PR does / why we need it

This PR removes the use of TANZU_CLI_PRE_RELEASE_REPO_IMAGE which was a temporary approach.

Instead, the central discovery is automatically created in the config file as a "discoverySource" and "tanzu plugin source update" can be used to override this default value.

This commit also updates the "tanzu plugin source" family of commands.
With the central discovery feature enabled:

  1. "tanzu plugin source add" is removed
  2. "tanzu plugin source update" no longer has a "--type/-t" flag
  3. "tanzu plugin source init" is added

Please see the additional notes at the end of this PR's description to see how "tanzu plugin source delete" is handled.

Which issue(s) this PR fixes

Fixes # N/A

Describe testing done for PR

I confirm that make e2e-context-tmc-test passes locally.

# Cleanup
$ rm ~/.cache/tanzu/plugin_inventory
$ rm ~/.config/tanzu/config*
$ unset TANZU_CLI_PRE_RELEASE_REPO_IMAGE
$ tz ceip-participation set true

# Notice the default central discovery is automatically set
$ tz plugin source list
  NAME     IMAGE
  default  projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest
$ tz plugin search
[i] Reading plugin inventory for "projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest", this will take a few seconds.
  NAME     DESCRIPTION             TARGET  LATEST
  builder  Build Tanzu components  global  v0.90.0-alpha.0
  test     Test the CLI            global  v0.90.0-alpha.0

# Update the default plugin source (meant for air-gapped)
$ tz plugin source update default -u localhost:9876/tanzu-cli/plugins/central:small
[ok] updated discovery source default
$ tz config set env.TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_VERIFICATION_SKIP_LIST localhost:9876/tanzu-cli/plugins/central:small
$ tz plugin source list
  NAME     IMAGE
  default  localhost:9876/tanzu-cli/plugins/central:small
$ tz plugin search
[i] Reading plugin inventory for "localhost:9876/tanzu-cli/plugins/central:small", this will take a few seconds.
[!] Skipping the plugins discovery image signature verification for "localhost:9876/tanzu-cli/plugins/central:small"

  NAME                DESCRIPTION                  TARGET           LATEST
  isolated-cluster    Desc for isolated-cluster    global           v9.9.9
  pinniped-auth       Desc for pinniped-auth       global           v9.9.9
  cluster             Desc for cluster             kubernetes       v9.9.9
[...]

# Reset the default plugin source
$ tz plugin source init
[ok] successfully initialized discovery source
$ tz plugin source list
  NAME     IMAGE
  default  projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

# Remove the config files and see that the default source is re-created automatically
$ rm ~/.config/tanzu/config*
$ tz ceip-participation set true
$ tz plugin source list
  NAME     IMAGE
  default  projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

Now lets test the special "plugin source delete" handling which allows to remove the default central discovery:

$ tz plugin source delete default
[ok] deleted discovery source default

# Notice that the plugin source remains deleted (not added back automatically)
$ tz plugin source list
  NAME  IMAGE
$ tz plugin search
  NAME  DESCRIPTION  TARGET  LATEST

# Notice that we can easily restore the default central discovery
$ tz plugin source init
[ok] successfully initialized discovery source
$ tz plugin source list
  NAME     IMAGE
  default  projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

Release note

The temporary `TANZU_CLI_PRE_RELEASE_REPO_IMAGE` has been removed.  Instead, the use of `tanzu plugin source update` can be used to override the default central discovery location.

Additional information

Special notes for your reviewer

There is an important behaviour I'd like to get opinions on:
I decided to keep tanzu plugin source delete. The idea is that I've always been a bit uncomfortable with the fact there was no way to remove the default discovery. By keeping the tanzu plugin source delete command it allows us to remove the default central repo and not have the CLI add it back automatically; instead, if a user does a tanzu plugin source delete default they can add back the central repo by doing tanzu plugin source init.

Note that on first use or removal of the config file, the CLI will notice the config file has no top-level entry for discoverySources and will create the default discovery source; but after a tanzu plugin source delete, the CLI will see the discoverySources section exist but is empty, in which case it will not add back the central discovery source.

If this is not desirable, we can easily remove the tanzu plugin source delete command as was originally planned.

@marckhouzam marckhouzam force-pushed the feat/newDicoveryConfig branch 2 times, most recently from 6b2153e to 69bdd95 Compare April 25, 2023 16:32
@marckhouzam marckhouzam force-pushed the feat/newDicoveryConfig branch 4 times, most recently from c8159eb to e341e68 Compare April 26, 2023 03:21
@marckhouzam marckhouzam changed the title TEST Use a plugin source to find the central plugin discovery Apr 26, 2023
@marckhouzam marckhouzam marked this pull request as ready for review April 26, 2023 03:36
@marckhouzam marckhouzam requested a review from a team as a code owner April 26, 2023 03:36
pkg/config/init.go Outdated Show resolved Hide resolved
test/e2e/Makefile Outdated Show resolved Hide resolved
pkg/command/discovery_source.go Show resolved Hide resolved
go.mod Show resolved Hide resolved
pkg/command/discovery_source.go Show resolved Hide resolved
pkg/command/discovery_source.go Show resolved Hide resolved
pkg/command/discovery_source.go Show resolved Hide resolved
pkg/command/discovery_source.go Show resolved Hide resolved
pkg/command/discovery_source.go Show resolved Hide resolved
pkg/config/defaults_test.go Show resolved Hide resolved
// this allows a user to delete the default central discovery and not
// have the CLI add it again. A user can then use "plugin source init"
// to add the default discovery again.
if force || discoverySources == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that if len(discoverySources) == 0 we don't create the default central discovery.

I decided to do that so it is possible to run the CLI with no default central repo.

pkg/command/discovery_source.go Show resolved Hide resolved
test/e2e/Makefile Outdated Show resolved Hide resolved
@marckhouzam marckhouzam force-pushed the feat/newDicoveryConfig branch 3 times, most recently from 11182f1 to 0ee85b5 Compare April 26, 2023 19:35
This commit removes the use of TANZU_CLI_PRE_RELEASE_REPO_IMAGE which
was a temporary approach.

Instead, the central discovery is automatically created in the config
file as a "discoverySource" and "tanzu plugin source update" can be used
to override this default value.

This commit also updates the "tanzu plugin source" family of commands.
With the central discovery feature enabled:
1. "tanzu plugin source add" is removed
2. "tanzu plugin source update" no longer has a "--type/-t" flag
3. "tanzu plugin source init" is added

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
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.

The changes look good to me. Thanks!

@marckhouzam marckhouzam merged commit 9c9bf4c into vmware-tanzu:main Apr 27, 2023
@marckhouzam marckhouzam deleted the feat/newDicoveryConfig branch April 27, 2023 00:10
marckhouzam added a commit to marckhouzam/tanzu-cli that referenced this pull request Apr 27, 2023
With PR vmware-tanzu#232 the trusted registries include the configured plugin source.
The default central repo URI is no longer automatically trusted but only
if it is configure as a plugin source (which happens by default).

Therefore, the unit test is superceded by the unit tests of the same
file that verifies the trusted registries for configured plugin source.

Furthermore, the test that this commit removes would fail locally when
the plugin source configured is not the default central repo.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
marckhouzam added a commit that referenced this pull request Apr 27, 2023
With PR #232 the trusted registries include the configured plugin source.
The default central repo URI is no longer automatically trusted but only
if it is configured as a plugin source (which happens by default).

Therefore, this removed unit test is superceded by the unit test of the same
file that verifies the trusted registries for configured plugin sources.

Furthermore, the test that this commit removes would fail locally when
the plugin source configured is not the default central repo.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
vuil pushed a commit that referenced this pull request May 3, 2023
This commit removes the use of TANZU_CLI_PRE_RELEASE_REPO_IMAGE which
was a temporary approach.

Instead, the central discovery is automatically created in the config
file as a "discoverySource" and "tanzu plugin source update" can be used
to override this default value.

This commit also updates the "tanzu plugin source" family of commands.
With the central discovery feature enabled:
1. "tanzu plugin source add" is removed
2. "tanzu plugin source update" no longer has a "--type/-t" flag
3. "tanzu plugin source init" is added

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
vuil pushed a commit that referenced this pull request May 3, 2023
With PR #232 the trusted registries include the configured plugin source.
The default central repo URI is no longer automatically trusted but only
if it is configured as a plugin source (which happens by default).

Therefore, this removed unit test is superceded by the unit test of the same
file that verifies the trusted registries for configured plugin sources.

Furthermore, the test that this commit removes would fail locally when
the plugin source configured is not the default central repo.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants