From eccfc2dc2304349629d3498428fcc790995afd02 Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Mon, 26 Feb 2024 15:24:16 -0500 Subject: [PATCH 1/2] Make regions and plans printers consistent (#412) * Make `plan` use marshal function * Remove meta struct from `regions availability` list --- cmd/plans/printer.go | 30 ++++++------------------------ cmd/regions/printer.go | 3 +-- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/cmd/plans/printer.go b/cmd/plans/printer.go index ae4c9acc..51850266 100644 --- a/cmd/plans/printer.go +++ b/cmd/plans/printer.go @@ -1,13 +1,11 @@ package plans import ( - "encoding/json" "strconv" "github.com/vultr/govultr/v3" "github.com/vultr/vultr-cli/v3/cmd/printer" "github.com/vultr/vultr-cli/v3/cmd/utils" - "gopkg.in/yaml.v3" ) // PlansPrinter represents the plans data from the API @@ -18,21 +16,12 @@ type PlansPrinter struct { // JSON provides the JSON formatted byte data func (p *PlansPrinter) JSON() []byte { - js, err := json.MarshalIndent(p, "", " ") - if err != nil { - panic(err.Error()) - } - - return js + return printer.MarshalObject(p, "json") } // YAML provides the YAML formatted byte data func (p *PlansPrinter) YAML() []byte { - yml, err := yaml.Marshal(p) - if err != nil { - panic(err.Error()) - } - return yml + return printer.MarshalObject(p, "yaml") } // Columns provides the plan columns for the printer @@ -85,6 +74,8 @@ func (p *PlansPrinter) Paging() [][]string { return printer.NewPaging(p.Meta.Total, &p.Meta.Links.Next, &p.Meta.Links.Prev).Compose() } +// ====================================== + // MetalPlansPrinter represents the bare metal plans data from the API type MetalPlansPrinter struct { Plans []govultr.BareMetalPlan `json:"plans_metal"` @@ -93,21 +84,12 @@ type MetalPlansPrinter struct { // JSON provides the JSON formatted byte data func (m *MetalPlansPrinter) JSON() []byte { - js, err := json.MarshalIndent(m, "", " ") - if err != nil { - panic(err.Error()) - } - - return js + return printer.MarshalObject(m, "json") } // YAML provides the YAML formatted byte data func (m *MetalPlansPrinter) YAML() []byte { - yml, err := yaml.Marshal(m) - if err != nil { - panic(err.Error()) - } - return yml + return printer.MarshalObject(m, "yaml") } // Columns provides the plan columns for the printer diff --git a/cmd/regions/printer.go b/cmd/regions/printer.go index 34d2724c..e426406b 100644 --- a/cmd/regions/printer.go +++ b/cmd/regions/printer.go @@ -67,7 +67,6 @@ func (r *RegionsPrinter) Paging() [][]string { // via the ResourceOutput interface type RegionsAvailabilityPrinter struct { Plans *govultr.PlanAvailability `json:"available_plans"` - Meta *govultr.Meta `json:"meta"` } // JSON provides the JSON formatted byte data @@ -107,5 +106,5 @@ func (r *RegionsAvailabilityPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (r *RegionsAvailabilityPrinter) Paging() [][]string { - return printer.NewPaging(r.Meta.Total, &r.Meta.Links.Next, &r.Meta.Links.Prev).Compose() + return nil } From 30dfcfdd91198302b523a5de50794ecdbcf53237 Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Mon, 26 Feb 2024 15:48:47 -0500 Subject: [PATCH 2/2] Add kubernetes `enable-firewall` flag on create (#413) --- cmd/kubernetes/kubernetes.go | 13 +++++++++++++ cmd/kubernetes/printer.go | 2 ++ 2 files changed, 15 insertions(+) diff --git a/cmd/kubernetes/kubernetes.go b/cmd/kubernetes/kubernetes.go index 83f1dccd..0819abbe 100644 --- a/cmd/kubernetes/kubernetes.go +++ b/cmd/kubernetes/kubernetes.go @@ -335,6 +335,11 @@ func NewCmdKubernetes(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo return fmt.Errorf("error parsing flag 'high-avail' for kubernetes cluster create : %v", errHi) } + fw, errFw := cmd.Flags().GetBool("enable-firewall") + if errHi != nil { + return fmt.Errorf("error parsing flag 'enable-firewall' for kubernetes cluster create : %v", errFw) + } + nps, errFm := formatNodePools(nodepools) if errFm != nil { return fmt.Errorf("error in node pool formating : %v", errFm) @@ -346,6 +351,7 @@ func NewCmdKubernetes(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo NodePools: nps, Version: version, HAControlPlanes: ha, + EnableFirewall: fw, } k8, err := o.create() @@ -385,6 +391,13 @@ func NewCmdKubernetes(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo highly available, control planes`, ) + create.Flags().BoolP( + "enable-firewall", + "f", + false, + `(optional, default false) whether a firewall group should be created for the cluster`, + ) + create.Flags().StringArrayP( "node-pools", "n", diff --git a/cmd/kubernetes/printer.go b/cmd/kubernetes/printer.go index e567e5bc..469f7572 100644 --- a/cmd/kubernetes/printer.go +++ b/cmd/kubernetes/printer.go @@ -111,6 +111,7 @@ func (c *ClustersPrinter) Data() [][]string { []string{"IP", c.Clusters[i].IP}, []string{"ENDPOINT", c.Clusters[i].Endpoint}, []string{"HIGH AVAIL", strconv.FormatBool(c.Clusters[i].HAControlPlanes)}, + []string{"FIREWALL GROUP ID", c.Clusters[i].FirewallGroupID}, []string{"VERSION", c.Clusters[i].Version}, []string{"REGION", c.Clusters[i].Region}, []string{"STATUS", c.Clusters[i].Status}, @@ -197,6 +198,7 @@ func (c *ClusterPrinter) Data() [][]string { []string{"IP", c.Cluster.IP}, []string{"ENDPOINT", c.Cluster.Endpoint}, []string{"HIGH AVAIL", strconv.FormatBool(c.Cluster.HAControlPlanes)}, + []string{"FIREWALL GROUP ID", c.Cluster.FirewallGroupID}, []string{"VERSION", c.Cluster.Version}, []string{"REGION", c.Cluster.Region}, []string{"STATUS", c.Cluster.Status},