Skip to content

Commit

Permalink
Parthvi review
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed May 11, 2022
1 parent 0ddcd94 commit 288c4e3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
10 changes: 5 additions & 5 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ func getResourcesForComponent(client kclient.ClientInterface, name string, names

// GetRunningModes returns the list of modes on which a "name" component is deployed, by looking into namespace
// the resources deployed with matching labels, based on the "odo.dev/mode" label
func GetRunningModes(client kclient.ClientInterface, name string, namespace string) ([]api.RunningMode, error) {
list, err := getResourcesForComponent(client, name, namespace)
func GetRunningModes(client kclient.ClientInterface, name string) ([]api.RunningMode, error) {
list, err := getResourcesForComponent(client, name, client.GetCurrentNamespace())
if err != nil {
return []api.RunningMode{api.RunningModeUnknown}, nil
}

if len(list) == 0 {
return nil, NewNoComponentFoundError(name, namespace)
return nil, NewNoComponentFoundError(name, client.GetCurrentNamespace())
}

mapResult := map[string]bool{}
Expand Down Expand Up @@ -272,8 +272,8 @@ func Contains(component OdoComponent, components []OdoComponent) bool {
}

// GetDevfileInfoFromCluster extracts information from the labels and annotations of resources to rebuild a Devfile
func GetDevfileInfoFromCluster(client kclient.ClientInterface, name string, namespace string) (parser.DevfileObj, error) {
list, err := getResourcesForComponent(client, name, namespace)
func GetDevfileInfoFromCluster(client kclient.ClientInterface, name string) (parser.DevfileObj, error) {
list, err := getResourcesForComponent(client, name, client.GetCurrentNamespace())
if err != nil {
return parser.DevfileObj{}, nil
}
Expand Down
35 changes: 17 additions & 18 deletions pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ func TestGetRunningModes(t *testing.T) {
packageManifestResource.SetLabels(labels.Builder().WithMode(labels.ComponentDevMode).Labels())

type args struct {
client func(ctrl *gomock.Controller) kclient.ClientInterface
name string
namespace string
client func(ctrl *gomock.Controller) kclient.ClientInterface
name string
}
tests := []struct {
name string
Expand All @@ -186,11 +185,11 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return([]unstructured.Unstructured{}, nil)
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: nil,
wantErr: true,
Expand All @@ -200,11 +199,11 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return([]unstructured.Unstructured{packageManifestResource}, nil)
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: nil,
wantErr: true,
Expand All @@ -214,11 +213,11 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return([]unstructured.Unstructured{packageManifestResource, otherResource}, nil)
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: []api.RunningMode{},
},
Expand All @@ -227,11 +226,11 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return([]unstructured.Unstructured{packageManifestResource, otherResource, resourceDev1, resourceDev2}, nil)
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: []api.RunningMode{api.RunningModeDev},
},
Expand All @@ -240,11 +239,11 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return([]unstructured.Unstructured{packageManifestResource, otherResource, resourceDeploy1, resourceDeploy2}, nil)
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: []api.RunningMode{api.RunningModeDeploy},
},
Expand All @@ -253,11 +252,11 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return([]unstructured.Unstructured{packageManifestResource, otherResource, resourceDev1, resourceDev2, resourceDeploy1, resourceDeploy2}, nil)
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: []api.RunningMode{api.RunningModeDev, api.RunningModeDeploy},
},
Expand All @@ -266,19 +265,19 @@ func TestGetRunningModes(t *testing.T) {
args: args{
client: func(ctrl *gomock.Controller) kclient.ClientInterface {
c := kclient.NewMockClientInterface(ctrl)
c.EXPECT().GetCurrentNamespace().Return("a-namespace").AnyTimes()
c.EXPECT().GetAllResourcesFromSelector(gomock.Any(), gomock.Any()).Return(nil, errors.New("error"))
return c
},
name: "aname",
namespace: "anamespace",
name: "aname",
},
want: []api.RunningMode{api.RunningModeUnknown},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
got, err := GetRunningModes(tt.args.client(ctrl), tt.args.name, tt.args.namespace)
got, err := GetRunningModes(tt.args.client(ctrl), tt.args.name)
if (err != nil) != tt.wantErr {
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/odo/cli/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func (o *ComponentOptions) run(ctx context.Context) (result api.Component, devfi

// describeNamedComponent describes a component given its name
func (o *ComponentOptions) describeNamedComponent(name string) (result api.Component, devfileObj *parser.DevfileObj, err error) {
runningIn, err := component.GetRunningModes(o.clientset.KubernetesClient, name, o.clientset.KubernetesClient.GetCurrentNamespace())
runningIn, err := component.GetRunningModes(o.clientset.KubernetesClient, name)
if err != nil {
return api.Component{}, nil, err
}
devfile, err := component.GetDevfileInfoFromCluster(o.clientset.KubernetesClient, name, o.clientset.KubernetesClient.GetCurrentNamespace())
devfile, err := component.GetDevfileInfoFromCluster(o.clientset.KubernetesClient, name)
if err != nil {
return api.Component{}, nil, err
}
Expand All @@ -136,7 +136,7 @@ func (o *ComponentOptions) describeDevfileComponent() (result api.Component, dev
if err != nil {
return api.Component{}, nil, err
}
runningIn, err := component.GetRunningModes(o.clientset.KubernetesClient, devfileObj.GetMetadataName(), o.clientset.KubernetesClient.GetCurrentNamespace())
runningIn, err := component.GetRunningModes(o.clientset.KubernetesClient, devfileObj.GetMetadataName())
if err != nil {
if !errors.As(err, &component.NoComponentFoundError{}) {
return api.Component{}, nil, err
Expand Down

0 comments on commit 288c4e3

Please sign in to comment.