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
7f49ba0d
Commit
7f49ba0d
authored
Jan 05, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put quantity into packages
kubelet, GCE, validation, client
parent
40d29f4f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
70 deletions
+71
-70
validation_test.go
pkg/api/validation/validation_test.go
+13
-12
client_test.go
pkg/client/client_test.go
+4
-4
gce.go
pkg/cloudprovider/gce/gce.go
+9
-7
kubelet.go
pkg/kubelet/kubelet.go
+3
-3
predicates.go
pkg/scheduler/predicates.go
+8
-10
predicates_test.go
pkg/scheduler/predicates_test.go
+6
-13
priorities.go
pkg/scheduler/priorities.go
+20
-12
priorities_test.go
pkg/scheduler/priorities_test.go
+8
-9
No files found.
pkg/api/validation/validation_test.go
View file @
7f49ba0d
...
...
@@ -22,6 +22,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
...
...
@@ -372,8 +373,8 @@ func TestValidateManifest(t *testing.T) {
Image
:
"image"
,
Command
:
[]
string
{
"foo"
,
"bar"
},
WorkingDir
:
"/tmp"
,
Memory
:
1
,
CPU
:
1
,
Memory
:
*
resource
.
Q
(
"1"
)
,
CPU
:
*
resource
.
Q
(
"1"
)
,
Ports
:
[]
api
.
Port
{
{
Name
:
"p1"
,
ContainerPort
:
80
,
HostPort
:
8080
},
{
Name
:
"p2"
,
ContainerPort
:
81
},
...
...
@@ -623,7 +624,7 @@ func TestValidatePodUpdate(t *testing.T) {
Containers
:
[]
api
.
Container
{
{
Image
:
"foo:V1"
,
CPU
:
100
,
CPU
:
*
resource
.
Q
(
"100m"
)
,
},
},
},
...
...
@@ -634,7 +635,7 @@ func TestValidatePodUpdate(t *testing.T) {
Containers
:
[]
api
.
Container
{
{
Image
:
"foo:V2"
,
CPU
:
1000
,
CPU
:
*
resource
.
Q
(
"1000m"
)
,
},
},
},
...
...
@@ -1300,8 +1301,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
"cpu"
:
util
.
NewIntOrStringFromInt
(
10000
),
"memory"
:
util
.
NewIntOrStringFromInt
(
100
),
api
.
ResourceCPU
:
*
resource
.
Q
(
"10000"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"100"
),
},
},
},
api
.
Node
{
...
...
@@ -1310,8 +1311,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
"cpu"
:
util
.
NewIntOrStringFromInt
(
100
),
"memory"
:
util
.
NewIntOrStringFromInt
(
10000
),
api
.
ResourceCPU
:
*
resource
.
Q
(
"100"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"10000"
),
},
},
},
true
},
...
...
@@ -1322,8 +1323,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
"cpu"
:
util
.
NewIntOrStringFromInt
(
10000
),
"memory"
:
util
.
NewIntOrStringFromInt
(
100
),
api
.
ResourceCPU
:
*
resource
.
Q
(
"10000"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"100"
),
},
},
},
api
.
Node
{
...
...
@@ -1333,8 +1334,8 @@ func TestValidateMinionUpdate(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
"cpu"
:
util
.
NewIntOrStringFromInt
(
100
),
"memory"
:
util
.
NewIntOrStringFromInt
(
10000
),
api
.
ResourceCPU
:
*
resource
.
Q
(
"100"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"10000"
),
},
},
},
true
},
...
...
pkg/client/client_test.go
View file @
7f49ba0d
...
...
@@ -28,9 +28,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
...
...
@@ -96,7 +96,7 @@ func (c *testClient) Setup() *testClient {
func
(
c
*
testClient
)
Validate
(
t
*
testing
.
T
,
received
runtime
.
Object
,
err
error
)
{
c
.
ValidateCommon
(
t
,
err
)
if
c
.
Response
.
Body
!=
nil
&&
!
reflect
.
DeepEqual
(
c
.
Response
.
Body
,
received
)
{
if
c
.
Response
.
Body
!=
nil
&&
!
api
.
Semantic
.
DeepEqual
(
c
.
Response
.
Body
,
received
)
{
t
.
Errorf
(
"bad response for request %#v: expected %#v, got %#v"
,
c
.
Request
,
c
.
Response
.
Body
,
received
)
}
}
...
...
@@ -734,8 +734,8 @@ func TestCreateMinion(t *testing.T) {
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
resources
.
CPU
:
util
.
NewIntOrStringFromInt
(
1000
),
resources
.
Memory
:
util
.
NewIntOrStringFromInt
(
1024
*
1024
),
api
.
ResourceCPU
:
*
resource
.
Q
(
"1000m"
),
api
.
ResourceMemory
:
*
resource
.
Q
(
"1Mi"
),
},
},
}
...
...
pkg/cloudprovider/gce/gce.go
View file @
7f49ba0d
...
...
@@ -28,13 +28,13 @@ import (
"strings"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"code.google.com/p/goauth2/compute/serviceaccount"
compute
"code.google.com/p/google-api-go-client/compute/v1"
container
"code.google.com/p/google-api-go-client/container/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
)
...
...
@@ -338,11 +338,12 @@ func (gce *GCECloud) List(filter string) ([]string, error) {
return
instances
,
nil
}
func
makeResources
(
cpu
float32
,
memory
float32
)
*
api
.
NodeResources
{
// cpu is in cores, memory is in GiB
func
makeResources
(
cpu
float64
,
memory
float64
)
*
api
.
NodeResources
{
return
&
api
.
NodeResources
{
Capacity
:
api
.
ResourceList
{
resources
.
CPU
:
util
.
NewIntOrStringFromInt
(
int
(
cpu
*
1000
)
),
resources
.
Memory
:
util
.
NewIntOrStringFromInt
(
int
(
memory
*
1024
*
1024
*
1024
)
),
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
int64
(
cpu
*
1000
),
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
int64
(
memory
*
1024
*
1024
*
1024
),
resource
.
BinarySI
),
},
}
}
...
...
@@ -359,6 +360,7 @@ func (gce *GCECloud) GetNodeResources(name string) (*api.NodeResources, error) {
if
err
!=
nil
{
return
nil
,
err
}
// TODO: actually read machine size instead of this awful hack.
switch
canonicalizeMachineType
(
res
.
MachineType
)
{
case
"f1-micro"
:
return
makeResources
(
1
,
0.6
),
nil
...
...
pkg/kubelet/kubelet.go
View file @
7f49ba0d
...
...
@@ -398,7 +398,7 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m
return
exposedPorts
,
portBindings
}
func
milliCPUToShares
(
milliCPU
int
)
int
{
func
milliCPUToShares
(
milliCPU
int
64
)
int64
{
if
milliCPU
==
0
{
// zero milliCPU means unset. Use kernel default.
return
0
...
...
@@ -537,8 +537,8 @@ func (kl *Kubelet) runContainer(pod *api.BoundPod, container *api.Container, pod
ExposedPorts
:
exposedPorts
,
Hostname
:
pod
.
Name
,
Image
:
container
.
Image
,
Memory
:
int64
(
container
.
Memory
),
CPUShares
:
int64
(
milliCPUToShares
(
container
.
CPU
)),
Memory
:
container
.
Memory
.
Value
(
),
CPUShares
:
milliCPUToShares
(
container
.
CPU
.
MilliValue
(
)),
WorkingDir
:
container
.
WorkingDir
,
},
}
...
...
pkg/scheduler/predicates.go
View file @
7f49ba0d
...
...
@@ -22,7 +22,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/golang/glog"
)
...
...
@@ -89,15 +88,15 @@ type ResourceFit struct {
}
type
resourceRequest
struct
{
milliCPU
int
memory
int
milliCPU
int
64
memory
int
64
}
func
getResourceRequest
(
pod
*
api
.
Pod
)
resourceRequest
{
result
:=
resourceRequest
{}
for
ix
:=
range
pod
.
Spec
.
Containers
{
result
.
memory
+=
pod
.
Spec
.
Containers
[
ix
]
.
Memory
result
.
milliCPU
+=
pod
.
Spec
.
Containers
[
ix
]
.
CPU
result
.
memory
+=
pod
.
Spec
.
Containers
[
ix
]
.
Memory
.
Value
()
result
.
milliCPU
+=
pod
.
Spec
.
Containers
[
ix
]
.
CPU
.
MilliValue
()
}
return
result
}
...
...
@@ -113,17 +112,16 @@ func (r *ResourceFit) PodFitsResources(pod api.Pod, existingPods []api.Pod, node
if
err
!=
nil
{
return
false
,
err
}
milliCPURequested
:=
0
memoryRequested
:=
0
milliCPURequested
:=
int64
(
0
)
memoryRequested
:=
int64
(
0
)
for
ix
:=
range
existingPods
{
existingRequest
:=
getResourceRequest
(
&
existingPods
[
ix
])
milliCPURequested
+=
existingRequest
.
milliCPU
memoryRequested
+=
existingRequest
.
memory
}
// TODO: convert to general purpose resource matching, when pods ask for resources
totalMilliCPU
:=
int
(
resources
.
GetFloatResource
(
info
.
Spec
.
Capacity
,
resources
.
CPU
,
0
)
*
1000
)
totalMemory
:=
resources
.
GetIntegerResource
(
info
.
Spec
.
Capacity
,
resources
.
Memory
,
0
)
totalMilliCPU
:=
info
.
Spec
.
Capacity
.
Get
(
api
.
ResourceCPU
)
.
MilliValue
()
totalMemory
:=
info
.
Spec
.
Capacity
.
Get
(
api
.
ResourceMemory
)
.
Value
()
fitsCPU
:=
totalMilliCPU
==
0
||
(
totalMilliCPU
-
milliCPURequested
)
>=
podRequest
.
milliCPU
fitsMemory
:=
totalMemory
==
0
||
(
totalMemory
-
memoryRequested
)
>=
podRequest
.
memory
...
...
pkg/scheduler/predicates_test.go
View file @
7f49ba0d
...
...
@@ -21,8 +21,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
)
type
FakeNodeInfo
api
.
Node
...
...
@@ -32,17 +31,11 @@ func (n FakeNodeInfo) GetNodeInfo(nodeName string) (*api.Node, error) {
return
&
node
,
nil
}
func
makeResources
(
milliCPU
int
,
memory
int
)
api
.
NodeResources
{
func
makeResources
(
milliCPU
int
64
,
memory
int64
)
api
.
NodeResources
{
return
api
.
NodeResources
{
Capacity
:
api
.
ResourceList
{
resources
.
CPU
:
util
.
IntOrString
{
IntVal
:
milliCPU
,
Kind
:
util
.
IntstrInt
,
},
resources
.
Memory
:
util
.
IntOrString
{
IntVal
:
memory
,
Kind
:
util
.
IntstrInt
,
},
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
milliCPU
,
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
memory
,
resource
.
BinarySI
),
},
}
}
...
...
@@ -51,8 +44,8 @@ func newResourcePod(usage ...resourceRequest) api.Pod {
containers
:=
[]
api
.
Container
{}
for
_
,
req
:=
range
usage
{
containers
=
append
(
containers
,
api
.
Container
{
Memory
:
req
.
memory
,
CPU
:
req
.
milliCPU
,
Memory
:
*
resource
.
NewQuantity
(
req
.
memory
,
resource
.
BinarySI
)
,
CPU
:
*
resource
.
NewMilliQuantity
(
req
.
milliCPU
,
resource
.
DecimalSI
)
,
})
}
return
api
.
Pod
{
...
...
pkg/scheduler/priorities.go
View file @
7f49ba0d
...
...
@@ -18,13 +18,12 @@ package scheduler
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/golang/glog"
)
// the unused capacity is calculated on a scale of 0-10
// 0 being the lowest priority and 10 being the highest
func
calculateScore
(
requested
,
capacity
int
,
node
string
)
int
{
func
calculateScore
(
requested
,
capacity
int
64
,
node
string
)
int
{
if
capacity
==
0
{
return
0
}
...
...
@@ -32,30 +31,39 @@ func calculateScore(requested, capacity int, node string) int {
glog
.
Errorf
(
"Combined requested resources from existing pods exceeds capacity on minion: %s"
,
node
)
return
0
}
return
((
capacity
-
requested
)
*
10
)
/
capacity
return
int
(((
capacity
-
requested
)
*
10
)
/
capacity
)
}
// Calculate the occupancy on a node. 'node' has information about the resources on the node.
// 'pods' is a list of pods currently scheduled on the node.
func
calculateOccupancy
(
pod
api
.
Pod
,
node
api
.
Node
,
pods
[]
api
.
Pod
)
HostPriority
{
total
CPU
:=
0
totalMemory
:=
0
total
MilliCPU
:=
int64
(
0
)
totalMemory
:=
int64
(
0
)
for
_
,
existingPod
:=
range
pods
{
for
_
,
container
:=
range
existingPod
.
Spec
.
Containers
{
total
CPU
+=
container
.
CPU
totalMemory
+=
container
.
Memory
total
MilliCPU
+=
container
.
CPU
.
MilliValue
()
totalMemory
+=
container
.
Memory
.
Value
()
}
}
// Add the resources requested by the current pod being scheduled.
// This also helps differentiate between differently sized, but empty, minions.
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
total
CPU
+=
container
.
CPU
totalMemory
+=
container
.
Memory
total
MilliCPU
+=
container
.
CPU
.
MilliValue
()
totalMemory
+=
container
.
Memory
.
Value
()
}
cpuScore
:=
calculateScore
(
totalCPU
,
resources
.
GetIntegerResource
(
node
.
Spec
.
Capacity
,
resources
.
CPU
,
0
),
node
.
Name
)
memoryScore
:=
calculateScore
(
totalMemory
,
resources
.
GetIntegerResource
(
node
.
Spec
.
Capacity
,
resources
.
Memory
,
0
),
node
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"Least Requested Priority, AbsoluteRequested: (%d, %d) Score:(%d, %d)"
,
totalCPU
,
totalMemory
,
cpuScore
,
memoryScore
)
capacityMilliCPU
:=
node
.
Spec
.
Capacity
.
Get
(
api
.
ResourceCPU
)
.
MilliValue
()
capacityMemory
:=
node
.
Spec
.
Capacity
.
Get
(
api
.
ResourceMemory
)
.
Value
()
cpuScore
:=
calculateScore
(
totalMilliCPU
,
capacityMilliCPU
,
node
.
Name
)
memoryScore
:=
calculateScore
(
totalMemory
,
capacityMemory
,
node
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"%v -> %v: Least Requested Priority, AbsoluteRequested: (%d, %d) / (%d, %d) Score: (%d, %d)"
,
pod
.
Name
,
node
.
Name
,
totalMilliCPU
,
totalMemory
,
capacityMilliCPU
,
capacityMemory
,
cpuScore
,
memoryScore
,
)
return
HostPriority
{
host
:
node
.
Name
,
...
...
pkg/scheduler/priorities_test.go
View file @
7f49ba0d
...
...
@@ -21,17 +21,16 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
)
func
makeMinion
(
node
string
,
cpu
,
memory
int
)
api
.
Node
{
func
makeMinion
(
node
string
,
milliCPU
,
memory
int64
)
api
.
Node
{
return
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
node
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
resources
.
CPU
:
util
.
NewIntOrStringFromInt
(
cpu
),
resources
.
Memory
:
util
.
NewIntOrStringFromInt
(
memory
),
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
milliCPU
,
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
memory
,
resource
.
BinarySI
),
},
},
}
...
...
@@ -57,14 +56,14 @@ func TestLeastRequested(t *testing.T) {
}
cpuOnly
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
CPU
:
1000
},
{
CPU
:
2000
},
{
CPU
:
*
resource
.
Q
(
"1000m"
)
},
{
CPU
:
*
resource
.
Q
(
"2000m"
)
},
},
}
cpuAndMemory
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
CPU
:
1000
,
Memory
:
2000
},
{
CPU
:
2000
,
Memory
:
3000
},
{
CPU
:
*
resource
.
Q
(
"1000m"
),
Memory
:
*
resource
.
Q
(
"2000"
)
},
{
CPU
:
*
resource
.
Q
(
"2000m"
),
Memory
:
*
resource
.
Q
(
"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