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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Download the latest binary from the [releases page](https://github.com/cloudoper

```sh
# macOS / Linux
curl -Lo cloudctl https://github.com/cloudoperators/cloudctl/releases/latest/download/cloudctl-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)
curl -L https://github.com/cloudoperators/cloudctl/releases/latest/download/cloudctl_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m).tar.gz | tar -xz cloudctl
chmod +x cloudctl
sudo mv cloudctl /usr/local/bin/
```
Expand Down
83 changes: 35 additions & 48 deletions cmd/output/interactive_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,45 @@ func (p *interactivePrinter) printSyncResult(r SyncResult) error {
w("\n")
}

// Collect only clusters that need attention.
// Collect only clusters that need attention (failed; skipped/not-ready are expected).
var issues []ClusterSyncResult
for _, c := range r.Clusters {
if c.Status != ClusterSyncStatusSynced {
if c.Status == ClusterSyncStatusFailed {
issues = append(issues, c)
}
}

// Progress bar (or empty-state message).
if total == 0 {
w("%s\n", styleFaint.Render("No clusters found to sync."))
} else {
const barWidth = 32
filled := (r.Synced * barWidth) / total
bar := styleGreen.Render(strings.Repeat("█", filled)) +
styleFaint.Render(strings.Repeat("░", barWidth-filled))

var annotation string
switch {
case r.Failed > 0 && r.Skipped > 0:
annotation = fmt.Sprintf("%s %s",
styleFaint.Render(fmt.Sprintf("%d clusters skipped (not ready — run with --include-not-ready to force)", r.Skipped)),
styleRed.Render(fmt.Sprintf("%d failed", r.Failed)),
)
case r.Failed > 0:
annotation = styleRed.Render(fmt.Sprintf("%d failed", r.Failed))
case r.Skipped > 0:
annotation = styleFaint.Render(fmt.Sprintf("%d clusters skipped (not ready — run with --include-not-ready to force)", r.Skipped))
default:
annotation = styleGreen.Render("All clusters synced successfully.")
}

w(" %s %s/%d %s · %s\n\n", bar,
styleGreen.Render(fmt.Sprintf("%d", r.Synced)), total,
styleBold.Render("Synced"),
annotation,
)
}

if len(issues) > 0 {
const (
colCluster = 30
Expand All @@ -208,65 +239,21 @@ func (p *interactivePrinter) printSyncResult(r SyncResult) error {
w("%s\n", styleHeader.Render(header))

for _, c := range issues {
var icon, statusStr string
switch c.Status {
case ClusterSyncStatusFailed:
icon = styleRed.Render("✗")
statusStr = styleRed.Render("failed")
default:
icon = styleYellow.Render("!")
statusStr = styleYellow.Render("skipped")
}

name := c.Name
if len(name) > colCluster-2 {
name = name[:colCluster-5] + "..."
}
reason := c.Reason
if reason == "" {
if c.Status == ClusterSyncStatusSkipped {
reason = "not ready"
} else {
reason = "unknown error"
}
reason = "unknown error"
}

w("%s %-*s %-*s %s\n",
icon, colCluster-1, name, colStatus, statusStr, reason,
styleRed.Render("✗"), colCluster-1, name, colStatus, styleRed.Render("failed"), reason,
)
}
w("\n")
}

// Summary sentence.
var summary string
switch {
case total == 0:
summary = styleFaint.Render("No clusters found to sync.")
case r.Failed > 0 && r.Skipped > 0:
summary = fmt.Sprintf("%s %s %s",
styleGreen.Render(fmt.Sprintf("Synced %d of %d cluster(s).", r.Synced, total)),
styleYellow.Render(fmt.Sprintf("%d skipped,", r.Skipped)),
styleRed.Render(fmt.Sprintf("%d failed.", r.Failed)),
)
case r.Failed > 0:
summary = fmt.Sprintf("%s %s",
styleGreen.Render(fmt.Sprintf("Synced %d of %d cluster(s).", r.Synced, total)),
styleRed.Render(fmt.Sprintf("%d failed.", r.Failed)),
)
case r.Skipped > 0:
summary = fmt.Sprintf("%s %s",
styleGreen.Render(fmt.Sprintf("Synced %d of %d cluster(s).", r.Synced, total)),
styleYellow.Render(fmt.Sprintf("%d skipped (not ready).", r.Skipped)),
)
default:
if total == 1 {
summary = styleGreen.Render("Synced 1 cluster successfully.")
} else {
summary = styleGreen.Render(fmt.Sprintf("Synced all %d clusters successfully.", total))
}
}
w("%s\n", summary)
return writeErr
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ func TestPlainPrinter_SyncResult(t *testing.T) {
out := buf.String()
// Synced clusters are not listed individually.
g.Expect(out).ToNot(ContainSubstring("[+]"))
// Skipped and failed clusters appear with their reason.
g.Expect(out).To(ContainSubstring("[-] b"))
// Skipped (not ready) clusters are not listed — only failed ones appear.
g.Expect(out).ToNot(ContainSubstring("[-] b"))
g.Expect(out).To(ContainSubstring("[!] c"))
g.Expect(out).To(ContainSubstring("error"))
// Summary is a human-readable sentence.
g.Expect(out).To(ContainSubstring("Synced 1 of 3"))
g.Expect(out).To(ContainSubstring("1 skipped"))
g.Expect(out).To(ContainSubstring("1 not ready"))
g.Expect(out).To(ContainSubstring("1 failed"))
}

Expand Down
10 changes: 2 additions & 8 deletions cmd/output/plain_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ func (p *plainPrinter) Print(v any) error {
// List clusters that need attention first.
for _, c := range t.Clusters {
switch c.Status {
case ClusterSyncStatusSkipped:
reason := c.Reason
if reason == "" {
reason = "not ready"
}
w(" [-] %s — skipped (%s)\n", c.Name, reason)
case ClusterSyncStatusFailed:
reason := c.Reason
if reason == "" {
Expand All @@ -61,13 +55,13 @@ func (p *plainPrinter) Print(v any) error {
// Summary sentence.
switch {
case t.Failed > 0 && t.Skipped > 0:
w("Synced %d of %d cluster(s). %d skipped, %d failed.\n",
w("Synced %d of %d cluster(s). %d not ready, %d failed.\n",
t.Synced, total, t.Skipped, t.Failed)
case t.Failed > 0:
w("Synced %d of %d cluster(s). %d failed.\n",
t.Synced, total, t.Failed)
case t.Skipped > 0:
w("Synced %d of %d cluster(s). %d skipped (not ready).\n",
w("Synced %d of %d cluster(s). %d not ready.\n",
t.Synced, total, t.Skipped)
default:
if total == 1 {
Expand Down
32 changes: 16 additions & 16 deletions cmd/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,34 +1060,34 @@ func TestResolveDisplaySources(t *testing.T) {
sep := string(os.PathListSeparator)

tests := []struct {
name string
explicitPath string
kubeconfig string
wantSources string
name string
explicitPath string
kubeconfig string
wantSources string
}{
{
name: "explicit path returned as-is",
name: "explicit path returned as-is",
explicitPath: "/explicit/kubeconfig",
kubeconfig: "/env/kubeconfig",
wantSources: "/explicit/kubeconfig",
kubeconfig: "/env/kubeconfig",
wantSources: "/explicit/kubeconfig",
},
{
name: "single KUBECONFIG entry returned as-is",
name: "single KUBECONFIG entry returned as-is",
explicitPath: "",
kubeconfig: "/single/kubeconfig",
wantSources: "/single/kubeconfig",
kubeconfig: "/single/kubeconfig",
wantSources: "/single/kubeconfig",
},
{
name: "multi-file KUBECONFIG: full list returned",
name: "multi-file KUBECONFIG: full list returned",
explicitPath: "",
kubeconfig: "/first" + sep + "/second" + sep + "/third",
wantSources: "/first" + sep + "/second" + sep + "/third",
kubeconfig: "/first" + sep + "/second" + sep + "/third",
wantSources: "/first" + sep + "/second" + sep + "/third",
},
{
name: "empty KUBECONFIG falls back to default",
name: "empty KUBECONFIG falls back to default",
explicitPath: "",
kubeconfig: "",
wantSources: clientcmd.RecommendedHomeFile,
kubeconfig: "",
wantSources: clientcmd.RecommendedHomeFile,
},
}

Expand Down
Loading