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 7, 2024
1 parent 5fa28b2 commit 81d5a73
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
9 changes: 8 additions & 1 deletion pkg/cmd/roachprod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,14 @@ var pgurlCmd = &cobra.Command{
Short: "generate pgurls for the nodes in a cluster",
Long: `Generate pgurls for the nodes in a cluster.
--auth-mode specifies the method of authentication unless --insecure is passed.
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:
root: authenticates with the root user and root certificates
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 @@ -23,8 +23,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 @@ -158,8 +158,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, DefaultAuthMode)
return url, url != "", err
default:
Expand Down Expand Up @@ -187,8 +187,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 @@ -189,7 +189,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 81d5a73

Please sign in to comment.