Skip to content

addition of cluster get and sync status #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/hashicorp/go-multierror v1.1.1
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/signadot/go-sdk v0.3.8-0.20230917202415-61cf5bfada91
github.com/signadot/go-sdk v0.3.8-0.20231025100955-7260daf67ccc
github.com/signadot/libconnect v0.1.1-0.20231011194636-a0941512a00a
github.com/spf13/cobra v1.6.0
github.com/spf13/viper v1.11.0
Expand Down Expand Up @@ -85,9 +85,9 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.9.0 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/signadot/go-sdk v0.3.8-0.20230917202415-61cf5bfada91 h1:DVxA0GXvgVmrlpUo48xd0SDbcXHLO+KkUHkUFbWfSwg=
github.com/signadot/go-sdk v0.3.8-0.20230917202415-61cf5bfada91/go.mod h1:X86A7rI8J//a2T8aKVCCVXxOMBjh32c2GJ50WK7iYzs=
github.com/signadot/go-sdk v0.3.8-0.20231025094337-42064c0da2a0 h1:d0ouDwdrPJWQBhw6KWIP3TOZovnUar3GLfp8NnFDPCY=
github.com/signadot/go-sdk v0.3.8-0.20231025094337-42064c0da2a0/go.mod h1:LRz8QgcijAl1HcxojPD+Ewad9/McFSceyJg2i+9u8nM=
github.com/signadot/go-sdk v0.3.8-0.20231025100955-7260daf67ccc h1:qAisu1I1b4kQKtn3A0JLRrclxIwb0rve+zn4gtStl0I=
github.com/signadot/go-sdk v0.3.8-0.20231025100955-7260daf67ccc/go.mod h1:LRz8QgcijAl1HcxojPD+Ewad9/McFSceyJg2i+9u8nM=
github.com/signadot/libconnect v0.1.1-0.20231011194636-a0941512a00a h1:o+GNGQP7MKm/wX6S/rXoCMVyjSHGVcCtROMpiQLJnJk=
github.com/signadot/libconnect v0.1.1-0.20231011194636-a0941512a00a/go.mod h1:LIU36XBqFs+GlaE05UIJxI7+O/MHISAAMGupQdTAEUE=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down Expand Up @@ -427,14 +429,14 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs=
go.opentelemetry.io/otel v1.18.0/go.mod h1:9lWqYO0Db579XzVuCKFNPDl4s73Voa+zEck3wHaAYQI=
go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvzhtRrSQ=
go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k=
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=
go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM=
go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10=
go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0=
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
Expand Down
1 change: 1 addition & 0 deletions internal/command/cluster/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func New(api *config.API) *cobra.Command {

// Subcommands
cmd.AddCommand(
newGet(cfg),
newAdd(cfg),
newList(cfg),
token.New(cfg),
Expand Down
51 changes: 51 additions & 0 deletions internal/command/cluster/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cluster

import (
"fmt"
"io"

"github.com/signadot/cli/internal/config"
"github.com/signadot/cli/internal/print"
"github.com/signadot/go-sdk/client/cluster"
"github.com/signadot/go-sdk/models"
"github.com/spf13/cobra"
)

func newGet(cluster *config.Cluster) *cobra.Command {
cfg := &config.ClusterGet{Cluster: cluster}

cmd := &cobra.Command{
Use: "get",
Short: "get a cluster",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return get(cfg, cmd.OutOrStdout(), args)
},
}

return cmd
}

func get(cfg *config.ClusterGet, out io.Writer, args []string) error {
if err := cfg.InitAPIConfig(); err != nil {
return err
}
params := cluster.NewGetClusterParams().
WithOrgName(cfg.Org).
WithClusterName(args[0])
resp, err := cfg.Client.Cluster.GetCluster(params, nil)
if err != nil {
return err
}

switch cfg.OutputFormat {
case config.OutputFormatDefault:
return printClusterTable(out, []*models.Cluster{resp.Payload})
case config.OutputFormatJSON:
return print.RawJSON(out, resp.Payload)
case config.OutputFormatYAML:
return print.RawYAML(out, resp.Payload)
default:
return fmt.Errorf("unsupported output format: %q", cfg.OutputFormat)
}
}
23 changes: 17 additions & 6 deletions internal/command/cluster/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@ import (
)

type clusterRow struct {
Name string `sdtab:"NAME"`
Created string `sdtab:"CREATED"`
Version string `sdtab:"OPERATOR VERSION"`
Name string `sdtab:"NAME"`
Created string `sdtab:"CREATED"`
Version string `sdtab:"OPERATOR VERSION"`
LastSync string `sdtab:"LAST SYNC"`
}

func printClusterTable(out io.Writer, clusters []*models.Cluster) error {
t := sdtab.New[clusterRow](out)
t.AddHeader()
for _, cluster := range clusters {
lastSync := "-"
if cluster.SyncStatus != nil {
syncStat := cluster.SyncStatus
if syncStat.LastSync != nil {
if syncStat.LastSync.Time != "" {
lastSync = syncStat.LastSync.Time
}
}
}
t.AddRow(clusterRow{
Name: cluster.Name,
Created: cluster.CreatedAt,
Version: cluster.Operator.Version,
Name: cluster.Name,
Created: cluster.CreatedAt,
Version: cluster.Operator.Version,
LastSync: lastSync,
})
}
return t.Flush()
Expand Down
4 changes: 4 additions & 0 deletions internal/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func (c *ClusterAdd) AddFlags(cmd *cobra.Command) {
type ClusterList struct {
*Cluster
}

type ClusterGet struct {
*Cluster
}