From d22878311fcf6ca6203727b771f695dc540fa747 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 18 May 2021 16:20:23 -0400 Subject: [PATCH 1/3] cli: Handle nil MemoryMaxMB Handle when MemoryMaxMB is nil, as expected when a new 1.1.0 is hitting a pre-1.1.0 Server. --- command/quota_status.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/command/quota_status.go b/command/quota_status.go index 34dd3bc2f67..53930d5d32c 100644 --- a/command/quota_status.go +++ b/command/quota_status.go @@ -191,7 +191,13 @@ func formatQuotaLimits(spec *api.QuotaSpec, usages map[string]*api.QuotaUsage) s 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)) + + memMax := 0 + if mm := used.RegionLimit.MemoryMaxMB; mm != nil { + memMax = *mm + } + memoryMax := fmt.Sprintf("%d / %s", memMax, 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)) From 91fb7f2ff4a0b4b94d9408f0b193afa9a84c7b63 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 18 May 2021 16:27:31 -0400 Subject: [PATCH 2/3] be more defensive --- command/quota_status.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/command/quota_status.go b/command/quota_status.go index 53930d5d32c..4e9434e4ce6 100644 --- a/command/quota_status.go +++ b/command/quota_status.go @@ -189,14 +189,16 @@ 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)) - - memMax := 0 - if mm := used.RegionLimit.MemoryMaxMB; mm != nil { - memMax = *mm + orZero := func(v *int) int { + if v == nil { + return 0 + } + return *v } - memoryMax := fmt.Sprintf("%d / %s", memMax, formatQuotaLimitInt(specLimit.RegionLimit.MemoryMaxMB)) + + 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 { From 0ca985a61217c2be763530fefeea2fee869d6db8 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 19 May 2021 16:55:35 -0400 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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: