From 35a1d2b4cb86e2573d9a9e63eb8fd64167dcfe18 Mon Sep 17 00:00:00 2001 From: pokorny Date: Fri, 14 Aug 2026 19:21:24 +0200 Subject: [PATCH] feat: (HCP-17081) - add cce list attribute: api endpoint - upgrade gophertelekomcloud library to v0.9.8 --- cmd/cce_list.go | 18 ++++++++++-------- go.mod | 2 +- go.sum | 4 ++-- services/cce/root.go | 42 ++++++++++++++++++++++++++++++++++++++++-- services/sfs/root.go | 7 +------ 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/cmd/cce_list.go b/cmd/cce_list.go index d816385..5376653 100644 --- a/cmd/cce_list.go +++ b/cmd/cce_list.go @@ -6,7 +6,6 @@ import ( "github.com/ysoftdevs/otc-cli/formats" "github.com/ysoftdevs/otc-cli/services/cce" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters" "github.com/spf13/cobra" ) @@ -31,21 +30,24 @@ func init() { initFlagFormat(listCmd) } -func clustersTableView() formats.View[clusters.Clusters] { - return formats.View[clusters.Clusters]{ - Columns: []formats.Column[clusters.Clusters]{ - formats.Col("ID", func(c clusters.Clusters) string { +func clustersTableView() formats.View[cce.Cluster] { + return formats.View[cce.Cluster]{ + Columns: []formats.Column[cce.Cluster]{ + formats.Col("ID", func(c cce.Cluster) string { return c.Metadata.Id }), - formats.Col("Name", func(c clusters.Clusters) string { + formats.Col("Name", func(c cce.Cluster) string { return c.Metadata.Name }), - formats.Col("Status", func(c clusters.Clusters) string { + formats.Col("Status", func(c cce.Cluster) string { return c.Status.Phase }), - formats.Col("Version", func(c clusters.Clusters) string { + formats.Col("Version", func(c cce.Cluster) string { return c.Spec.Version }), + formats.Col("API Endpoint", func(c cce.Cluster) string { + return c.APIEndpoint + }), }, } } diff --git a/go.mod b/go.mod index 0402ebf..36501c9 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.24.5 require ( github.com/chromedp/chromedp v0.14.2 github.com/jedib0t/go-pretty v4.3.0+incompatible - github.com/opentelekomcloud/gophertelekomcloud v0.9.5 + github.com/opentelekomcloud/gophertelekomcloud v0.9.8 github.com/spf13/cobra v1.10.2 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 6ae4a05..0bc5e1d 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byF github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/opentelekomcloud/gophertelekomcloud v0.9.5 h1:wJMqv0xU6CcTVZAWVw2qig1j/hn7+5eulpF0A7LGWo0= -github.com/opentelekomcloud/gophertelekomcloud v0.9.5/go.mod h1:la8cQVYopRoEbNe2L7HlGTdLxUQOwIqHp1VHtjE/5qA= +github.com/opentelekomcloud/gophertelekomcloud v0.9.8 h1:xBhB2Og/uvciAmeUDDLy9mwMM42lD4CYWAQCBbrEHgE= +github.com/opentelekomcloud/gophertelekomcloud v0.9.8/go.mod h1:la8cQVYopRoEbNe2L7HlGTdLxUQOwIqHp1VHtjE/5qA= github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw= github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/services/cce/root.go b/services/cce/root.go index 99c02dc..c2085ec 100644 --- a/services/cce/root.go +++ b/services/cce/root.go @@ -29,7 +29,16 @@ func getCCEClouds(commonConfig *config.CommonConfig) (*golangsdk.ServiceClient, }) } -func List(commonConfig *config.CommonConfig) ([]clusters.Clusters, error) { +// Cluster embeds the full SDK cluster representation and adds the API +// endpoint as a top-level, easily discoverable field. The SDK's own +// Status.Endpoints field is excluded from JSON marshaling (json:"-"), so +// without this it would be missing from the JSON output. +type Cluster struct { + clusters.Clusters `yaml:",inline"` + APIEndpoint string `json:"apiEndpoint" yaml:"apiEndpoint"` +} + +func List(commonConfig *config.CommonConfig) ([]Cluster, error) { cce, err := getCCEClouds(commonConfig) if err != nil { return nil, fmt.Errorf("failed to create CCE client: %w", err) @@ -40,7 +49,36 @@ func List(commonConfig *config.CommonConfig) ([]clusters.Clusters, error) { return nil, fmt.Errorf("failed to list clusters: %w", err) } - return clusterList, nil + result := make([]Cluster, 0, len(clusterList)) + for _, c := range clusterList { + result = append(result, Cluster{ + Clusters: c, + APIEndpoint: endpoint(c), + }) + } + + return result, nil +} + +// endpoint returns the API access address of a cluster, preferring the +// public (external) endpoint and falling back to internal ones. +func endpoint(c clusters.Clusters) string { + for _, e := range c.Status.Endpoints { + if e.External != "" { + return e.External + } + } + for _, e := range c.Status.Endpoints { + if e.Url != "" { + return e.Url + } + } + for _, e := range c.Status.Endpoints { + if e.Internal != "" { + return e.Internal + } + } + return "" } type ConfigArgs struct { diff --git a/services/sfs/root.go b/services/sfs/root.go index 7e0f5eb..fbaf74f 100644 --- a/services/sfs/root.go +++ b/services/sfs/root.go @@ -46,16 +46,11 @@ func List(args ListArgs) ([]ShareInfo, error) { return nil, fmt.Errorf("failed to create SFS Turbo client: %w", err) } - pages, err := shares.List(sfsClient, shares.ListOpts{}).AllPages() + allShares, err := shares.List(sfsClient, shares.ListOpts{}) if err != nil { return nil, fmt.Errorf("failed to list SFS Turbo shares: %w", err) } - allShares, err := shares.ExtractTurbos(pages) - if err != nil { - return nil, fmt.Errorf("failed to extract SFS Turbo shares: %w", err) - } - result := make([]ShareInfo, 0, len(allShares)) for _, s := range allShares { if args.Filter != "" && !strings.Contains(s.Name, args.Filter) {