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
2050131b
Commit
2050131b
authored
Jan 06, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ParseOrDie -> MustParse; stop returning pointer
parent
35f54add
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
35 deletions
+32
-35
quantity.go
pkg/api/resource/quantity.go
+6
-9
quantity_example_test.go
pkg/api/resource/quantity_example_test.go
+5
-5
validation_test.go
pkg/api/validation/validation_test.go
+12
-12
client_test.go
pkg/client/client_test.go
+2
-2
openstack.go
pkg/cloudprovider/openstack/openstack.go
+3
-3
priorities_test.go
pkg/scheduler/priorities_test.go
+4
-4
No files found.
pkg/api/resource/quantity.go
View file @
2050131b
...
...
@@ -102,14 +102,14 @@ const (
DecimalSI
=
Format
(
"DecimalSI"
)
// e.g., 12M (12 * 10^6)
)
//
ParseOrDi
e turns the given string into a quantity or panics; for tests
//
MustPars
e turns the given string into a quantity or panics; for tests
// or others cases where you know the string is valid.
func
ParseOrDie
(
str
string
)
*
Quantity
{
func
MustParse
(
str
string
)
Quantity
{
q
,
err
:=
ParseQuantity
(
str
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"cannot parse '%v': %v"
,
str
,
err
))
}
return
q
return
*
q
}
const
(
...
...
@@ -403,10 +403,7 @@ func (qf qFlag) String() string {
// QuantityFlag is a helper that makes a quantity flag (using standard flag package).
// Will panic if defaultValue is not a valid quantity.
func
QuantityFlag
(
flagName
,
defaultValue
,
description
string
)
*
Quantity
{
q
,
err
:=
ParseQuantity
(
defaultValue
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"can't use %v as a quantity: %v"
,
defaultValue
,
err
))
}
flag
.
Var
(
qFlag
{
q
},
flagName
,
description
)
return
q
q
:=
MustParse
(
defaultValue
)
flag
.
Var
(
qFlag
{
&
q
},
flagName
,
description
)
return
&
q
}
pkg/api/resource/quantity_example_test.go
View file @
2050131b
...
...
@@ -38,17 +38,17 @@ func ExampleFormat() {
// cores = 5300m
}
func
Example
ParseOrDi
e
()
{
memorySize
:=
resource
.
ParseOrDi
e
(
"5Gi"
)
func
Example
MustPars
e
()
{
memorySize
:=
resource
.
MustPars
e
(
"5Gi"
)
fmt
.
Printf
(
"memorySize = %v (%v)
\n
"
,
memorySize
.
Value
(),
memorySize
.
Format
)
diskSize
:=
resource
.
ParseOrDi
e
(
"5G"
)
diskSize
:=
resource
.
MustPars
e
(
"5G"
)
fmt
.
Printf
(
"diskSize = %v (%v)
\n
"
,
diskSize
.
Value
(),
diskSize
.
Format
)
cores
:=
resource
.
ParseOrDi
e
(
"5300m"
)
cores
:=
resource
.
MustPars
e
(
"5300m"
)
fmt
.
Printf
(
"milliCores = %v (%v)
\n
"
,
cores
.
MilliValue
(),
cores
.
Format
)
cores2
:=
resource
.
ParseOrDi
e
(
"5.4"
)
cores2
:=
resource
.
MustPars
e
(
"5.4"
)
fmt
.
Printf
(
"milliCores = %v (%v)
\n
"
,
cores2
.
MilliValue
(),
cores2
.
Format
)
// Output:
...
...
pkg/api/validation/validation_test.go
View file @
2050131b
...
...
@@ -373,8 +373,8 @@ func TestValidateManifest(t *testing.T) {
Image
:
"image"
,
Command
:
[]
string
{
"foo"
,
"bar"
},
WorkingDir
:
"/tmp"
,
Memory
:
*
resource
.
Q
(
"1"
),
CPU
:
*
resource
.
Q
(
"1"
),
Memory
:
resource
.
MustParse
(
"1"
),
CPU
:
resource
.
MustParse
(
"1"
),
Ports
:
[]
api
.
Port
{
{
Name
:
"p1"
,
ContainerPort
:
80
,
HostPort
:
8080
},
{
Name
:
"p2"
,
ContainerPort
:
81
},
...
...
@@ -624,7 +624,7 @@ func TestValidatePodUpdate(t *testing.T) {
Containers
:
[]
api
.
Container
{
{
Image
:
"foo:V1"
,
CPU
:
*
resource
.
Q
(
"100m"
),
CPU
:
resource
.
MustParse
(
"100m"
),
},
},
},
...
...
@@ -635,7 +635,7 @@ func TestValidatePodUpdate(t *testing.T) {
Containers
:
[]
api
.
Container
{
{
Image
:
"foo:V2"
,
CPU
:
*
resource
.
Q
(
"1000m"
),
CPU
:
resource
.
MustParse
(
"1000m"
),
},
},
},
...
...
@@ -1301,8 +1301,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
Q
(
"10000"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"100"
),
},
},
},
api
.
Node
{
...
...
@@ -1311,8 +1311,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
Q
(
"100"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"10000"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
},
},
},
true
},
...
...
@@ -1323,8 +1323,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
Q
(
"10000"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"100"
),
},
},
},
api
.
Node
{
...
...
@@ -1334,8 +1334,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
Q
(
"100"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"10000"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
},
},
},
true
},
...
...
pkg/client/client_test.go
View file @
2050131b
...
...
@@ -734,8 +734,8 @@ func TestCreateMinion(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
Q
(
"1000m"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"1Mi"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"1000m"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"1Mi"
),
},
},
}
...
...
pkg/cloudprovider/openstack/openstack.go
View file @
2050131b
...
...
@@ -170,10 +170,10 @@ func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
rsrc
:=
api
.
NodeResources
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
int64
(
flavor
.
VCPUs
*
1000
),
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
Q
(
fmt
.
Sprintf
(
"%dMi"
,
flavor
.
RAM
)),
"openstack.org/disk"
:
*
resource
.
Q
(
fmt
.
Sprintf
(
"%dG"
,
flavor
.
Disk
)),
api
.
ResourceMemory
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dMi"
,
flavor
.
RAM
)),
"openstack.org/disk"
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dG"
,
flavor
.
Disk
)),
"openstack.org/rxTxFactor"
:
*
resource
.
NewQuantity
(
int64
(
flavor
.
RxTxFactor
*
1000
),
resource
.
DecimalSI
),
"openstack.org/swap"
:
*
resource
.
Q
(
fmt
.
Sprintf
(
"%dMiB
"
,
flavor
.
Swap
)),
"openstack.org/swap"
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dMi
"
,
flavor
.
Swap
)),
},
}
flavor_to_resource
[
flavor
.
ID
]
=
&
rsrc
...
...
pkg/scheduler/priorities_test.go
View file @
2050131b
...
...
@@ -56,14 +56,14 @@ func TestLeastRequested(t *testing.T) {
}
cpuOnly
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
CPU
:
*
resource
.
Q
(
"1000m"
)},
{
CPU
:
*
resource
.
Q
(
"2000m"
)},
{
CPU
:
resource
.
MustParse
(
"1000m"
)},
{
CPU
:
resource
.
MustParse
(
"2000m"
)},
},
}
cpuAndMemory
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
CPU
:
*
resource
.
Q
(
"1000m"
),
Memory
:
*
resource
.
Q
(
"2000"
)},
{
CPU
:
*
resource
.
Q
(
"2000m"
),
Memory
:
*
resource
.
Q
(
"3000"
)},
{
CPU
:
resource
.
MustParse
(
"1000m"
),
Memory
:
resource
.
MustParse
(
"2000"
)},
{
CPU
:
resource
.
MustParse
(
"2000m"
),
Memory
:
resource
.
MustParse
(
"3000"
)},
},
}
tests
:=
[]
struct
{
...
...
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