-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from replicatedhq/joshd/sc-99234/nodegroups-r…
…eplicated-cluster-nodegroup-ls Adding nodegroup ls command
- Loading branch information
Showing
6 changed files
with
150 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitClusterNodeGroup(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "nodegroup", | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/replicated/cli/print" | ||
"github.com/replicatedhq/replicated/pkg/platformclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitClusterNodeGroupList(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "ls [ID]", | ||
Short: "List node groups for a cluster", | ||
Long: `List node groups for a cluster`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: r.listNodeGroups, | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table|wide (default: table)") | ||
|
||
return cmd | ||
} | ||
|
||
func (r *runners) listNodeGroups(cmd *cobra.Command, args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("cluster id is required") | ||
} | ||
clusterID := args[0] | ||
|
||
cluster, err := r.kotsAPI.GetCluster(clusterID) | ||
if errors.Cause(err) == platformclient.ErrForbidden { | ||
return ErrCompatibilityMatrixTermsNotAccepted | ||
} else if err != nil { | ||
return errors.Wrap(err, "get cluster") | ||
} | ||
|
||
return print.NodeGroups(r.outputFormat, r.w, cluster.NodeGroups) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package print | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"text/tabwriter" | ||
"text/template" | ||
|
||
"github.com/replicatedhq/replicated/pkg/types" | ||
) | ||
|
||
var nodeGroupsTmplSrc = `ID NAME DEFAULT INSTANCE TYPE NODES DISK | ||
{{ range . -}} | ||
{{ .ID }} {{ .Name }} {{ .IsDefault }} {{ .InstanceType }} {{.NodeCount}} {{.DiskGiB}} | ||
{{ end }}` | ||
|
||
var nodeGroupsTmpl = template.Must(template.New("nodegroups").Parse(nodeGroupsTmplSrc)) | ||
|
||
func NodeGroups(outputFormat string, w *tabwriter.Writer, addOns []*types.NodeGroup) error { | ||
switch outputFormat { | ||
case "table", "wide": | ||
if err := nodeGroupsTmpl.Execute(w, addOns); err != nil { | ||
return err | ||
} | ||
case "json": | ||
cAsByte, err := json.MarshalIndent(addOns, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
if _, err := fmt.Fprintln(w, string(cAsByte)); err != nil { | ||
return err | ||
} | ||
default: | ||
return fmt.Errorf("unsupported output format: %s", outputFormat) | ||
} | ||
return w.Flush() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters