feat(cmd): Add quotas command#337
Draft
craciunoiuc wants to merge 1 commit into
Draft
Conversation
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>
There was a problem hiding this comment.
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
quotassubcommand undermetros. - 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. Resetm.err = nilwhen handlingquotasLoadedMsg(before processing entries), and optionally also when starting a new fetch onquotasTickMsg.
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}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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