Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions cmd/cce_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}),
},
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.8-0.20260703083050-9dec68a8dcf7
github.com/opentelekomcloud/gophertelekomcloud v0.9.8
github.com/spf13/cobra v1.10.2
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.8-0.20260703083050-9dec68a8dcf7 h1:cf2lqasnVIqrFz+DW0m4gH79pdkYXlX00Lsuhi7dsek=
github.com/opentelekomcloud/gophertelekomcloud v0.9.8-0.20260703083050-9dec68a8dcf7/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=
Expand Down
42 changes: 40 additions & 2 deletions services/cce/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Loading