Skip to content

Commit

Permalink
Duplicate runningOn field with platform + deprecated runningOn
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Dec 23, 2022
1 parent cfa3c32 commit 48c9733
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions pkg/api/component-abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestListAllClusterComponents(t *testing.T) {
RunningIn: nil,
Type: "Unknown",
RunningOn: "cluster",
Platform: "cluster",
}},
wantErr: false,
},
Expand Down Expand Up @@ -127,13 +128,15 @@ func TestListAllClusterComponents(t *testing.T) {
RunningIn: nil,
Type: "Unknown",
RunningOn: "cluster",
Platform: "cluster",
}, {
Name: "svc1",
ManagedBy: "odo",
ManagedByVersion: "v3.0.0-beta3",
RunningIn: nil,
Type: "nodejs",
RunningOn: "cluster",
Platform: "cluster",
}},
wantErr: false,
},
Expand Down Expand Up @@ -161,6 +164,7 @@ func TestListAllClusterComponents(t *testing.T) {
},
Type: "nodejs",
RunningOn: "cluster",
Platform: "cluster",
}},
wantErr: false,
},
Expand Down
11 changes: 6 additions & 5 deletions pkg/odo/cli/list/component/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/odo/cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/podman/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
33 changes: 19 additions & 14 deletions tests/integration/cmd_devfile_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
}
})
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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"))
})
}
Expand Down

0 comments on commit 48c9733

Please sign in to comment.