From 97a02566805e1d16abd627ffd1a18d947b5f2a5e Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 19 May 2021 16:56:06 -0400 Subject: [PATCH] cli: Handle nil MemoryMaxMB (#10620) Handle when MemoryMaxMB is nil, as expected when a new 1.1.0 is hitting a pre-1.1.0 Server. --- CHANGELOG.md | 3 +++ command/quota_status.go | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b8e527bea..b9dcc6c8570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 1.1.1 (Unreleased) +BUG FIXES: +* cli: Fixed a bug where `quota status` and `namespace status` commands may panic if the CLI targets a pre-1.1.0 cluster + ## 1.1.0 (May 18, 2021) FEATURES: diff --git a/command/quota_status.go b/command/quota_status.go index 34dd3bc2f67..4e9434e4ce6 100644 --- a/command/quota_status.go +++ b/command/quota_status.go @@ -189,9 +189,17 @@ func formatQuotaLimits(spec *api.QuotaSpec, usages map[string]*api.QuotaUsage) s continue } - cpu := fmt.Sprintf("%d / %s", *used.RegionLimit.CPU, formatQuotaLimitInt(specLimit.RegionLimit.CPU)) - memory := fmt.Sprintf("%d / %s", *used.RegionLimit.MemoryMB, formatQuotaLimitInt(specLimit.RegionLimit.MemoryMB)) - memoryMax := fmt.Sprintf("%d / %s", *used.RegionLimit.MemoryMaxMB, formatQuotaLimitInt(specLimit.RegionLimit.MemoryMaxMB)) + orZero := func(v *int) int { + if v == nil { + return 0 + } + return *v + } + + cpu := fmt.Sprintf("%d / %s", orZero(used.RegionLimit.CPU), formatQuotaLimitInt(specLimit.RegionLimit.CPU)) + memory := fmt.Sprintf("%d / %s", orZero(used.RegionLimit.MemoryMB), formatQuotaLimitInt(specLimit.RegionLimit.MemoryMB)) + memoryMax := fmt.Sprintf("%d / %s", orZero(used.RegionLimit.MemoryMaxMB), formatQuotaLimitInt(specLimit.RegionLimit.MemoryMaxMB)) + net := fmt.Sprintf("- / %s", formatQuotaLimitInt(&specBits)) if len(used.RegionLimit.Networks) == 1 { net = fmt.Sprintf("%d / %s", *used.RegionLimit.Networks[0].MBits, formatQuotaLimitInt(&specBits))