Skip to content

Commit

Permalink
Add arch type to the output of the plugin info cmd
Browse files Browse the repository at this point in the history
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 <plugin> info" will help
in troubleshooting.

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam committed Oct 18, 2023
1 parent 3a45252 commit 25879f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugin/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package plugin
import (
"encoding/json"
"fmt"
"runtime"
"runtime/debug"

"github.com/spf13/cobra"
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions plugin/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package plugin
import (
"encoding/json"
"os"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -51,6 +52,7 @@ func TestInfo(t *testing.T) {

expectedInfo := pluginInfo{
PluginDescriptor: descriptor,
BinaryArch: runtime.GOARCH,
}

gotInfo := &pluginInfo{}
Expand All @@ -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")
}

0 comments on commit 25879f6

Please sign in to comment.