Skip to content

Commit c66852a

Browse files
committed
feat: report cluster id and platform id in namespaces/deployments/connectors sub command
1 parent 4da5f25 commit c66852a

File tree

11 files changed

+304
-96
lines changed

11 files changed

+304
-96
lines changed

rhoc/pkg/cmd/connectors/get/get.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package get
22

33
import (
4+
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/api/admin"
45
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/service"
56
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/cmdutil"
6-
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/response"
77
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
88
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
99
"github.com/spf13/cobra"
@@ -20,6 +20,12 @@ type options struct {
2020
f *factory.Factory
2121
}
2222

23+
type connectorDetail struct {
24+
admin.ConnectorAdminView `json:",inline" yaml:",inline"`
25+
ClusterID string `json:"cluster_id,omitempty" yaml:"cluster_id,omitempty"`
26+
PlatformID string `json:"platform_id,omitempty" yaml:"platform_id,omitempty"`
27+
}
28+
2329
func NewGetCommand(f *factory.Factory) *cobra.Command {
2430
opts := options{
2531
f: f,
@@ -54,15 +60,21 @@ func run(opts *options) error {
5460
return err
5561
}
5662

57-
result, httpRes, err := c.Clusters().GetConnector(opts.f.Context, opts.id).Execute()
58-
if httpRes != nil {
59-
defer func() {
60-
_ = httpRes.Body.Close()
61-
}()
63+
connector, err := service.GetConnectorByID(c, opts.id)
64+
if err != nil {
65+
return err
6266
}
67+
68+
cluster, err := service.GetClusterForNamespace(c, connector.NamespaceId)
6369
if err != nil {
64-
return response.Error(err, httpRes)
70+
return err
71+
}
72+
73+
detail := connectorDetail{
74+
ConnectorAdminView: *connector,
75+
ClusterID: cluster.Id,
76+
PlatformID: cluster.Status.Platform.Id,
6577
}
6678

67-
return dump.Formatted(opts.f.IOStreams.Out, opts.outputFormat, result)
79+
return dump.Formatted(opts.f.IOStreams.Out, opts.outputFormat, detail)
6880
}

rhoc/pkg/cmd/connectors/list/list.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package list
33
import (
44
"errors"
55
"fmt"
6-
76
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/api/admin"
87
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/service"
98
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/cmdutil"
@@ -29,6 +28,12 @@ type options struct {
2928
f *factory.Factory
3029
}
3130

31+
type connectorDetail struct {
32+
admin.ConnectorAdminView `json:",inline" yaml:",inline"`
33+
ClusterID string `json:"cluster_id,omitempty" yaml:"cluster_id,omitempty"`
34+
PlatformID string `json:"platform_id,omitempty" yaml:"platform_id,omitempty"`
35+
}
36+
3237
func NewListCommand(f *factory.Factory) *cobra.Command {
3338

3439
opts := options{
@@ -82,24 +87,40 @@ func run(opts *options) error {
8287
return err
8388
}
8489

85-
var items admin.ConnectorAdminViewList
90+
var connectors admin.ConnectorAdminViewList
91+
var cluster *admin.ConnectorClusterAdminView
8692

8793
switch {
8894
case opts.clusterID != "":
89-
items, err = service.ListConnectorsForCluster(c, opts.ListOptions, opts.clusterID)
95+
connectors, err = service.ListConnectorsForCluster(c, opts.ListOptions, opts.clusterID)
96+
if err == nil {
97+
cluster, err = service.GetClusterByID(c, opts.clusterID)
98+
}
9099
case opts.namespaceID != "":
91-
items, err = service.ListConnectorsForNamespace(c, opts.ListOptions, opts.namespaceID)
100+
connectors, err = service.ListConnectorsForNamespace(c, opts.ListOptions, opts.namespaceID)
101+
if err == nil {
102+
cluster, err = service.GetClusterForNamespace(c, opts.namespaceID)
103+
}
92104
}
93105

94106
if err != nil {
95107
return err
96108
}
97109

98-
if len(items.Items) == 0 && opts.outputFormat == "" {
110+
if len(connectors.Items) == 0 && opts.outputFormat == "" {
99111
_, _ = fmt.Fprint(opts.f.IOStreams.Out, "No result\n")
100112
return nil
101113
}
102114

115+
items := make([]connectorDetail, len(connectors.Items))
116+
for i := range connectors.Items {
117+
items[i] = connectorDetail{
118+
ConnectorAdminView: connectors.Items[i],
119+
ClusterID: cluster.Id,
120+
PlatformID: cluster.Status.Platform.Id,
121+
}
122+
}
123+
103124
switch opts.outputFormat {
104125
case dump.EmptyFormat:
105126
_, _ = fmt.Fprint(opts.f.IOStreams.Out, "\n")

rhoc/pkg/cmd/connectors/list/list_dumper.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ import (
55
"strconv"
66
"time"
77

8-
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/api/admin"
98
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/dumper"
109
"github.com/olekukonko/tablewriter"
1110
"k8s.io/apimachinery/pkg/util/duration"
1211
)
1312

14-
func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, style dumper.TableStyle) {
15-
config := dumper.TableConfig[admin.ConnectorAdminView]{
13+
func dumpAsTable(out io.Writer, items []connectorDetail, wide bool, style dumper.TableStyle) {
14+
config := dumper.TableConfig[connectorDetail]{
1615
Style: style,
1716
Wide: wide,
18-
Columns: []dumper.Column[admin.ConnectorAdminView]{
17+
Columns: []dumper.Column[connectorDetail]{
1918
{
2019
Name: "ID",
2120
Wide: false,
22-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
21+
Getter: func(in *connectorDetail) dumper.Row {
2322
return dumper.Row{
2423
Value: in.Id,
2524
}
@@ -28,16 +27,34 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
2827
{
2928
Name: "NamespaceId",
3029
Wide: false,
31-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
30+
Getter: func(in *connectorDetail) dumper.Row {
3231
return dumper.Row{
3332
Value: in.NamespaceId,
3433
}
3534
},
3635
},
36+
{
37+
Name: "ClusterId",
38+
Wide: true,
39+
Getter: func(in *connectorDetail) dumper.Row {
40+
return dumper.Row{
41+
Value: in.ClusterID,
42+
}
43+
},
44+
},
45+
{
46+
Name: "PlatformId",
47+
Wide: true,
48+
Getter: func(in *connectorDetail) dumper.Row {
49+
return dumper.Row{
50+
Value: in.PlatformID,
51+
}
52+
},
53+
},
3754
{
3855
Name: "Name",
3956
Wide: true,
40-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
57+
Getter: func(in *connectorDetail) dumper.Row {
4158
return dumper.Row{
4259
Value: in.Name,
4360
}
@@ -46,7 +63,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
4663
{
4764
Name: "Owner",
4865
Wide: false,
49-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
66+
Getter: func(in *connectorDetail) dumper.Row {
5067
return dumper.Row{
5168
Value: in.Owner,
5269
}
@@ -55,7 +72,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
5572
{
5673
Name: "ConnectorTypeId",
5774
Wide: false,
58-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
75+
Getter: func(in *connectorDetail) dumper.Row {
5976
return dumper.Row{
6077
Value: in.ConnectorTypeId,
6178
}
@@ -64,7 +81,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
6481
{
6582
Name: "DesiredState",
6683
Wide: false,
67-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
84+
Getter: func(in *connectorDetail) dumper.Row {
6885
return dumper.Row{
6986
Value: string(in.DesiredState),
7087
}
@@ -73,7 +90,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
7390
{
7491
Name: "State",
7592
Wide: false,
76-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
93+
Getter: func(in *connectorDetail) dumper.Row {
7794
r := dumper.Row{
7895
Value: string(in.Status.State),
7996
}
@@ -93,7 +110,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
93110
{
94111
Name: "Reason",
95112
Wide: true,
96-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
113+
Getter: func(in *connectorDetail) dumper.Row {
97114
return dumper.Row{
98115
Value: in.Status.Error,
99116
}
@@ -102,7 +119,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
102119
{
103120
Name: "Version",
104121
Wide: false,
105-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
122+
Getter: func(in *connectorDetail) dumper.Row {
106123
return dumper.Row{
107124
Value: strconv.FormatInt(in.ResourceVersion, 10),
108125
}
@@ -111,7 +128,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
111128
{
112129
Name: "Age",
113130
Wide: false,
114-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
131+
Getter: func(in *connectorDetail) dumper.Row {
115132
age := duration.HumanDuration(time.Since(in.CreatedAt))
116133
if in.CreatedAt.IsZero() {
117134
age = ""
@@ -125,7 +142,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
125142
{
126143
Name: "CreatedAt",
127144
Wide: true,
128-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
145+
Getter: func(in *connectorDetail) dumper.Row {
129146
return dumper.Row{
130147
Value: in.CreatedAt.Format(time.RFC3339),
131148
}
@@ -134,7 +151,7 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
134151
{
135152
Name: "ModifiedAt",
136153
Wide: true,
137-
Getter: func(in *admin.ConnectorAdminView) dumper.Row {
154+
Getter: func(in *connectorDetail) dumper.Row {
138155
return dumper.Row{
139156
Value: in.ModifiedAt.Format(time.RFC3339),
140157
}
@@ -143,5 +160,5 @@ func dumpAsTable(out io.Writer, items admin.ConnectorAdminViewList, wide bool, s
143160
},
144161
}
145162

146-
dumper.DumpTable(config, out, items.Items)
163+
dumper.DumpTable(config, out, items)
147164
}

rhoc/pkg/cmd/deployments/get/get.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package get
22

33
import (
4+
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/api/admin"
45
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/service"
56
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/cmdutil"
6-
"github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/response"
77
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
88
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
99
"github.com/spf13/cobra"
@@ -21,6 +21,11 @@ type options struct {
2121
f *factory.Factory
2222
}
2323

24+
type deploymentDetail struct {
25+
admin.ConnectorDeploymentAdminView `json:",inline" yaml:",inline"`
26+
PlatformID string `json:"platform_id,omitempty" yaml:"platform_id,omitempty"`
27+
}
28+
2429
func NewGetCommand(f *factory.Factory) *cobra.Command {
2530
opts := options{
2631
f: f,
@@ -56,15 +61,20 @@ func run(opts *options) error {
5661
return err
5762
}
5863

59-
result, httpRes, err := c.Clusters().GetConnectorDeployment(opts.f.Context, opts.clusterID, opts.id).Execute()
60-
if httpRes != nil {
61-
defer func() {
62-
_ = httpRes.Body.Close()
63-
}()
64+
deployment, err := service.GetDeploymentByID(c, opts.clusterID, opts.id)
65+
if err != nil {
66+
return err
6467
}
68+
69+
cluster, err := service.GetClusterByID(c, deployment.Spec.ClusterId)
6570
if err != nil {
66-
return response.Error(err, httpRes)
71+
return err
72+
}
73+
74+
detail := deploymentDetail{
75+
ConnectorDeploymentAdminView: *deployment,
76+
PlatformID: cluster.Status.Platform.Id,
6777
}
6878

69-
return dump.Formatted(opts.f.IOStreams.Out, opts.outputFormat, result)
79+
return dump.Formatted(opts.f.IOStreams.Out, opts.outputFormat, detail)
7080
}

rhoc/pkg/cmd/deployments/list/list.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ type options struct {
2929
f *factory.Factory
3030
}
3131

32+
type deploymentDetail struct {
33+
admin.ConnectorDeploymentAdminView `json:",inline" yaml:",inline"`
34+
PlatformID string `json:"platform_id,omitempty" yaml:"platform_id,omitempty"`
35+
}
36+
3237
func NewListCommand(f *factory.Factory) *cobra.Command {
3338
opts := options{
3439
f: f,
@@ -80,24 +85,39 @@ func run(opts *options) error {
8085
return err
8186
}
8287

83-
var items admin.ConnectorDeploymentAdminViewList
88+
var deployments admin.ConnectorDeploymentAdminViewList
89+
var cluster *admin.ConnectorClusterAdminView
8490

8591
switch {
8692
case opts.clusterID != "":
87-
items, err = service.ListDeploymentsForCluster(c, opts.ListDeploymentsOptions, opts.clusterID)
93+
deployments, err = service.ListDeploymentsForCluster(c, opts.ListDeploymentsOptions, opts.clusterID)
94+
if err == nil {
95+
cluster, err = service.GetClusterByID(c, opts.clusterID)
96+
}
8897
case opts.namespaceID != "":
89-
items, err = service.ListDeploymentsForNamespace(c, opts.ListOptions, opts.namespaceID)
98+
deployments, err = service.ListDeploymentsForNamespace(c, opts.ListOptions, opts.namespaceID)
99+
if err == nil {
100+
cluster, err = service.GetClusterForNamespace(c, opts.namespaceID)
101+
}
90102
}
91103

92104
if err != nil {
93105
return err
94106
}
95107

96-
if len(items.Items) == 0 && opts.outputFormat == "" {
108+
if len(deployments.Items) == 0 && opts.outputFormat == "" {
97109
_, _ = fmt.Fprint(opts.f.IOStreams.Out, "No result\n")
98110
return nil
99111
}
100112

113+
items := make([]deploymentDetail, len(deployments.Items))
114+
for i := range deployments.Items {
115+
items[i] = deploymentDetail{
116+
ConnectorDeploymentAdminView: deployments.Items[i],
117+
PlatformID: cluster.Status.Platform.Id,
118+
}
119+
}
120+
101121
switch opts.outputFormat {
102122
case dump.EmptyFormat:
103123
_, _ = fmt.Fprint(opts.f.IOStreams.Out, "\n")

0 commit comments

Comments
 (0)