Skip to content

Commit

Permalink
Revert "Fix: Non odo components not reported (redhat-developer#6021)"
Browse files Browse the repository at this point in the history
This reverts commit b4ee872.
  • Loading branch information
feloy committed Aug 18, 2022
1 parent 2015109 commit 43d8e64
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 137 deletions.
4 changes: 2 additions & 2 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ func ListAllClusterComponents(client kclient.ClientInterface, namespace string)
}

// Get the managedBy label
// IMPORTANT. If both "managed-by" and "instance" labels are BLANK, it is most likely an operator
// IMPORTANT. If "managed-by" label is BLANK, it is most likely an operator
// or a non-component. We do not want to show these in the list of components
// so we skip them if there is no "managed-by" label.

managedBy := odolabels.GetManagedBy(labels)
if managedBy == "" && name == "" {
if managedBy == "" {
continue
}

Expand Down
29 changes: 6 additions & 23 deletions pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import (
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/labels"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/redhat-developer/odo/pkg/api"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func TestListAllClusterComponents(t *testing.T) {
res1 := getUnstructured("dep1", "deployment", "v1", "Unknown", "Unknown", "my-ns")
res2 := getUnstructured("svc1", "service", "v1", "odo", "nodejs", "my-ns")
res3 := getUnstructured("dep1", "deployment", "v1", "Unknown", "Unknown", "my-ns")
res3.SetLabels(map[string]string{})

commonLabels := labels.Builder().WithComponentName("comp1").WithManager("odo")

resDev := getUnstructured("depDev", "deployment", "v1", "odo", "nodejs", "my-ns")
Expand Down Expand Up @@ -68,31 +66,15 @@ func TestListAllClusterComponents(t *testing.T) {
}},
wantErr: false,
},
{
name: "0 non-odo resource without instance label is not returned",
fields: fields{
kubeClient: func(ctrl *gomock.Controller) kclient.ClientInterface {
var resources []unstructured.Unstructured
resources = append(resources, res3)
client := kclient.NewMockClientInterface(ctrl)
client.EXPECT().GetAllResourcesFromSelector(gomock.Any(), "my-ns").Return(resources, nil)
return client
},
},
args: args{
namespace: "my-ns",
},
want: nil,
wantErr: false,
},
{
name: "1 non-odo resource returned with Unknown, and 1 odo resource returned with odo",
fields: fields{
kubeClient: func(ctrl *gomock.Controller) kclient.ClientInterface {
var resources []unstructured.Unstructured
resources = append(resources, res1, res2)
client := kclient.NewMockClientInterface(ctrl)
client.EXPECT().GetAllResourcesFromSelector(gomock.Any(), "my-ns").Return(resources, nil)
selector := ""
client.EXPECT().GetAllResourcesFromSelector(selector, "my-ns").Return(resources, nil)
return client
},
},
Expand All @@ -119,7 +101,8 @@ func TestListAllClusterComponents(t *testing.T) {
var resources []unstructured.Unstructured
resources = append(resources, resDev, resDeploy)
client := kclient.NewMockClientInterface(ctrl)
client.EXPECT().GetAllResourcesFromSelector(gomock.Any(), "my-ns").Return(resources, nil)
selector := ""
client.EXPECT().GetAllResourcesFromSelector(selector, "my-ns").Return(resources, nil)
return client
},
},
Expand Down
7 changes: 6 additions & 1 deletion tests/examples/manifests/deployment-app-label.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
app: app
app.kubernetes.io/instance: example-deployment
app.kubernetes.io/managed-by: some-tool
app.kubernetes.io/managed-by: console
app.kubernetes.io/managed-by-version: v4.7.0
app.kubernetes.io/name: example-deployment
app.kubernetes.io/part-of: app
Expand All @@ -18,6 +18,11 @@ spec:
metadata:
labels:
app: app
app.kubernetes.io/instance: example-deployment
app.kubernetes.io/managed-by: console
app.kubernetes.io/managed-by-version: v4.7.0
app.kubernetes.io/name: example-deployment
app.kubernetes.io/part-of: app
spec:
containers:
- name: httpd
Expand Down
47 changes: 0 additions & 47 deletions tests/examples/manifests/deployment-without-managed-by-label.yaml

This file was deleted.

64 changes: 0 additions & 64 deletions tests/integration/cmd_devfile_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"

devfilepkg "github.com/devfile/api/v2/pkg/devfile"
"github.com/tidwall/gjson"

"github.com/redhat-developer/odo/tests/helper"

Expand All @@ -26,69 +25,6 @@ var _ = Describe("odo list with devfile", func() {
var _ = AfterEach(func() {
helper.CommonAfterEach(commonVar)
})
Context("listing non-odo managed components", func() {
When("a non-odo managed component is deployed", func() {
const (
// hard coded names from the deployment-app-label.yaml
deploymentName = "example-deployment"
managedBy = "some-tool"
)
BeforeEach(func() {
commonVar.CliRunner.Run("create", "-f", helper.GetExamplePath("manifests", "deployment-app-label.yaml"))
})
AfterEach(func() {
commonVar.CliRunner.Run("delete", "-f", helper.GetExamplePath("manifests", "deployment-app-label.yaml"))
})
It("should list the component with odo list", func() {
output := helper.Cmd("odo", "list").ShouldPass().Out()
helper.MatchAllInOutput(output, []string{deploymentName, "Unknown", "None", managedBy})
})
It("should list the component in JSON", func() {
output := helper.Cmd("odo", "list", "-o", "json").ShouldPass().Out()
helper.JsonPathContentIs(output, "components.0.name", deploymentName)
Expect(gjson.Get(output, "components.0.runningIn").String()).To(BeEmpty())
helper.JsonPathContentIs(output, "components.0.projectType", "Unknown")
helper.JsonPathContentIs(output, "components.0.managedBy", managedBy)
})
})
When("a non-odo managed component without the managed-by label is deployed", func() {
const (
// hard coded names from the deployment-without-managed-by-label.yaml
deploymentName = "java-springboot-basic"
)
BeforeEach(func() {
commonVar.CliRunner.Run("create", "-f", helper.GetExamplePath("manifests", "deployment-without-managed-by-label.yaml"))
})
AfterEach(func() {
commonVar.CliRunner.Run("delete", "-f", helper.GetExamplePath("manifests", "deployment-without-managed-by-label.yaml"))
})
It("should list the component with odo list", func() {
output := helper.Cmd("odo", "list").ShouldPass().Out()
helper.MatchAllInOutput(output, []string{deploymentName, "Unknown", "None", "Unknown"})
})
It("should list the component in JSON", func() {
output := helper.Cmd("odo", "list", "-o", "json").ShouldPass().Out()
helper.JsonPathContentContain(output, "components.0.name", deploymentName)
Expect(gjson.Get(output, "components.0.runningIn").String()).To(BeEmpty())
helper.JsonPathContentContain(output, "components.0.projectType", "Unknown")
helper.JsonPathContentContain(output, "components.0.managedBy", "")
})
})
When("an operator managed deployment(without instance and managed-by label) is deployed", func() {
deploymentName := "nginx"
BeforeEach(func() {
commonVar.CliRunner.Run("create", "deployment", deploymentName, "--image=nginx")
})
AfterEach(func() {
commonVar.CliRunner.Run("delete", "deployment", deploymentName)
})
It("should not be listed in the odo list output", func() {
output := helper.Cmd("odo", "list").ShouldRun().Out()
Expect(output).ToNot(ContainSubstring(deploymentName))

})
})
})

When("a component created in 'app' application", func() {

Expand Down

0 comments on commit 43d8e64

Please sign in to comment.