Skip to content

Commit

Permalink
roachprod: use 'lb' to denote load balancer
Browse files Browse the repository at this point in the history
Previously, `L` was used in the `roachprod` expanders and other place to select
load balancers. This change updates it to `LB` or `lb` to be more explicit. The
help for commands have also been updated to inform the user that an option
exists to select a load balancer.

Epic: None
Release Note: None
  • Loading branch information
herkolategan committed May 3, 2024
1 parent 67f1274 commit c31dbbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions pkg/cmd/roachprod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,13 @@ var pgurlCmd = &cobra.Command{
Short: "generate pgurls for the nodes in a cluster",
Long: `Generate pgurls for the nodes in a cluster.
The command generates postgres urls for the specified nodes in a cluster.
Both the nodes or a load balancer can be specified as the target of the pgurl.
Examples of <cluster>:
cluster-name:1-3
cluster-name:lb
--auth-mode specifies the method of authentication if --secure is passed.
Defaults to root if not passed. Available auth-modes are:
Expand Down
12 changes: 6 additions & 6 deletions pkg/roachprod/install/expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

var parameterRe = regexp.MustCompile(`{[^{}]*}`)
var pgURLRe = regexp.MustCompile(`{pgurl(:[-,0-9]+|:L)?(:[a-z0-9\-]+)?(:[0-9]+)?}`)
var pgHostRe = regexp.MustCompile(`{pghost(:[-,0-9]+|:L)?(:[a-z0-9\-]+)?(:[0-9]+)?}`)
var pgURLRe = regexp.MustCompile(`{pgurl(:[-,0-9]+|:(?i)lb)?(:[a-z0-9\-]+)?(:[0-9]+)?}`)
var pgHostRe = regexp.MustCompile(`{pghost(:[-,0-9]+|:(?i)lb)?(:[a-z0-9\-]+)?(:[0-9]+)?}`)
var pgPortRe = regexp.MustCompile(`{pgport(:[-,0-9]+)?(:[a-z0-9\-]+)?(:[0-9]+)?}`)
var uiPortRe = regexp.MustCompile(`{uiport(:[-,0-9]+)}`)
var storeDirRe = regexp.MustCompile(`{store-dir(:[0-9]+)?}`)
Expand Down Expand Up @@ -157,8 +157,8 @@ func (e *expander) maybeExpandPgURL(
if err != nil {
return "", false, err
}
switch m[1] {
case ":L":
switch strings.ToLower(m[1]) {
case ":lb":
url, err := c.loadBalancerURL(ctx, l, virtualClusterName, sqlInstance, AuthUserCert)
return url, url != "", err
default:
Expand Down Expand Up @@ -186,8 +186,8 @@ func (e *expander) maybeExpandPgHost(
return "", false, err
}

switch m[1] {
case ":L":
switch strings.ToLower(m[1]) {
case ":lb":
services, err := c.DiscoverServices(ctx, virtualClusterName, ServiceTypeSQL, ServiceInstancePredicate(sqlInstance))
if err != nil {
return "", false, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/roachprod/install/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func ListNodes(s string, numNodesInCluster int) (Nodes, error) {
return nil, errors.AssertionFailedf("invalid number of nodes %d", numNodesInCluster)
}

// "L" is a special value that also returns all nodes, but implies a load
// "lb" is a special value that also returns all nodes, but implies a load
// balancer should be used when applicable.
if s == "all" || s == "L" {
if s == "all" || strings.ToLower(s) == "lb" {
return allNodes(numNodesInCluster), nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/roachprod/roachprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func newCluster(
// name is set to select a load balancer.
func preferLoadBalancer(name string) bool {
parts := strings.Split(name, ":")
return len(parts) == 2 && parts[1] == "L"
return len(parts) == 2 && strings.ToLower(parts[1]) == "lb"
}

// userClusterNameRegexp returns a regexp that matches all clusters owned by the
Expand Down

0 comments on commit c31dbbe

Please sign in to comment.