Skip to content

feat(cmd): Add quotas command#337

Draft
craciunoiuc wants to merge 1 commit into
stagingfrom
craciunoiuc/add-fancy-quotas
Draft

feat(cmd): Add quotas command#337
craciunoiuc wants to merge 1 commit into
stagingfrom
craciunoiuc/add-fancy-quotas

Conversation

@craciunoiuc
Copy link
Copy Markdown
Member

Interactive terminal that shows aggregated quotas and per-node quotas. Displays all data available from nodes and sums them up for the all view.

The controlplane is used for fetching image data, which does not depend on a node for fetching.

Depends on: https://github.com/unikraft-cloud/console/pull/775
Depends on: https://github.com/unikraft-cloud/proto/pull/280

TODOs left:

Closes: TOOL-541

Interactive terminal that shows aggregated quotas and per-node quotas.
Displays all data available from nodes and sums them up for the all
view.

The controlplane is used for fetching image data, which does not depend
on a node for fetching.

Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
@craciunoiuc craciunoiuc requested review from Copilot and jedevc May 22, 2026 11:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new metros quotas subcommand that presents per-metro and aggregated quota usage, with both an interactive Bubble Tea TUI mode and a non-interactive one-shot (optionally watched) output mode.

Changes:

  • Wire a new quotas subcommand under metros.
  • Implement quota fetching across configured metros and aggregation into an “All” view.
  • Add TUI rendering (tabs, refresh ticking) plus a non-interactive renderer with optional --watch.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/cmd/metros.go Adds the Quotas subcommand under MetrosCmd.
internal/cmd/metro_quotas.go Implements fetching, aggregation, and TUI/non-interactive rendering for quota usage.
Comments suppressed due to low confidence (1)

internal/cmd/metro_quotas.go:188

  • The model error state is never cleared on a subsequent successful refresh. If the first fetch yields m.err, the UI will keep rendering the error view even after later fetches return data. Reset m.err = nil when handling quotasLoadedMsg (before processing entries), and optionally also when starting a new fetch on quotasTickMsg.
	case quotasLoadedMsg:
		m.loading = false
		m.userName = msg.userName
		m.data = make(map[string]*platform.Quotas)
		var tabs []string
		if m.metro == "" {
			tabs = []string{"All"}
		}
		var firstErr error
		for _, e := range msg.entries {
			if e.err != nil {
				if firstErr == nil {
					firstErr = e.err
				}
				continue
			}
			m.data[e.metro] = e.quotas
			tabs = append(tabs, e.metro)
		}
		m.tabs = tabs
		if m.activeTab >= len(m.tabs) {
			m.activeTab = 0
		}
		if len(m.data) == 0 && firstErr != nil {
			m.err = firstErr
		}
		if m.watch != nil {
			interval := cmp.Or(*m.watch, 2*time.Second)
			return m, tea.Tick(interval, func(time.Time) tea.Msg {
				return quotasTickMsg{}
			})
		}
		return m, nil

	case quotasTickMsg:
		m.loading = true
		return m, m.fetchCmd()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +444 to +457
metros := profile.Metros
if metro != "" {
for _, m := range profile.Metros {
if m.Name == metro {
metros = []config.Metro{m}
break
}
}
if len(metros) == len(profile.Metros) {
return quotasFetchResult{
entries: []quotaEntry{{err: fmt.Errorf("metro %q not found in profile", metro)}},
userName: userName,
}
}
Comment on lines +152 to +171
case quotasLoadedMsg:
m.loading = false
m.userName = msg.userName
m.data = make(map[string]*platform.Quotas)
var tabs []string
if m.metro == "" {
tabs = []string{"All"}
}
var firstErr error
for _, e := range msg.entries {
if e.err != nil {
if firstErr == nil {
firstErr = e.err
}
continue
}
m.data[e.metro] = e.quotas
tabs = append(tabs, e.metro)
}
m.tabs = tabs
func renderQuotaView(q *platform.Quotas, userName string) string {
sections := [][]quotaRow{
{
{label: "active instances", bar: true, used: q.Used.LiveInstances, limit: q.Hard.Instances},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants