-
Notifications
You must be signed in to change notification settings - Fork 116
Retry terraform init on transient 502/503 errors #1840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c8522f8
33635f9
65a9b06
82254bc
72e6de0
ff8c348
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text.RegularExpressions; | ||
| using System.Threading; | ||
| using Calamari.Common.Commands; | ||
| using Calamari.Common.Features.Processes; | ||
| using Calamari.Common.FeatureToggles; | ||
|
|
@@ -12,6 +13,7 @@ | |
| using Calamari.Common.Plumbing.FileSystem; | ||
| using Calamari.Common.Plumbing.Logging; | ||
| using Calamari.Common.Plumbing.Proxies; | ||
| using Calamari.Common.Plumbing.Retry; | ||
| using Calamari.Common.Plumbing.Variables; | ||
| using Calamari.Terraform.Helpers; | ||
| using Newtonsoft.Json; | ||
|
|
@@ -217,10 +219,30 @@ void InitializePlugins() | |
| initCommand += " -no-color"; | ||
| if (Version?.IsLessThan("0.15.0") == true) | ||
| initCommand += $" -get-plugins={allowPluginDownloads.ToString().ToLower()}"; | ||
|
|
||
| initCommand += $" {initParams}"; | ||
|
|
||
| ExecuteCommandAndVerifySuccess(new[] { initCommand }, out _, true); | ||
| var retry = new RetryTracker(maxRetries: 3, timeLimit: null, new LimitedExponentialRetryInterval(2000, 30000, 2)); | ||
| while (retry.Try()) | ||
| { | ||
| var commandResult = ExecuteCommandInternal(new[] { initCommand }, out _, true); | ||
| if (commandResult.ExitCode == 0) | ||
| return; | ||
|
|
||
| if (IsTransientInitError(commandResult.Errors) && retry.CanRetry()) | ||
| { | ||
| log.Warn($"Terraform init failed with a transient error (attempt {retry.CurrentTry} of 4). Retrying after backoff..."); | ||
| Thread.Sleep(retry.Sleep()); | ||
| continue; | ||
| } | ||
|
Comment on lines
+224
to
+236
|
||
|
|
||
| VerifySuccess(commandResult); | ||
| } | ||
| } | ||
|
|
||
| internal static bool IsTransientInitError(string errors) | ||
| { | ||
| if (string.IsNullOrEmpty(errors)) return false; | ||
| return Regex.IsMatch(errors, @"50[23] (Bad Gateway|Service Unavailable)", RegexOptions.IgnoreCase); | ||
| } | ||
|
|
||
| class TerraformVersionCommandOutput | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backoff settings here don't match the PR description (5s, 10s, 20s). With LimitedExponentialRetryInterval(2000, 30000, 2) and RetryTracker.Sleep() using the current try number, the sleeps are 4s, 8s, 16s. Either update the interval parameters to achieve the intended delays, or adjust the PR description/log messaging accordingly.