Skip to content

Commit

Permalink
doctl/commands: Load Balancers updates (#1307)
Browse files Browse the repository at this point in the history
* doctl/commands: move Load Balancers forwarding rules details to embedded file

* doctl/commands: add UDP protocol to Load Balancer docs

This has been released for a while.

* doctl/commands: add HTTP/3 protocol to Load Balancer docs

This is currently in beta.

* doctl/commands: move Load Balancers details to embedded file

Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
  • Loading branch information
anitgandhi and andrewsomething authored Nov 15, 2022
1 parent c0ae193 commit 076f589
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
6 changes: 6 additions & 0 deletions commands/forwarding_detail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- `entry_protocol`: The entry protocol used for traffic to the load balancer. Possible values are: `http`, `https`, `http2`, `http3`, `tcp`, or `udp`.
- `entry_port`: The entry port used for incoming traffic to the load balancer.
- `target_protocol`: The target protocol used for traffic from the load balancer to the backend Droplets. Possible values are: `http`, `https`, `http2`, `http3`, `tcp`, or `udp`.
- `target_port`: The target port used to send traffic from the load balancer to the backend Droplets.
- `certificate_id`: The ID of the TLS certificate used for SSL termination, if enabled. Can be obtained with `doctl certificate list`
- `tls_passthrough`: Whether SSL passthrough is enabled on the load balancer.
15 changes: 15 additions & 0 deletions commands/lb_detail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- The load balancer's ID
- The load balancer's name
- The load balancer's IP address
- The load balancer's traffic algorithm. Must
be either `round_robin` or `least_connections`
- The current state of the load balancer. This can be `new`, `active`, or `errored`.
- The load balancer's creation date, in ISO8601 combined date and time format.
- The load balancer's forwarding rules. See `doctl compute load-balancer add-forwarding-rules --help` for a list.
- The `health_check` settings for the load balancer.
- The `sticky_sessions` settings for the load balancer.
- The datacenter region the load balancer is located in.
- The Droplet tag corresponding to the Droplets assigned to the load balancer.
- The IDs of the Droplets assigned to the load balancer.
- Whether HTTP request to the load balancer on port 80 will be redirected to HTTPS on port 443.
- Whether the PROXY protocol is in use on the load balancer.
47 changes: 15 additions & 32 deletions commands/load_balancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package commands

import (
_ "embed"
"fmt"
"os"
"reflect"
Expand All @@ -28,6 +29,14 @@ import (
"github.com/spf13/cobra"
)

var (
//go:embed forwarding_detail.txt
forwardingDetail string

//go:embed lb_detail.txt
lbDetail string
)

// LoadBalancer creates the load balancer command.
func LoadBalancer() *Command {
cmd := &Command{
Expand All @@ -39,39 +48,13 @@ func LoadBalancer() *Command {
With the load-balancer command, you can list, create, or delete load balancers, and manage their configuration details.`,
},
}
lbDetail := `
- The load balancer's ID
- The load balancer's name
- The load balancer's IP address
- The load balancer's traffic algorithm. Must
be either ` + "`" + `round_robin` + "`" + ` or ` + "`" + `least_connections` + "`" + `
- The current state of the load balancer. This can be ` + "`" + `new` + "`" + `, ` + "`" + `active` + "`" + `, or ` + "`" + `errored` + "`" + `.
- The load balancer's creation date, in ISO8601 combined date and time format.
- The load balancer's forwarding rules. See ` + "`" + `doctl compute load-balancer add-forwarding-rules --help` + "`" + ` for a list.
- The ` + "`" + `health_check` + "`" + ` settings for the load balancer.
- The ` + "`" + `sticky_sessions` + "`" + ` settings for the load balancer.
- The datacenter region the load balancer is located in.
- The Droplet tag corresponding to the Droplets assigned to the load balancer.
- The IDs of the Droplets assigned to the load balancer.
- Whether HTTP request to the load balancer on port 80 will be redirected to HTTPS on port 443.
- Whether the PROXY protocol is in use on the load balancer.
`
forwardingDetail := `
- ` + "`" + `entry_protocol` + "`" + `: The entry protocol used for traffic to the load balancer. Possible values are: ` + "`" + `http` + "`" + `, ` + "`" + `https` + "`" + `, ` + "`" + `http2` + "`" + `, or ` + "`" + `tcp` + "`" + `.
- ` + "`" + `entry_port` + "`" + `: The entry port used for incoming traffic to the load balancer.
- ` + "`" + `target_protocol` + "`" + `: The target protocol used for traffic from the load balancer to the backend Droplets. Possible values are: ` + "`" + `http` + "`" + `, ` + "`" + `https` + "`" + `, ` + "`" + `http2` + "`" + `, or ` + "`" + `tcp` + "`" + `.
- ` + "`" + `target_port` + "`" + `: The target port used to send traffic from the load balancer to the backend Droplets.
- ` + "`" + `certificate_id` + "`" + `: The ID of the TLS certificate used for SSL termination, if enabled. Can be obtained with ` + "`" + `doctl certificate list` + "`" + `
- ` + "`" + `tls_passthrough` + "`" + `: Whether SSL passthrough is enabled on the load balancer.
`

forwardingRulesTxt := "A comma-separated list of key-value pairs representing forwarding rules, which define how traffic is routed, e.g.: `entry_protocol:tcp,entry_port:3306,target_protocol:tcp,target_port:3306`."
CmdBuilder(cmd, RunLoadBalancerGet, "get <id>", "Retrieve a load balancer", "Use this command to retrieve information about a load balancer instance, including:"+lbDetail, Writer,
CmdBuilder(cmd, RunLoadBalancerGet, "get <id>", "Retrieve a load balancer", "Use this command to retrieve information about a load balancer instance, including:\n\n"+lbDetail, Writer,
aliasOpt("g"), displayerType(&displayers.LoadBalancer{}))

cmdRecordCreate := CmdBuilder(cmd, RunLoadBalancerCreate, "create",
"Create a new load balancer", "Use this command to create a new load balancer on your account. Valid forwarding rules are:"+forwardingDetail, Writer, aliasOpt("c"))
"Create a new load balancer", "Use this command to create a new load balancer on your account. Valid forwarding rules are:\n"+forwardingDetail, Writer, aliasOpt("c"))
AddStringFlag(cmdRecordCreate, doctl.ArgLoadBalancerName, "", "",
"The load balancer's name", requiredOpt())
AddStringFlag(cmdRecordCreate, doctl.ArgRegionSlug, "", "",
Expand Down Expand Up @@ -132,7 +115,7 @@ With the load-balancer command, you can list, create, or delete load balancers,
AddBoolFlag(cmdRecordUpdate, doctl.ArgDisableLetsEncryptDNSRecords, "", false,
"disable automatic DNS record creation for Let's Encrypt certificates that are added to the load balancer")

CmdBuilder(cmd, RunLoadBalancerList, "list", "List load balancers", "Use this command to get a list of the load balancers on your account, including the following information for each:"+lbDetail, Writer,
CmdBuilder(cmd, RunLoadBalancerList, "list", "List load balancers", "Use this command to get a list of the load balancers on your account, including the following information for each:\n\n"+lbDetail, Writer,
aliasOpt("ls"), displayerType(&displayers.LoadBalancer{}))

cmdRunRecordDelete := CmdBuilder(cmd, RunLoadBalancerDelete, "delete <id>",
Expand All @@ -151,11 +134,11 @@ With the load-balancer command, you can list, create, or delete load balancers,
"A comma-separated list of IDs of Droplets to remove from the load balancer, example value: `12,33`")

cmdAddForwardingRules := CmdBuilder(cmd, RunLoadBalancerAddForwardingRules,
"add-forwarding-rules <id>", "Add forwarding rules to a load balancer", "Use this command to add forwarding rules to a load balancer, specified with the `--forwarding-rules` flag. Valid rules include:"+forwardingDetail, Writer)
"add-forwarding-rules <id>", "Add forwarding rules to a load balancer", "Use this command to add forwarding rules to a load balancer, specified with the `--forwarding-rules` flag. Valid rules include:\n"+forwardingDetail, Writer)
AddStringFlag(cmdAddForwardingRules, doctl.ArgForwardingRules, "", "", forwardingRulesTxt)

cmdRemoveForwardingRules := CmdBuilder(cmd, RunLoadBalancerRemoveForwardingRules,
"remove-forwarding-rules <id>", "Remove forwarding rules from a load balancer", "Use this command to remove forwarding rules from a load balancer, specified with the `--forwarding-rules` flag. Valid rules include:"+forwardingDetail, Writer)
"remove-forwarding-rules <id>", "Remove forwarding rules from a load balancer", "Use this command to remove forwarding rules from a load balancer, specified with the `--forwarding-rules` flag. Valid rules include:\n"+forwardingDetail, Writer)
AddStringFlag(cmdRemoveForwardingRules, doctl.ArgForwardingRules, "", "", forwardingRulesTxt)

return cmd
Expand Down

0 comments on commit 076f589

Please sign in to comment.