Skip to content

Commit 7356653

Browse files
If cluster doesn't exist return default version values. (#2167)
1 parent 3928a2e commit 7356653

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

internal/cmd/skupper/version/kube/version.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ func (cmd *CmdVersion) InputToOptions() {
6969
if cmd.KubeClient != nil {
7070
// search for running pods in the current namespace
7171
runningPodList, err := cmd.KubeClient.CoreV1().Pods(cmd.namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "app.kubernetes.io/part-of in (skupper, skupper-network-observer)"})
72-
if err != nil {
73-
return
74-
}
75-
76-
for _, runningPod := range runningPodList.Items {
77-
for _, container := range runningPod.Status.ContainerStatuses {
78-
mapRunningPods[container.Name] = container.Image
72+
if err == nil {
73+
for _, runningPod := range runningPodList.Items {
74+
for _, container := range runningPod.Status.ContainerStatuses {
75+
mapRunningPods[container.Name] = container.Image
76+
}
7977
}
8078
}
8179
}
@@ -85,11 +83,11 @@ func (cmd *CmdVersion) InputToOptions() {
8583
} else {
8684
cmd.manifest = configs.ManifestManager{Components: images.KubeComponents, EnableSHA: false, RunningPods: mapRunningPods}
8785
}
88-
8986
}
9087

9188
func (cmd *CmdVersion) Run() error {
9289
files := cmd.manifest.GetConfiguredManifest()
90+
9391
if cmd.output != "" {
9492
encodedOutput, err := utils.Encode(cmd.output, files)
9593
if err != nil {

internal/cmd/skupper/version/kube/version_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
77
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
8+
fakeclient "github.com/skupperproject/skupper/internal/kube/client/fake"
89
"github.com/skupperproject/skupper/internal/utils/configs"
910
"gotest.tools/v3/assert"
1011
"k8s.io/apimachinery/pkg/runtime"
@@ -116,6 +117,11 @@ func TestCmdVersion_Run(t *testing.T) {
116117
flags: common.CommandVersionFlags{Output: "not-valid"},
117118
errorMessage: "format not-valid not supported",
118119
},
120+
{
121+
name: "no cluster",
122+
flags: common.CommandVersionFlags{},
123+
errorMessage: "Cluster is not accessible",
124+
},
119125
}
120126

121127
for _, test := range testTable {
@@ -142,8 +148,14 @@ func TestCmdVersion_Run(t *testing.T) {
142148

143149
func newCmdVersionWithMocks(namespace string, k8sObjects []runtime.Object, skupperObjects []runtime.Object, fakeSkupperError string) (*CmdVersion, error) {
144150

151+
client, err := fakeclient.NewFakeClient(namespace, k8sObjects, skupperObjects, fakeSkupperError)
152+
if err != nil {
153+
return nil, err
154+
}
145155
cmdVersion := &CmdVersion{
146-
namespace: namespace,
156+
Client: client.GetSkupperClient().SkupperV2alpha1(),
157+
namespace: namespace,
158+
KubeClient: client.GetKubeClient(),
147159
}
148160

149161
return cmdVersion, nil

0 commit comments

Comments
 (0)