Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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)
```

<!-- readmegen:cli-help:end -->
17 changes: 13 additions & 4 deletions internal/provisioncheck/provisioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions internal/provisioncheck/provisioncheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading