Merge pull request #102177 from atiratree/quotaunitscli

kubectl: show consistent unit format in quota describe

Kubernetes-commit: 303fe39e1c1ed551b8537bcd76bda15d24587338
This commit is contained in:
Kubernetes Publisher 2021-07-09 16:49:18 -07:00
commit 52bae703b5
4 changed files with 21 additions and 18 deletions

12
go.mod
View File

@ -32,9 +32,9 @@ require (
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975
k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439
k8s.io/apimachinery v0.0.0-20210712060818-a644435e2c13
k8s.io/cli-runtime v0.0.0-20210708220808-2cd779a6117f
k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb
k8s.io/component-base v0.0.0-20210708095030-632996df852a
k8s.io/component-helpers v0.0.0-20210708095128-55a3896515e9
k8s.io/klog/v2 v2.9.0
@ -48,9 +48,9 @@ require (
replace (
k8s.io/api => k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975
k8s.io/client-go => k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210712060818-a644435e2c13
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210708220808-2cd779a6117f
k8s.io/client-go => k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20210708071253-ee3ba0fad71e
k8s.io/component-base => k8s.io/component-base v0.0.0-20210708095030-632996df852a
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20210708095128-55a3896515e9

12
go.sum
View File

@ -739,12 +739,12 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4 h1:SONTS5tRMTV7iWmw9T6C7vsEFrQy4bygwu/PaUJP2Lo=
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4/go.mod h1:72i8FbvEsYM9+Hy9ZRCr4WADf5G8kTsusBNrcSkt2aY=
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74 h1:Daxg4VCqUpkKuMJjia7XcVVDHnPjH6IeKb7jcZDcQUM=
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975 h1:0PtzYqhVBCUKi/XvmanrSTIcfsWg1t5VVgJ/Yx25CMM=
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975/go.mod h1:vBIJsdwtI2UT9JES/vOvvOQ+D0cmTCtsG25Hm45AuKw=
k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439 h1:/KWGV2YkMr96+/rRzrRkhI4bvzwS8NixKg3ElVoFAws=
k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439/go.mod h1:sf6aX4lO8AyErF5l4A2Aa//yf44Xb5ghYUCNLRBLOKk=
k8s.io/apimachinery v0.0.0-20210712060818-a644435e2c13 h1:Y40e5ho6n8KOvBCqdz/jm7ssKQyQLQdbZbC3lR9TaCU=
k8s.io/apimachinery v0.0.0-20210712060818-a644435e2c13/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
k8s.io/cli-runtime v0.0.0-20210708220808-2cd779a6117f h1:8Ho5dsKOarHnnqE8gpc90zVJ0ujgxHZq1AnzpjCUdL4=
k8s.io/cli-runtime v0.0.0-20210708220808-2cd779a6117f/go.mod h1:+w+O40wYPoErje+Zoxomw8PIc9Z8JKF87V2ObeoqyE0=
k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb h1:Hx8ZvH95DUXm9tFnwAAvyNmZGMSn+jiMZ19AtnQvEPA=
k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb/go.mod h1:sf6aX4lO8AyErF5l4A2Aa//yf44Xb5ghYUCNLRBLOKk=
k8s.io/code-generator v0.0.0-20210708071253-ee3ba0fad71e/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
k8s.io/component-base v0.0.0-20210708095030-632996df852a h1:PRk5Hh5WlaBfH5IjtoqNeL1Waqillce5m2p7RuvOeqA=
k8s.io/component-base v0.0.0-20210708095030-632996df852a/go.mod h1:LBVnEifw+SvQx2si1RCpd0WVE198EULnwqnMg0QBBQQ=

View File

@ -672,10 +672,13 @@ func describeQuota(resourceQuota *corev1.ResourceQuota) (string, error) {
msg := "%v\t%v\t%v\n"
for i := range resources {
resource := resources[i]
hardQuantity := resourceQuota.Status.Hard[resource]
usedQuantity := resourceQuota.Status.Used[resource]
w.Write(LEVEL_0, msg, resource, usedQuantity.String(), hardQuantity.String())
resourceName := resources[i]
hardQuantity := resourceQuota.Status.Hard[resourceName]
usedQuantity := resourceQuota.Status.Used[resourceName]
if hardQuantity.Format != usedQuantity.Format {
usedQuantity = *resource.NewQuantity(usedQuantity.Value(), hardQuantity.Format)
}
w.Write(LEVEL_0, msg, resourceName, usedQuantity.String(), hardQuantity.String())
}
return nil
})

View File

@ -4066,7 +4066,7 @@ func TestDescribeResourceQuota(t *testing.T) {
corev1.ResourceName(corev1.ResourceLimitsMemory): resource.MustParse("0G"),
corev1.ResourceName(corev1.ResourceMemory): resource.MustParse("0G"),
corev1.ResourceName(corev1.ResourceRequestsCPU): resource.MustParse("0"),
corev1.ResourceName(corev1.ResourceRequestsMemory): resource.MustParse("0G"),
corev1.ResourceName(corev1.ResourceRequestsMemory): resource.MustParse("1000Ki"),
},
},
})
@ -4076,7 +4076,7 @@ func TestDescribeResourceQuota(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
expectedOut := []string{"bar", "foo", "limits.cpu", "2", "limits.memory", "2G", "requests.cpu", "1", "requests.memory", "1G"}
expectedOut := []string{"bar", "foo", "limits.cpu", "2", "limits.memory", "2G", "requests.cpu", "1", "requests.memory", "1024k", "1G"}
for _, expected := range expectedOut {
if !strings.Contains(out, expected) {
t.Errorf("expected to find %q in output: %q", expected, out)