Skip to content

Commit 1668e37

Browse files
committed
fix: retry bootstrap check on on controllers when there are errors
At the moment, when concierge checks for a bootstrapped controller, if the command fails the check is considered a failure, and thus that the controller doesn't exist. In some cases, that is correct, and we can tell that from the error message. In other cases, the check fails because the controller fails to respond. This commit introduces a retry with backoff on that check.
1 parent 086520a commit 1668e37

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

internal/juju/juju.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package juju
22

33
import (
4+
"context"
45
"fmt"
56
"log/slog"
67
"path"
@@ -12,6 +13,7 @@ import (
1213
"github.com/jnsgruk/concierge/internal/packages"
1314
"github.com/jnsgruk/concierge/internal/providers"
1415
"github.com/jnsgruk/concierge/internal/system"
16+
"github.com/sethvargo/go-retry"
1517
"golang.org/x/sync/errgroup"
1618
"gopkg.in/yaml.v3"
1719
)
@@ -264,14 +266,27 @@ func (j *JujuHandler) checkBootstrapped(controllerName string) (bool, error) {
264266
user := j.system.User().Username
265267
cmd := system.NewCommandAs(user, "", "juju", []string{"show-controller", controllerName})
266268

267-
result, err := j.system.Run(cmd)
268-
if err != nil && strings.Contains(string(result), "not found") {
269-
return false, nil
270-
} else if err != nil {
271-
return false, err
272-
}
269+
// Configure a back-off for retrying the assessment of controller status.
270+
backoff := retry.WithMaxRetries(10, retry.NewExponential(1*time.Second))
271+
272+
// Run a function, with retries/backoff, to assess whether the controller exists.
273+
// This retry works around an issue where a given controller may not respond, causing the
274+
// tool to conclude that the controller doesn't exist, rather than the controller simply
275+
// not responding.
276+
return retry.DoValue(context.Background(), backoff, func(ctx context.Context) (bool, error) {
277+
output, err := j.system.Run(cmd)
278+
if err != nil {
279+
// If the error message on checking contains "not found" then the controller
280+
// is not actually there, so don't retry the check.
281+
if strings.Contains(string(output), "not found") {
282+
return false, nil
283+
}
284+
// Otherwise, retry the check for a bootstrapped controller.
285+
return false, retry.RetryableError(err)
286+
}
273287

274-
return true, nil
288+
return true, nil
289+
})
275290
}
276291

277292
// sortedKeys gets an alphabetically sorted list of keys from a map.

0 commit comments

Comments
 (0)