Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6968a4e0
Commit
6968a4e0
authored
Jun 01, 2015
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve quota describe output
parent
1845ca88
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
1 deletion
+60
-1
quantity.go
pkg/api/resource/quantity.go
+8
-1
quantity_test.go
pkg/api/resource/quantity_test.go
+20
-0
conversion_test.go
pkg/api/v1beta3/conversion_test.go
+32
-0
No files found.
pkg/api/resource/quantity.go
View file @
6968a4e0
...
@@ -190,7 +190,9 @@ func ParseQuantity(str string) (*Quantity, error) {
...
@@ -190,7 +190,9 @@ func ParseQuantity(str string) (*Quantity, error) {
// of an amount.
// of an amount.
// Arguably, this should be inf.RoundHalfUp (normal rounding), but
// Arguably, this should be inf.RoundHalfUp (normal rounding), but
// that would have the side effect of rounding values < .5m to zero.
// that would have the side effect of rounding values < .5m to zero.
amount
.
Round
(
amount
,
3
,
inf
.
RoundUp
)
if
v
,
ok
:=
amount
.
Unscaled
();
v
!=
int64
(
0
)
||
!
ok
{
amount
.
Round
(
amount
,
3
,
inf
.
RoundUp
)
}
// The max is just a simple cap.
// The max is just a simple cap.
if
amount
.
Cmp
(
maxAllowed
)
>
0
{
if
amount
.
Cmp
(
maxAllowed
)
>
0
{
...
@@ -237,6 +239,11 @@ func (q *Quantity) Canonicalize() (string, suffix) {
...
@@ -237,6 +239,11 @@ func (q *Quantity) Canonicalize() (string, suffix) {
return
"0"
,
""
return
"0"
,
""
}
}
// zero is zero always
if
q
.
Amount
.
Cmp
(
&
inf
.
Dec
{})
==
0
{
return
"0"
,
""
}
format
:=
q
.
Format
format
:=
q
.
Format
switch
format
{
switch
format
{
case
DecimalExponent
,
DecimalSI
:
case
DecimalExponent
,
DecimalSI
:
...
...
pkg/api/resource/quantity_test.go
View file @
6968a4e0
...
@@ -57,6 +57,26 @@ func TestDec(t *testing.T) {
...
@@ -57,6 +57,26 @@ func TestDec(t *testing.T) {
}
}
}
}
// TestQuantityParseZero ensures that when a 0 quantity is passed, its string value is 0
func
TestQuantityParseZero
(
t
*
testing
.
T
)
{
zero
:=
MustParse
(
"0"
)
if
expected
,
actual
:=
"0"
,
zero
.
String
();
expected
!=
actual
{
t
.
Errorf
(
"Expected %v, actual %v"
,
expected
,
actual
)
}
}
// Verifies that you get 0 as canonical value if internal value is 0, and not 0<suffix>
func
TestQuantityCanocicalizeZero
(
t
*
testing
.
T
)
{
val
:=
MustParse
(
"1000m"
)
x
:=
val
.
Amount
y
:=
dec
(
1
,
0
)
z
:=
val
.
Amount
.
Sub
(
x
,
y
)
zero
:=
Quantity
{
z
,
DecimalSI
}
if
expected
,
actual
:=
"0"
,
zero
.
String
();
expected
!=
actual
{
t
.
Errorf
(
"Expected %v, actual %v"
,
expected
,
actual
)
}
}
func
TestQuantityParse
(
t
*
testing
.
T
)
{
func
TestQuantityParse
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
input
string
input
string
...
...
pkg/api/v1beta3/conversion_test.go
View file @
6968a4e0
...
@@ -20,9 +20,41 @@ import (
...
@@ -20,9 +20,41 @@ import (
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
versioned
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
versioned
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
)
)
func
TestResourceQuotaStatusConversion
(
t
*
testing
.
T
)
{
// should serialize as "0"
expected
:=
resource
.
NewQuantity
(
int64
(
0
),
resource
.
DecimalSI
)
if
"0"
!=
expected
.
String
()
{
t
.
Errorf
(
"Expected: 0, Actual: %v, do not require units"
,
expected
.
String
())
}
parsed
:=
resource
.
MustParse
(
"0"
)
if
"0"
!=
parsed
.
String
()
{
t
.
Errorf
(
"Expected: 0, Actual: %v, do not require units"
,
parsed
.
String
())
}
quota
:=
&
api
.
ResourceQuota
{}
quota
.
Status
=
api
.
ResourceQuotaStatus
{}
quota
.
Status
.
Hard
=
api
.
ResourceList
{}
quota
.
Status
.
Used
=
api
.
ResourceList
{}
quota
.
Status
.
Hard
[
api
.
ResourcePods
]
=
*
expected
// round-trip the object
data
,
_
:=
versioned
.
Codec
.
Encode
(
quota
)
object
,
_
:=
versioned
.
Codec
.
Decode
(
data
)
after
:=
object
.
(
*
api
.
ResourceQuota
)
actualQuantity
:=
after
.
Status
.
Hard
[
api
.
ResourcePods
]
actual
:=
&
actualQuantity
// should be "0", but was "0m"
if
expected
.
String
()
!=
actual
.
String
()
{
t
.
Errorf
(
"Expected %v, Actual %v"
,
expected
.
String
(),
actual
.
String
())
}
}
func
TestNodeConversion
(
t
*
testing
.
T
)
{
func
TestNodeConversion
(
t
*
testing
.
T
)
{
obj
,
err
:=
versioned
.
Codec
.
Decode
([]
byte
(
`{"kind":"Minion","apiVersion":"v1beta3"}`
))
obj
,
err
:=
versioned
.
Codec
.
Decode
([]
byte
(
`{"kind":"Minion","apiVersion":"v1beta3"}`
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment