diff --git a/README.md b/README.md index 5e06288..248a8c6 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Flags: --timeout-reboot-os duration Timeout for rebooting into installed OS (default 45s) --timeout-reboot-rescue duration Timeout for requesting reboot to rescue (default 45s) --timeout-wait-os duration Timeout for waiting until installed OS is reachable (default 6m0s) - --timeout-wait-rescue duration Timeout for waiting until rescue SSH is reachable (default 6m0s) + --timeout-wait-rescue duration Timeout for waiting until rescue SSH is reachable (default 8m0s) ``` ### `caphcli create-host-yaml --help` @@ -123,7 +123,7 @@ Flags: --timeout-fetch-server duration Timeout for fetching server details from Robot (default 30s) --timeout-load-input duration Timeout for env loading + initial validation (default 30s) --timeout-reboot-rescue duration Timeout for requesting reboot to rescue (default 45s) - --timeout-wait-rescue duration Timeout for waiting until rescue SSH is reachable (default 6m0s) + --timeout-wait-rescue duration Timeout for waiting until rescue SSH is reachable (default 8m0s) ``` diff --git a/internal/provisioncheck/provisioncheck.go b/internal/provisioncheck/provisioncheck.go index c94f5c2..27927c5 100644 --- a/internal/provisioncheck/provisioncheck.go +++ b/internal/provisioncheck/provisioncheck.go @@ -62,7 +62,7 @@ const ( // DefaultRebootToRescueTimeout is the default timeout for requesting the reboot into rescue. DefaultRebootToRescueTimeout = 45 * time.Second // DefaultWaitForRescueTimeout is the default timeout for waiting until rescue SSH is reachable. - DefaultWaitForRescueTimeout = 6 * time.Minute + DefaultWaitForRescueTimeout = 8 * time.Minute // DefaultCheckDiskInRescueTimeout is the default timeout for smartctl disk checks in rescue. DefaultCheckDiskInRescueTimeout = 1 * time.Minute // DefaultInstallUbuntuTimeout is the default timeout for one installimage run. @@ -72,8 +72,9 @@ const ( // DefaultWaitForOSTimeout is the default timeout for waiting until the installed OS is reachable. DefaultWaitForOSTimeout = 6 * time.Minute - rescueHostName = "rescue" - sshPort = 22 + stepWarningThresholdPercent = 80.0 + rescueHostName = "rescue" + sshPort = 22 ) // Timeouts contains per-step timeouts for the provision check workflow. @@ -1110,7 +1111,7 @@ func (r *runner) runStep(ctx context.Context, name string, timeout time.Duration if used > 100 { used = 100 } - msg := fmt.Sprintf(format, args...) + msg := fmt.Sprintf("%s%s", stepWarningPrefix(used), fmt.Sprintf(format, args...)) r.logf("step=%s state=running elapsed=%s used=%.1f%% remaining=%s %s", name, formatMinSec(elapsed), used, formatMinSec(remaining), msg) } @@ -1151,6 +1152,14 @@ func (r *runner) logf(format string, args ...any) { _, _ = fmt.Fprintf(r.out, "overall=%s %s\n", overall, fmt.Sprintf(format, args...)) } +func stepWarningPrefix(used float64) string { + if used >= stepWarningThresholdPercent { + return "⚠️ " + } + + return "" +} + func formatMinSec(d time.Duration) string { if d < 0 { d = 0 diff --git a/internal/provisioncheck/provisioncheck_test.go b/internal/provisioncheck/provisioncheck_test.go index 4106113..2f62895 100644 --- a/internal/provisioncheck/provisioncheck_test.go +++ b/internal/provisioncheck/provisioncheck_test.go @@ -21,10 +21,55 @@ import ( "path/filepath" "strings" "testing" + "time" infrav1 "github.com/syself/cluster-api-provider-hetzner/api/v1beta1" ) +func TestDefaultConfigWaitForRescueTimeout(t *testing.T) { + t.Parallel() + + if got, want := DefaultConfig().Timeouts.WaitForRescue, 8*time.Minute; got != want { + t.Fatalf("DefaultConfig().Timeouts.WaitForRescue = %s, want %s", got, want) + } +} + +func TestStepWarningPrefix(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + used float64 + want string + }{ + { + name: "below threshold", + used: 79.9, + want: "", + }, + { + name: "at threshold", + used: 80.0, + want: "⚠️ ", + }, + { + name: "above threshold", + used: 95.5, + want: "⚠️ ", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + if got := stepWarningPrefix(tt.used); got != tt.want { + t.Fatalf("stepWarningPrefix(%v) = %q, want %q", tt.used, got, tt.want) + } + }) + } +} + func TestLoadHostsFromHBMHYAMLFile(t *testing.T) { t.Parallel()