From 48c9733f94a4c06bad5137e1e27ae7d358c2bc5d Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Fri, 23 Dec 2022 14:59:35 +0100 Subject: [PATCH] Duplicate runningOn field with platform + deprecated runningOn --- pkg/api/component-abstract.go | 3 ++ pkg/component/component.go | 1 + pkg/component/component_test.go | 4 +++ pkg/odo/cli/list/component/list.go | 11 ++++---- pkg/odo/cli/list/list.go | 1 + pkg/podman/component.go | 1 + tests/integration/cmd_devfile_list_test.go | 33 +++++++++++++--------- 7 files changed, 35 insertions(+), 19 deletions(-) diff --git a/pkg/api/component-abstract.go b/pkg/api/component-abstract.go index bb8a98566cd..74445acb4f8 100644 --- a/pkg/api/component-abstract.go +++ b/pkg/api/component-abstract.go @@ -9,7 +9,10 @@ type ComponentAbstract struct { RunningIn RunningModes `json:"runningIn"` Type string `json:"projectType"` // RunningOn is the platform the component is running on, either cluster or podman + // This field is deprecated and will be replaced by Platform RunningOn string `json:"runningOn,omitempty"` + // Platform is the platform the component is running on, either cluster or podman + Platform string `json:"platform,omitempty"` } const ( diff --git a/pkg/component/component.go b/pkg/component/component.go index ff0be3dd870..737ee80293c 100644 --- a/pkg/component/component.go +++ b/pkg/component/component.go @@ -173,6 +173,7 @@ func ListAllClusterComponents(client kclient.ClientInterface, namespace string) Type: componentType, ManagedByVersion: managedByVersion, RunningOn: commonflags.PlatformCluster, + Platform: commonflags.PlatformCluster, } mode := odolabels.GetMode(labels) componentFound := false diff --git a/pkg/component/component_test.go b/pkg/component/component_test.go index fca0737b4c1..9866b8d8f98 100644 --- a/pkg/component/component_test.go +++ b/pkg/component/component_test.go @@ -86,6 +86,7 @@ func TestListAllClusterComponents(t *testing.T) { RunningIn: nil, Type: "Unknown", RunningOn: "cluster", + Platform: "cluster", }}, wantErr: false, }, @@ -127,6 +128,7 @@ func TestListAllClusterComponents(t *testing.T) { RunningIn: nil, Type: "Unknown", RunningOn: "cluster", + Platform: "cluster", }, { Name: "svc1", ManagedBy: "odo", @@ -134,6 +136,7 @@ func TestListAllClusterComponents(t *testing.T) { RunningIn: nil, Type: "nodejs", RunningOn: "cluster", + Platform: "cluster", }}, wantErr: false, }, @@ -161,6 +164,7 @@ func TestListAllClusterComponents(t *testing.T) { }, Type: "nodejs", RunningOn: "cluster", + Platform: "cluster", }}, wantErr: false, }, diff --git a/pkg/odo/cli/list/component/list.go b/pkg/odo/cli/list/component/list.go index 7c52e5debfa..7966dd117f5 100644 --- a/pkg/odo/cli/list/component/list.go +++ b/pkg/odo/cli/list/component/list.go @@ -129,6 +129,7 @@ func (lo *ListOptions) run(ctx context.Context) (api.ResourcesList, error) { if !feature.IsEnabled(ctx, feature.GenericPformFlag) { for i := range allComponents { allComponents[i].RunningOn = "" + allComponents[i].Platform = "" } } return api.ResourcesList{ @@ -177,7 +178,7 @@ func HumanReadableOutput(ctx context.Context, list api.ResourcesList) { // Create the header and then sort accordingly headers := table.Row{"NAME", "PROJECT TYPE", "RUNNING IN", "MANAGED"} if feature.IsEnabled(ctx, feature.GenericPformFlag) { - headers = append(headers, "RUNNING ON") + headers = append(headers, "PLATFORM") } t.AppendHeader(headers) t.SortBy([]table.SortBy{ @@ -221,11 +222,11 @@ func HumanReadableOutput(ctx context.Context, list api.ResourcesList) { row := table.Row{name, componentType, mode, managedBy} if feature.IsEnabled(ctx, feature.GenericPformFlag) { - runningOn := comp.RunningOn - if runningOn == "" { - runningOn = "None" + platform := comp.Platform + if platform == "" { + platform = "None" } - row = append(row, runningOn) + row = append(row, platform) } t.AppendRow(row) diff --git a/pkg/odo/cli/list/list.go b/pkg/odo/cli/list/list.go index 07e4d5d1cdb..37b133d8963 100644 --- a/pkg/odo/cli/list/list.go +++ b/pkg/odo/cli/list/list.go @@ -146,6 +146,7 @@ func (lo *ListOptions) run(ctx context.Context) (list api.ResourcesList, err err if !feature.IsEnabled(ctx, feature.GenericPformFlag) { for i := range allComponents { allComponents[i].RunningOn = "" + allComponents[i].Platform = "" } } diff --git a/pkg/podman/component.go b/pkg/podman/component.go index 4e2f6c5a8f5..b084d4f8ca1 100644 --- a/pkg/podman/component.go +++ b/pkg/podman/component.go @@ -71,6 +71,7 @@ func (o *PodmanCli) ListAllComponents() ([]api.ComponentAbstract, error) { Type: componentType, ManagedByVersion: managedByVersion, RunningOn: commonflags.PlatformPodman, + Platform: commonflags.PlatformPodman, } mode := odolabels.GetMode(labels) if mode != "" { diff --git a/tests/integration/cmd_devfile_list_test.go b/tests/integration/cmd_devfile_list_test.go index bff02ad4eb6..2b062c3ede1 100644 --- a/tests/integration/cmd_devfile_list_test.go +++ b/tests/integration/cmd_devfile_list_test.go @@ -143,37 +143,39 @@ var _ = Describe("odo list with devfile", func() { }) } - It("should display runningOn depending on experimental mode", func() { + It("should display platform depending on experimental mode", func() { for _, cmd := range [][]string{ {"list", "component"}, {"list"}, } { cmd := cmd - By("returning runningOn when experimental mode is enabled with json output", func() { + By("returning platform when experimental mode is enabled with json output", func() { args := append(cmd, "-o", "json") res := helper.Cmd("odo", args...).AddEnv("ODO_EXPERIMENTAL_MODE=true").ShouldPass() stdout, stderr := res.Out(), res.Err() Expect(stderr).To(BeEmpty()) Expect(helper.IsJSON(stdout)).To(BeTrue(), "output should be in JSON format") helper.JsonPathContentIs(stdout, "components.#", "1") - helper.JsonPathContentIs(stdout, "components.0.runningOn", "cluster") + helper.JsonPathContentIs(stdout, "components.0.runningOn", "cluster") // Deprecated + helper.JsonPathContentIs(stdout, "components.0.platform", "cluster") }) - By("not returning runningOn when experimental mode is not enabled with json output", func() { + By("not returning platform when experimental mode is not enabled with json output", func() { args := append(cmd, "-o", "json") res := helper.Cmd("odo", args...).ShouldPass() stdout, stderr := res.Out(), res.Err() Expect(stderr).To(BeEmpty()) Expect(helper.IsJSON(stdout)).To(BeTrue(), "output should be in JSON format") helper.JsonPathContentIs(stdout, "components.#", "1") - helper.JsonPathDoesNotExist(stdout, "components.0.runningOn") + helper.JsonPathDoesNotExist(stdout, "components.0.runningOn") // Deprecated + helper.JsonPathDoesNotExist(stdout, "components.0.platform") }) - By("displaying runningOn when experimental mode is enabled", func() { + By("displaying platform when experimental mode is enabled", func() { stdout := helper.Cmd("odo", cmd...).AddEnv("ODO_EXPERIMENTAL_MODE=true").ShouldPass().Out() - Expect(stdout).To(ContainSubstring("RUNNING ON")) + Expect(stdout).To(ContainSubstring("PLATFORM")) }) - By("not displaying runningOn when experimental mode is not enabled", func() { + By("not displaying platform when experimental mode is not enabled", func() { stdout := helper.Cmd("odo", cmd...).ShouldPass().Out() - Expect(stdout).ToNot(ContainSubstring("RUNNING ON")) + Expect(stdout).ToNot(ContainSubstring("PLATFORM")) }) } }) @@ -262,7 +264,8 @@ var _ = Describe("odo list with devfile", func() { helper.JsonPathContentIs(stdout, "components.#", "1") helper.JsonPathContentIs(stdout, "components.0.name", componentName) helper.JsonPathContentIs(stdout, "components.0.runningIn.dev", "true") - helper.JsonPathContentIs(stdout, "components.0.runningOn", "podman") + helper.JsonPathContentIs(stdout, "components.0.runningOn", "podman") // Deprecated + helper.JsonPathContentIs(stdout, "components.0.platform", "podman") }) By("returning component not in dev mode when experimental mode is enabled with json output and run-on is cluster", func() { args := append(cmd, "-o", "json", "--platform", "cluster") @@ -271,7 +274,8 @@ var _ = Describe("odo list with devfile", func() { helper.JsonPathContentIs(stdout, "components.#", "1") helper.JsonPathContentIs(stdout, "components.0.name", componentName) helper.JsonPathContentIs(stdout, "components.0.runningIn.dev", "false") - helper.JsonPathDoesNotExist(stdout, "components.0.runningOn") + helper.JsonPathDoesNotExist(stdout, "components.0.runningOn") // Deprecated + helper.JsonPathDoesNotExist(stdout, "components.0.platform") }) By("returning component not in dev mode when experimental mode is not enabled with json output", func() { args := append(cmd, "-o", "json") @@ -280,19 +284,20 @@ var _ = Describe("odo list with devfile", func() { helper.JsonPathContentIs(stdout, "components.#", "1") helper.JsonPathContentIs(stdout, "components.0.name", componentName) helper.JsonPathContentIs(stdout, "components.0.runningIn.dev", "false") - helper.JsonPathDoesNotExist(stdout, "components.0.runningOn") + helper.JsonPathDoesNotExist(stdout, "components.0.runningOn") // Deprecated + helper.JsonPathDoesNotExist(stdout, "components.0.platform") }) By("displaying component in dev mode when experimental mode is enabled", func() { stdout := helper.Cmd("odo", cmd...).AddEnv("ODO_EXPERIMENTAL_MODE=true").ShouldPass().Out() Expect(stdout).To(ContainSubstring(componentName)) - Expect(stdout).To(ContainSubstring("RUNNING ON")) + Expect(stdout).To(ContainSubstring("PLATFORM")) Expect(stdout).To(ContainSubstring("podman")) Expect(stdout).To(ContainSubstring("Dev")) }) By("displaying component not in dev mode when experimental mode is not enabled", func() { stdout := helper.Cmd("odo", cmd...).ShouldPass().Out() Expect(stdout).To(ContainSubstring(componentName)) - Expect(stdout).ToNot(ContainSubstring("RUNNING ON")) + Expect(stdout).ToNot(ContainSubstring("PLATFORM")) Expect(stdout).To(ContainSubstring("None")) }) }