Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Implement plugin discovery source CRUD command for context aware CLI#950

Merged
anujc25 merged 2 commits intovmware-tanzu:mainfrom
anujc25:plugin-discovery-commands
Nov 9, 2021
Merged

Implement plugin discovery source CRUD command for context aware CLI#950
anujc25 merged 2 commits intovmware-tanzu:mainfrom
anujc25:plugin-discovery-commands

Conversation

@anujc25
Copy link
Copy Markdown
Contributor

@anujc25 anujc25 commented Oct 21, 2021

What this PR does / why we need it

  • Implements tanzu plugin source add/list/update/delete commands
  • Currently, supported discovery types are oci and local
  • Add newly added noun, flag to cli-wordlist.yml file

Which issue(s) this PR fixes

Fixes #947

Describe testing done for PR

  • Manual testing by adding/listing/updating/deleting discovery source

Release note

Implement CLIPlugin discovery source CRUD commands for managing discovery sources

PR Checklist

  • Squash the commits into one or a small number of logical commits
  • Use good commit messages
  • Ensure PR contains terms all contributors can understand and links all contributors can access

Additional information

Special notes for your reviewer

@anujc25 anujc25 requested review from a team and miclettej as code owners October 21, 2021 23:47
@anujc25 anujc25 changed the title Implement plugin discovery CRUD command Implement plugin discovery CRUD command for context aware CLI Oct 21, 2021
@anujc25 anujc25 force-pushed the plugin-discovery-commands branch 4 times, most recently from cca655a to 59eeab4 Compare October 22, 2021 04:03
@anujc25 anujc25 added area/cli area/plugin kind/feature Categorizes issue or PR as related to a new feature labels Oct 22, 2021
@anujc25 anujc25 force-pushed the plugin-discovery-commands branch from 59eeab4 to 1bda275 Compare October 22, 2021 19:22
@imikushin
Copy link
Copy Markdown
Contributor

Sorry if it's too late, but would source be a better noun than discovery?

Also see my comment: #947 (comment)

Copy link
Copy Markdown
Member

@zjs zjs 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. Left a couple of nit-picky comments.

(Note that this was a pretty cursory review as I ran out of time. If there's anywhere you'd like me to take a more careful look at, just let me know!)

@anujc25 anujc25 changed the title Implement plugin discovery CRUD command for context aware CLI Implement plugin discovery source CRUD command for context aware CLI Nov 2, 2021
@anujc25 anujc25 force-pushed the plugin-discovery-commands branch from 1bda275 to 186f284 Compare November 3, 2021 00:14
@anujc25
Copy link
Copy Markdown
Contributor Author

anujc25 commented Nov 3, 2021

would source be a better noun than discovery?

As discussed in #947, I have updated the noun to source.

@anujc25 anujc25 force-pushed the plugin-discovery-commands branch from 186f284 to fd31bd0 Compare November 3, 2021 06:03
Copy link
Copy Markdown
Contributor

@imikushin imikushin left a comment

Choose a reason for hiding this comment

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

A few comments to make code simpler and more testable.

Also, please add unit tests for all new functionality.

Comment on lines +172 to +156
discoverySources := cfg.ClientOptions.CLI.DiscoverySources

newDiscoverySources := []configv1alpha1.PluginDiscovery{}
found := false
for _, ds := range discoverySources {
if checkDiscoveryName(ds, discoveryName) {
found = true
ds = configv1alpha1.PluginDiscovery{}
switch strings.ToLower(discoverySourceType) {
case common.DiscoveryTypeLocal:
ds.Local = createLocalDiscoverySource(discoveryName, uri)
case common.DiscoveryTypeOCI:
ds.OCI = createOCIDiscoverySource(discoveryName, uri)
default:
return errors.Errorf("discovery source type '%s' is not yet supported", discoverySourceType)
}
}
newDiscoverySources = append(newDiscoverySources, ds)
}
if !found {
return discoveryNoExistError
}

cfg.ClientOptions.CLI.DiscoverySources = newDiscoverySources
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The whole block should be a separate function (that is easily unit testable):

newDiscoverySources, err := updateDiscoverySources(cfg.ClientOptions.CLI.DiscoverySources, discoveryName, discoverySourceType, uri)
if err != nil {
	return err
}
cfg.ClientOptions.CLI.DiscoverySources = newDiscoverySources

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one hasn't been addressed :(

Please refactor consistent with deleteDiscoverySource() and addDiscoverySource()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done. Refactored and added unit tests

@anujc25 anujc25 force-pushed the plugin-discovery-commands branch 5 times, most recently from fac141c to b2fe37f Compare November 6, 2021 07:25
@anujc25 anujc25 added the ok-to-merge PRs should be labelled with this before merging label Nov 6, 2021
Copy link
Copy Markdown
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.

Lgtm. Just a nit on the doc.

Copy link
Copy Markdown
Contributor

@imikushin imikushin left a comment

Choose a reason for hiding this comment

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

A couple comments still un-addressed. Otherwise looks good!

@anujc25 anujc25 force-pushed the plugin-discovery-commands branch from b2fe37f to 444ae70 Compare November 9, 2021 00:23
Anuj Chaudhari added 2 commits November 8, 2021 17:26
- Implements `tanzu plugin source add/list/update/delete` commands
- Currently, supported discovery types are oci and local
- Add newly added noun, flag to cli-wordlist.yml file

Signed-off-by: Anuj Chaudhari <anujc@vmware.com>
@anujc25 anujc25 force-pushed the plugin-discovery-commands branch from 444ae70 to 87abe10 Compare November 9, 2021 01:26
@anujc25 anujc25 merged commit c355f79 into vmware-tanzu:main Nov 9, 2021
yharish991 pushed a commit to yharish991/tanzu-framework that referenced this pull request Nov 9, 2021
…mware-tanzu#950)

* Implement plugin discovery source CRUD command

- Implements `tanzu plugin source add/list/update/delete` commands
- Currently, supported discovery types are oci and local
- Add newly added noun, flag to cli-wordlist.yml file

* Update cobra docs for the commands
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/cli area/plugin cla-not-required kind/feature Categorizes issue or PR as related to a new feature ok-to-merge PRs should be labelled with this before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement discovery CRUD commands to configure discovery source to Tanzu Config file

6 participants