Skip to content

Commit f0da5e8

Browse files
committed
roachprod: fix confusing start-up error
Starting a cluster locally does a check for certificates. In the event the certificates are not found, which is a valid case, an error is printed. The start command works correctly, but the error can cause confusion: ```bash /bin/roachprod start local --secure 12:47:56 cluster_synced.go:2475: 0: COMMAND_PROBLEM: exit status 1 (1) COMMAND_PROBLEM Wraps: (2) exit status 1 Error types: (1) errors.Cmd (2) *exec.ExitError: local: initializing certs 1/1 / local: distributing certs 2/2 ``` This change modifies the command to do a check without causing an error, and also propagates any real errors that could occur while doing the check.
1 parent 6693bef commit f0da5e8

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

pkg/roachprod/install/cluster_synced.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,9 @@ const (
12991299
// DistributeCerts will generate and distribute certificates to all of the
13001300
// nodes.
13011301
func (c *SyncedCluster) DistributeCerts(ctx context.Context, l *logger.Logger) error {
1302-
if c.checkForCertificates(ctx, l) {
1302+
if found, err := c.checkForCertificates(ctx, l); err != nil {
1303+
return err
1304+
} else if found {
13031305
return nil
13041306
}
13051307

@@ -1375,11 +1377,15 @@ tar cvf %[3]s certs
13751377
func (c *SyncedCluster) DistributeTenantCerts(
13761378
ctx context.Context, l *logger.Logger, hostCluster *SyncedCluster, tenantID int,
13771379
) error {
1378-
if hostCluster.checkForTenantCertificates(ctx, l) {
1380+
if found, err := hostCluster.checkForTenantCertificates(ctx, l); err != nil {
1381+
return err
1382+
} else if found {
13791383
return nil
13801384
}
13811385

1382-
if !hostCluster.checkForCertificates(ctx, l) {
1386+
if found, err := hostCluster.checkForCertificates(ctx, l); err != nil {
1387+
return err
1388+
} else if !found {
13831389
return errors.New("host cluster missing certificate bundle")
13841390
}
13851391

@@ -1489,7 +1495,7 @@ func (c *SyncedCluster) getFileFromFirstNode(
14891495

14901496
// checkForCertificates checks if the cluster already has a certs bundle created
14911497
// on the first node.
1492-
func (c *SyncedCluster) checkForCertificates(ctx context.Context, l *logger.Logger) bool {
1498+
func (c *SyncedCluster) checkForCertificates(ctx context.Context, l *logger.Logger) (bool, error) {
14931499
dir := ""
14941500
if c.IsLocal() {
14951501
dir = c.localVMDir(1)
@@ -1499,7 +1505,9 @@ func (c *SyncedCluster) checkForCertificates(ctx context.Context, l *logger.Logg
14991505

15001506
// checkForTenantCertificates checks if the cluster already has a tenant-certs bundle created
15011507
// on the first node.
1502-
func (c *SyncedCluster) checkForTenantCertificates(ctx context.Context, l *logger.Logger) bool {
1508+
func (c *SyncedCluster) checkForTenantCertificates(
1509+
ctx context.Context, l *logger.Logger,
1510+
) (bool, error) {
15031511
dir := ""
15041512
if c.IsLocal() {
15051513
dir = c.localVMDir(1)
@@ -1509,24 +1517,10 @@ func (c *SyncedCluster) checkForTenantCertificates(ctx context.Context, l *logge
15091517

15101518
func (c *SyncedCluster) fileExistsOnFirstNode(
15111519
ctx context.Context, l *logger.Logger, path string,
1512-
) bool {
1513-
var existsErr error
1514-
display := fmt.Sprintf("%s: checking %s", c.Name, path)
1515-
if err := c.Parallel(ctx, l, 1, func(ctx context.Context, i int) (*RunResultDetails, error) {
1516-
node := c.Nodes[i]
1517-
sess := c.newSession(l, node, `test -e `+path)
1518-
defer sess.Close()
1519-
1520-
out, cmdErr := sess.CombinedOutput(ctx)
1521-
res := newRunResultDetails(node, cmdErr)
1522-
res.CombinedOut = out
1523-
1524-
existsErr = res.Err
1525-
return res, nil
1526-
}, WithDisplay(display)); err != nil {
1527-
return false
1528-
}
1529-
return existsErr == nil
1520+
) (bool, error) {
1521+
l.Printf("%s: checking %s", c.Name, path)
1522+
result, err := c.runCmdOnSingleNode(ctx, l, c.Nodes[0], `$(test -e `+path+`); echo $?`, false, l.Stdout, l.Stderr)
1523+
return result.Stdout == "0", err
15301524
}
15311525

15321526
// createNodeCertArguments returns a list of strings appropriate for use as

0 commit comments

Comments
 (0)