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

Adding 'pluginRuntimeVersion' to PluginDescriptor #3555

Closed
wants to merge 2 commits into from

Conversation

prkalle
Copy link
Contributor

@prkalle prkalle commented Oct 5, 2022

Signed-off-by: Prem Kumar Kalle pkalle@vmware.com

What this PR does / why we need it

This PR adds "PluginRuntimeVersion" to PluginDescriptor. This version would be used by tanzu core CLI to add version validations.

Which issue(s) this PR fixes

Fixes #3547

Describe testing done for PR

❯ tanzu management-cluster info
{"name":"management-cluster","description":"Kubernetes management cluster operations","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","completionType":0,"aliases":["mc","management-clusters"],"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu feature  info
{"name":"feature","description":"Operate on features and featuregates","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu kr info
{"name":"kubernetes-release","description":"Kubernetes release operations","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","completionType":0,"aliases":["kr","kubernetes-releases"],"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu login info
{"name":"login","description":"Login to the platform","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"System","docURL":"","completionType":0,"aliases":["lo","logins"],"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu package info
{"name":"package","description":"Tanzu package management","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu pinniped-auth info
{"name":"pinniped-auth","description":"Pinniped authentication operations (usually not directly invoked)","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","hidden":true,"completionType":0,"aliases":["pa","pinniped-auths"],"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu secret info
{"name":"secret","description":"Tanzu secret management","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

 ❯ tanzu telemetry info
{"name":"telemetry","description":"configure cluster-wide settings for vmware tanzu telemetry","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Run","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu builder info
{"name":"builder","description":"Build Tanzu components","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Admin","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu codegen info
{"name":"codegen","description":"Tanzu code generation tool","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Admin","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

❯ tanzu test info
{"name":"test","description":"Test the CLI","version":"v0.27.0-dev","buildSHA":"74a09a79-dirty","digest":"","group":"Admin","docURL":"","completionType":0,"installationPath":"","discovery":"","scope":"","status":"","discoveredRecommendedVersion":"","pluginRuntimeVersion":"v0.27.0-dev"}

Release note

Include the plugin library version with plugin descriptor to determine library version of the plugin

Additional information

Special notes for your reviewer

Signed-off-by: Prem Kumar Kalle <pkalle@vmware.com>
@codecov
Copy link

codecov bot commented Oct 5, 2022

Codecov Report

Merging #3555 (63e05d5) into main (94a4dfb) will decrease coverage by 0.39%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #3555      +/-   ##
==========================================
- Coverage   45.28%   44.89%   -0.40%     
==========================================
  Files         370      416      +46     
  Lines       39306    39993     +687     
==========================================
+ Hits        17801    17956     +155     
- Misses      19894    20402     +508     
- Partials     1611     1635      +24     
Impacted Files Coverage Δ
cli/runtime/plugin/plugin.go 53.12% <100.00%> (+0.74%) ⬆️
cli/core/pkg/cli/usage.go 62.85% <0.00%> (ø)
tkg/carvelhelpers/registry.go 0.00% <0.00%> (ø)
cmd/cli/plugin/cluster/main.go 0.00% <0.00%> (ø)
...v1/tkr/controllers/source/tkr_source_controller.go
...emplate-resolver/templateresolver/resolver_impl.go
...kg/v2/object-propagation/propagation/reconciler.go
pkg/v1/auth/tkg/kube_config.go
...g/v1/tkr/controllers/label/tkr_label_controller.go
pkg/v2/tkr/util/topology/clusterclass.go
... and 116 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@anujc25
Copy link
Contributor

anujc25 commented Oct 5, 2022

nit: Update filename from cli/runtime/version/zz_bundled_plugin_runtime_version.go to cli/runtime/version/zz_generated_plugin_runtime_version.go?

Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

Thanks @prkalle. That solution works nicely.

Since I wasn't familiar with this approach and before seeing your new PR, I was trying to think of how we could figure out the version of the runtime lib that what used when a plugin was compiled. So I started wondering if Go could tell us. I found the ReadBuildInfo() function of the runtime/debug Go package: https://stackoverflow.com/a/59276408

I think using this package would allow us to avoid any special build steps and simply read the dependency that was used by the plugin directly in the info command.

I think another nice advantage is if a plugin uses a specific commit, or the main branch directly, we would get the specific commit in the version, instead of a generic "vx.y.x-dev"

If we prefer the current solution:

  1. What will be the workflow to set a new version of the cli-runtime lib?
  2. It may require changing .github/workflows/dev_tag_retrieval_pr.yaml for the automatic PR to include modifying the new zz_bundled_plugin_runtime_version.go file.
  3. Maybe also hack/verify-dirty.sh although I am not sure.

@@ -156,6 +156,9 @@ type PluginDescriptor struct {

// PostInstallHook is function to be run post install of a plugin.
PostInstallHook Hook `json:"-" yaml:"-"`

// PluginRuntimeVersion of the plugin. Must be a valid semantic version https://semver.org/
PluginRuntimeVersion string `json:"pluginRuntimeVersion" yaml:"pluginRuntimeVersion"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it useful to have this field in the PluginDescriptor?
I'm still getting familiar with the use of the PluginDescriptor, but the way I see it at the moment, is that it is used by a plugin to specify its "properties". This makes me hesitant to add a field that the plugin should not set itself.

In this PR, I gather that the reason we have this new field is that it will get printed by the info command. Maybe we can instead change the info command to print it? We may need to manipulate the json though.

But maybe I shouldn't worry about adding fields in the PluginDescriptor?

Copy link
Contributor Author

@prkalle prkalle Oct 5, 2022

Choose a reason for hiding this comment

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

The reason for adding this field in the PluginDescriptor is beacuse tanzu cli can get the properties of a plugin while invoking the plugin and can impose the compatibility conditions (ex: cli vX.Y.Z doesn't support the plugins created with plugin runtime version vA.B.C. )

Signed-off-by: Prem Kumar Kalle <pkalle@vmware.com>
@prkalle
Copy link
Contributor Author

prkalle commented Oct 10, 2022

I found the ReadBuildInfo() function of the runtime/debug Go package: https://stackoverflow.com/a/59276408

Thank you @marckhouzam for the information(I was not aware of it before). It is good solution and I think we can use this approach once the cli/runtime moves to different repository because, as we are using a replace in go.mod of plugins(eg: cluster/management-cluster etc..) the plugin verison is showing as "v0.0.0-00010101000000-000000000000".

since we are going with the current approach , I did fixed .github/workflows/dev_tag_retrieval_pr.yam and hack/verify-dirty.sh files as mentioned in your comments.

// All the variables are set during build time
// Note: Please !!DO NOT!!! change the name or remove this variable
var (
Version string = "v0.27.0-dev"
Copy link
Contributor

Choose a reason for hiding this comment

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

this should now be "v0.28.0-dev" I think

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to catch this thing as part of CI? I see we are ignoring this file as part of verify-dirty.sh, if we do not skip this file, will it create any issue?

@anujc25
Copy link
Contributor

anujc25 commented Oct 13, 2022

Closing this as requested changes are done as part of another PR: #3641

@anujc25 anujc25 closed this Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include the plugin library version with plugin descriptor to determine library version of the plugin
4 participants