Skip to content

Commit

Permalink
Enable control plane firewall pointer arguments and trim spaces (#1555)
Browse files Browse the repository at this point in the history
* Switch --enable-control-plane-firewall to be a optional boolean

* Trim allowed addresses

* Fix Check spelling CI check

* Use strings.TrimSpace() instead of strings.ReplaceAll()

---------

Co-authored-by: Oliver Love <olove@digitalocean.com>
  • Loading branch information
llDrLove and llDrLove authored Jul 22, 2024
1 parent 88deac4 commit d16c594
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
30 changes: 14 additions & 16 deletions commands/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ After creating a cluster, a configuration context is added to kubectl and made a
"Enables surge-upgrade for the cluster")
AddBoolFlag(cmdKubeClusterCreate, doctl.ArgHA, "", false,
"Creates the cluster with a highly-available control plane. Defaults to false. To enable the HA control plane, supply --ha=true.")
AddStringFlag(cmdKubeClusterCreate, doctl.ArgEnableControlPlaneFirewall, "", "",
AddBoolFlag(cmdKubeClusterCreate, doctl.ArgEnableControlPlaneFirewall, "", false,
"Creates the cluster with control plane firewall enabled. Defaults to false. To enable the control plane firewall, supply --enable-control-plane-firewall=true.")
AddStringSliceFlag(cmdKubeClusterCreate, doctl.ArgControlPlaneFirewallAllowedAddresses, "", nil,
"A comma-separated list of allowed addresses that can access the control plane.")
Expand Down Expand Up @@ -333,7 +333,7 @@ Updates the configuration values for a Kubernetes cluster. The cluster must be r
"Enables surge-upgrade for the cluster")
AddBoolFlag(cmdKubeClusterUpdate, doctl.ArgHA, "", false,
"Enables the highly-available control plane for the cluster")
AddStringFlag(cmdKubeClusterUpdate, doctl.ArgEnableControlPlaneFirewall, "", "",
AddBoolFlag(cmdKubeClusterUpdate, doctl.ArgEnableControlPlaneFirewall, "", false,
"Creates the cluster with control plane firewall enabled. Defaults to false. To enable the control plane firewall, supply --enable-control-plane-firewall=true.")
AddStringSliceFlag(cmdKubeClusterUpdate, doctl.ArgControlPlaneFirewallAllowedAddresses, "", nil,
"A comma-separated list of allowed addresses that can access the control plane.")
Expand Down Expand Up @@ -1657,17 +1657,13 @@ func buildClusterCreateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterCr
}
r.HA = ha

enableControlPlaneFirewall, err := c.Doit.GetString(c.NS, doctl.ArgEnableControlPlaneFirewall)
enableControlPlaneFirewall, err := c.Doit.GetBoolPtr(c.NS, doctl.ArgEnableControlPlaneFirewall)
if err != nil {
return err
}
if enableControlPlaneFirewall != "" {
enableControlPlaneFirewallBool, err := strconv.ParseBool(enableControlPlaneFirewall)
if err != nil {
return err
}
if enableControlPlaneFirewall != nil {
r.ControlPlaneFirewall = &godo.KubernetesControlPlaneFirewall{
Enabled: &enableControlPlaneFirewallBool,
Enabled: enableControlPlaneFirewall,
}
}

Expand All @@ -1679,6 +1675,9 @@ func buildClusterCreateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterCr
if r.ControlPlaneFirewall == nil {
r.ControlPlaneFirewall = &godo.KubernetesControlPlaneFirewall{}
}
for i := range controlPlaneFirewallAllowedAddresses {
controlPlaneFirewallAllowedAddresses[i] = strings.TrimSpace(controlPlaneFirewallAllowedAddresses[i])
}
r.ControlPlaneFirewall.AllowedAddresses = controlPlaneFirewallAllowedAddresses
}

Expand Down Expand Up @@ -1772,17 +1771,13 @@ func buildClusterUpdateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterUp
}
r.HA = ha

enableControlPlaneFirewall, err := c.Doit.GetString(c.NS, doctl.ArgEnableControlPlaneFirewall)
enableControlPlaneFirewall, err := c.Doit.GetBoolPtr(c.NS, doctl.ArgEnableControlPlaneFirewall)
if err != nil {
return err
}
if enableControlPlaneFirewall != "" {
enableControlPlaneFirewallBool, err := strconv.ParseBool(enableControlPlaneFirewall)
if err != nil {
return err
}
if enableControlPlaneFirewall != nil {
r.ControlPlaneFirewall = &godo.KubernetesControlPlaneFirewall{
Enabled: &enableControlPlaneFirewallBool,
Enabled: enableControlPlaneFirewall,
}
}

Expand All @@ -1794,6 +1789,9 @@ func buildClusterUpdateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterUp
if r.ControlPlaneFirewall == nil {
r.ControlPlaneFirewall = &godo.KubernetesControlPlaneFirewall{}
}
for i := range controlPlaneFirewallAllowedAddresses {
controlPlaneFirewallAllowedAddresses[i] = strings.TrimSpace(controlPlaneFirewallAllowedAddresses[i])
}
r.ControlPlaneFirewall.AllowedAddresses = controlPlaneFirewallAllowedAddresses
}

Expand Down
3 changes: 2 additions & 1 deletion commands/volume_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package commands
import (
"strconv"

"github.com/spf13/cobra"

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/commands/displayers"
"github.com/digitalocean/doctl/do"
"github.com/spf13/cobra"
)

type volumeActionFn func(das do.VolumeActionsService) (*do.Action, error)
Expand Down

0 comments on commit d16c594

Please sign in to comment.