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

Commit

Permalink
fix(cli): do not throw error for osm version when no control plane (#…
Browse files Browse the repository at this point in the history
…4433) (#4457)

If a control plane is not installed in the specified namespace do
not throw an error for `osm version`. Currently, the command
returns an error in this scenario.

Signed-off-by: jaellio <[email protected]>
  • Loading branch information
jaellio authored Jan 18, 2022
1 parent c764eed commit 8c87b8a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
8 changes: 6 additions & 2 deletions cmd/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (v *versionCmd) getMeshVersion() (*remoteVersionInfo, error) {
return nil, err
}
if len(controllerPods.Items) == 0 {
return nil, errors.Errorf("No mesh found in namespace [%s]", v.namespace)
return &remoteVersionInfo{}, nil
}

controllerPod := controllerPods.Items[0]
Expand Down Expand Up @@ -142,6 +142,10 @@ func (r *remoteVersion) proxyGetMeshVersion(pod string, namespace string, client
func (v *versionCmd) outputVersionInfo(versionInfo versionInfo) {
fmt.Fprintf(v.out, "CLI Version: %#v\n", *versionInfo.cliVersionInfo)
if versionInfo.remoteVersionInfo != nil {
fmt.Fprintf(v.out, "Mesh [%s] Version: %#v\n", versionInfo.remoteVersionInfo.meshName, *versionInfo.remoteVersionInfo.version)
if versionInfo.remoteVersionInfo.meshName != "" {
fmt.Fprintf(v.out, "Mesh [%s] Version: %#v\n", versionInfo.remoteVersionInfo.meshName, *versionInfo.remoteVersionInfo.version)
} else {
fmt.Fprintf(v.out, "Mesh Version: No control plane found in namespace [%s]\n", v.namespace)
}
}
}
37 changes: 32 additions & 5 deletions cmd/cli/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func TestGetMeshVersion(t *testing.T) {
name: "no mesh in namespace",
namespace: "test",
remoteVersion: nil,
remoteVersionInfo: nil,
remoteVersionInfo: &remoteVersionInfo{},
controllerPods: []*corev1.Pod{},
proxyGetMeshVersionErr: nil,
expectedErr: errors.Errorf("No mesh found in namespace [test]"),
expectedErr: nil,
},
{
name: "mesh in namespace and proxyGetMeshVersion fails",
Expand Down Expand Up @@ -139,7 +139,20 @@ func TestOutputVersionInfo(t *testing.T) {
clientOnly bool
}{
{
name: "cli and no mesh",
name: "cli and mesh versions with no control plane installed",
versionInfo: versionInfo{
cliVersionInfo: &version.Info{
Version: "v0.0.0",
GitCommit: "xxxxxxx",
BuildDate: "0000-00-00-00:00",
},
remoteVersionInfo: &remoteVersionInfo{},
},
expected: "CLI Version: version.Info{Version:\"v0.0.0\", GitCommit:\"xxxxxxx\", BuildDate:\"0000-00-00-00:00\"}\nMesh Version: No control plane found in namespace [test]\n",
clientOnly: false,
},
{
name: "cli version only",
versionInfo: versionInfo{
cliVersionInfo: &version.Info{
Version: "v0.0.0",
Expand All @@ -151,7 +164,7 @@ func TestOutputVersionInfo(t *testing.T) {
clientOnly: true,
},
{
name: "cli and mesh",
name: "cli and mesh versions with control plane installed",
versionInfo: versionInfo{
cliVersionInfo: &version.Info{
Version: "v0.0.0",
Expand All @@ -170,6 +183,19 @@ func TestOutputVersionInfo(t *testing.T) {
expected: "CLI Version: version.Info{Version:\"v0.0.0\", GitCommit:\"xxxxxxx\", BuildDate:\"0000-00-00-00:00\"}\nMesh [test] Version: version.Info{Version:\"v0.0.0\", GitCommit:\"xxxxxxx\", BuildDate:\"0000-00-00-00:00\"}\n",
clientOnly: false,
},
{
name: "cli and mesh versions with no remote version info",
versionInfo: versionInfo{
cliVersionInfo: &version.Info{
Version: "v0.0.0",
GitCommit: "xxxxxxx",
BuildDate: "0000-00-00-00:00",
},
remoteVersionInfo: nil,
},
expected: "CLI Version: version.Info{Version:\"v0.0.0\", GitCommit:\"xxxxxxx\", BuildDate:\"0000-00-00-00:00\"}\n",
clientOnly: false,
},
}

for _, test := range tests {
Expand All @@ -180,10 +206,11 @@ func TestOutputVersionInfo(t *testing.T) {
cmd := versionCmd{
out: buf,
clientOnly: test.clientOnly,
namespace: "test",
}
cmd.outputVersionInfo(test.versionInfo)

assert.Equal(buf.String(), test.expected)
assert.Equal(test.expected, buf.String())
})
}
}

0 comments on commit 8c87b8a

Please sign in to comment.