From 25879f69448b35de7118172a30c6844f247b545c Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 12 Oct 2023 16:38:05 -0400 Subject: [PATCH] Add arch type to the output of the plugin info cmd On Darwin ARM64 machines, the CLI can install plugins using either an ARM64 or an AMD64 build, depending of plugin binary availability. Showing the arch type in the output of "tanzu info" will help in troubleshooting. Signed-off-by: Marc Khouzam --- plugin/info.go | 7 +++++++ plugin/info_test.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/plugin/info.go b/plugin/info.go index 032bd2aec..441514daa 100644 --- a/plugin/info.go +++ b/plugin/info.go @@ -6,6 +6,7 @@ package plugin import ( "encoding/json" "fmt" + "runtime" "runtime/debug" "github.com/spf13/cobra" @@ -24,6 +25,11 @@ type pluginInfo struct { // PluginRuntimeVersion of the plugin. Must be a valid semantic version https://semver.org/ // This version specifies the version of Plugin Runtime that was used to build the plugin PluginRuntimeVersion string `json:"pluginRuntimeVersion" yaml:"pluginRuntimeVersion"` + + // The machine architecture of the plugin binary. + // This information can prove useful on Darwin (MacOS) ARM64 machine + // which can also execute AMD64 binaries in the Rosetta emulator. + BinaryArch string `json:"binaryArch" yaml:"binaryArch"` } func newInfoCmd(desc *PluginDescriptor) *cobra.Command { @@ -35,6 +41,7 @@ func newInfoCmd(desc *PluginDescriptor) *cobra.Command { pi := pluginInfo{ PluginDescriptor: *desc, PluginRuntimeVersion: getPluginRuntimeVersion(), + BinaryArch: runtime.GOARCH, } b, err := json.Marshal(pi) if err != nil { diff --git a/plugin/info_test.go b/plugin/info_test.go index 5299e0f45..9614f545f 100644 --- a/plugin/info_test.go +++ b/plugin/info_test.go @@ -6,6 +6,7 @@ package plugin import ( "encoding/json" "os" + "runtime" "testing" "github.com/stretchr/testify/assert" @@ -51,6 +52,7 @@ func TestInfo(t *testing.T) { expectedInfo := pluginInfo{ PluginDescriptor: descriptor, + BinaryArch: runtime.GOARCH, } gotInfo := &pluginInfo{} @@ -65,5 +67,6 @@ func TestInfo(t *testing.T) { assert.Equal(expectedInfo.BuildSHA, gotInfo.BuildSHA) assert.Equal(expectedInfo.DocURL, gotInfo.DocURL) assert.Equal(expectedInfo.Hidden, gotInfo.Hidden) + assert.Equal(expectedInfo.BinaryArch, gotInfo.BinaryArch) assert.Empty(gotInfo.PluginRuntimeVersion, "Should be empty since unit tests doesn't have the self (tanzu-plugin-runtime) module dependency") }