tanzu-cli icon indicating copy to clipboard operation
tanzu-cli copied to clipboard

Plugin "Hidden" internal data structure interface is confusing

Open marckhouzam opened this issue 1 year ago • 0 comments

Bug description

The PluginInventoryEntry structure has a Hidden field as can be seen towards the end of: https://github.com/vmware-tanzu/tanzu-cli/blob/f4963fff115c9e942cf55fc271e61cbb5c65c904/pkg/plugininventory/plugin_inventory.go#L52-L72

A PluginInventoryEntry represents an entire plugin including all its versions. On the other hand the concept of a "hidden" plugin applies to individual versions of a plugin and not to the entire plugin. For example, if a team has published plugin1 versions 1.0.0 and 1.1.0 (not hidden) and then has a new version v2.0.0 they want to test, they will publish only v2.0.0 as hidden and not the entire plugin.

This is actually all working because the previously mentioned Hidden field is not really used; instead, we handle "hidden" plugins through appropriate DB queries as seen here: https://github.com/vmware-tanzu/tanzu-cli/blob/f4963fff115c9e942cf55fc271e61cbb5c65c904/pkg/plugininventory/sqlite_inventory.go#L193-L196

I find that having a Hidden field at the plugin level in the PluginInventoryEntry structure is confusing and can lead to errors in future development.

Note that the Hidden field is actually used when writing plugin entries as can be seen here: https://github.com/vmware-tanzu/tanzu-cli/blob/f4963fff115c9e942cf55fc271e61cbb5c65c904/pkg/plugininventory/sqlite_inventory.go#L501 This works because we normally insert a single version at a time so we don't need to fill the plugin structure with all versions, but only with the newly published version and then the Hidden field happens to only apply to that version.

I suggest we simply remove it. If we need to actually keep track of which version of a plugin is hidden and which is not after the DB query is completed, then we can add a different Hidden field at the level of a version of a plugin. I suggest we only do this when needed as we re-use existing types for the plugin versions. For publishing a new plugin version, we can adapt the interface to add an hidden argument to the InsertPlugin() function call.

Note that as we introduce versions for plugin groups, we will face a similar situation.

Expected behavior

The plugin data structure properly reflects the reality of information for plugins.

Steps to reproduce the bug / Relevant debug output

N/A

Output of tanzu version

Today's main: f4963fff1

Environment where the bug was observed (cloud, OS, etc)

N/A

marckhouzam avatar May 04 '23 12:05 marckhouzam