Skip to content
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

Display formatted status during status wait #2261

Merged
merged 5 commits into from
Feb 28, 2024
Merged
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
14 changes: 14 additions & 0 deletions status/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func (k *K8sStatusCollector) Status(ctx context.Context) (*Status, error) {
ctx, cancel := context.WithTimeout(ctx, k.params.waitTimeout())
defer cancel()

var lines int
for {
select {
case <-ctx.Done():
Expand All @@ -332,13 +333,26 @@ func (k *K8sStatusCollector) Status(ctx context.Context) (*Status, error) {
}
if !k.statusIsReady(s) && k.params.Wait {
time.Sleep(defaults.WaitRetryInterval)
if k.params.Output == OutputSummary {
statusFmt := s.Format()
cursorUp(lines)
lines = len(strings.Split(statusFmt, "\n"))
fmt.Print(statusFmt)
}
continue
}

cursorUp(lines)
return mostRecentStatus, nil
}
}

func cursorUp(lines int) {
for i := 1; i < lines; i++ {
fmt.Print("\033[A\033[2K")
}
}

type statusTask struct {
name string
task func(_ context.Context) error
Expand Down
Loading