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
19379b5a
Commit
19379b5a
authored
Dec 07, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Internal rename api.Minion -> api.Node
parent
650aead4
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
212 additions
and
213 deletions
+212
-213
kubecfg.go
cmd/kubecfg/kubecfg.go
+1
-1
register.go
pkg/api/register.go
+6
-6
types.go
pkg/api/types.go
+6
-7
conversion.go
pkg/api/v1beta1/conversion.go
+4
-4
conversion_test.go
pkg/api/v1beta1/conversion_test.go
+14
-14
conversion.go
pkg/api/v1beta2/conversion.go
+2
-2
conversion_test.go
pkg/api/v1beta2/conversion_test.go
+2
-2
conversion_test.go
pkg/api/v1beta3/conversion_test.go
+2
-2
validation.go
pkg/api/validation/validation.go
+2
-2
validation_test.go
pkg/api/validation/validation_test.go
+13
-13
client_test.go
pkg/client/client_test.go
+3
-3
fake.go
pkg/client/fake.go
+1
-1
fake_minions.go
pkg/client/fake_minions.go
+5
-5
minions.go
pkg/client/minions.go
+9
-9
minioncontroller.go
pkg/cloudprovider/controller/minioncontroller.go
+6
-6
minioncontroller_test.go
pkg/cloudprovider/controller/minioncontroller_test.go
+16
-16
resource_printer.go
pkg/kubecfg/resource_printer.go
+2
-2
resource_printer.go
pkg/kubectl/resource_printer.go
+2
-2
etcd.go
pkg/registry/etcd/etcd.go
+6
-6
etcd_test.go
pkg/registry/etcd/etcd_test.go
+5
-5
healthy_registry.go
pkg/registry/minion/healthy_registry.go
+5
-5
healthy_registry_test.go
pkg/registry/minion/healthy_registry_test.go
+1
-1
registry.go
pkg/registry/minion/registry.go
+4
-4
rest.go
pkg/registry/minion/rest.go
+5
-5
rest_test.go
pkg/registry/minion/rest_test.go
+14
-14
rest_test.go
pkg/registry/pod/rest_test.go
+2
-2
minion.go
pkg/registry/registrytest/minion.go
+10
-10
rest.go
pkg/registry/service/rest.go
+1
-1
generic_scheduler.go
pkg/scheduler/generic_scheduler.go
+5
-5
generic_scheduler_test.go
pkg/scheduler/generic_scheduler_test.go
+3
-3
listers.go
pkg/scheduler/listers.go
+4
-4
predicates.go
pkg/scheduler/predicates.go
+4
-4
predicates_test.go
pkg/scheduler/predicates_test.go
+5
-5
priorities.go
pkg/scheduler/priorities.go
+1
-1
priorities_test.go
pkg/scheduler/priorities_test.go
+12
-12
factory.go
plugin/pkg/scheduler/factory/factory.go
+20
-20
factory_test.go
plugin/pkg/scheduler/factory/factory_test.go
+8
-8
scheduler_test.go
plugin/pkg/scheduler/scheduler_test.go
+1
-1
No files found.
cmd/kubecfg/kubecfg.go
View file @
19379b5a
...
...
@@ -79,7 +79,7 @@ var parser = kubecfg.NewParser(map[string]runtime.Object{
"pods"
:
&
api
.
Pod
{},
"services"
:
&
api
.
Service
{},
"replicationControllers"
:
&
api
.
ReplicationController
{},
"minions"
:
&
api
.
Minion
{},
"minions"
:
&
api
.
Node
{},
"events"
:
&
api
.
Event
{},
})
...
...
pkg/api/register.go
View file @
19379b5a
...
...
@@ -31,8 +31,8 @@ func init() {
&
ReplicationController
{},
&
ServiceList
{},
&
Service
{},
&
Minion
List
{},
&
Minion
{},
&
Node
List
{},
&
Node
{},
&
Status
{},
&
ServerOpList
{},
&
ServerOp
{},
...
...
@@ -47,8 +47,8 @@ func init() {
&
BoundPods
{},
)
// Legacy names are supported
Scheme
.
AddKnownTypeWithName
(
""
,
"
Node"
,
&
Minion
{})
Scheme
.
AddKnownTypeWithName
(
""
,
"
NodeList"
,
&
Minion
List
{})
Scheme
.
AddKnownTypeWithName
(
""
,
"
Minion"
,
&
Node
{})
Scheme
.
AddKnownTypeWithName
(
""
,
"
MinionList"
,
&
Node
List
{})
}
func
(
*
Pod
)
IsAnAPIObject
()
{}
...
...
@@ -59,8 +59,8 @@ func (*Service) IsAnAPIObject() {}
func
(
*
ServiceList
)
IsAnAPIObject
()
{}
func
(
*
Endpoints
)
IsAnAPIObject
()
{}
func
(
*
EndpointsList
)
IsAnAPIObject
()
{}
func
(
*
Minion
)
IsAnAPIObject
()
{}
func
(
*
MinionList
)
IsAnAPIObject
()
{}
func
(
*
Node
)
IsAnAPIObject
()
{}
func
(
*
NodeList
)
IsAnAPIObject
()
{}
func
(
*
Binding
)
IsAnAPIObject
()
{}
func
(
*
Status
)
IsAnAPIObject
()
{}
func
(
*
ServerOp
)
IsAnAPIObject
()
{}
...
...
pkg/api/types.go
View file @
19379b5a
...
...
@@ -672,10 +672,9 @@ type ResourceName string
type
ResourceList
map
[
ResourceName
]
util
.
IntOrString
// Minion is a worker node in Kubernetenes
// The name of the minion according to etcd is in ObjectMeta.Name.
// TODO: Rename to Node
type
Minion
struct
{
// Node is a worker node in Kubernetenes
// The name of the node according to etcd is in ObjectMeta.Name.
type
Node
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
...
...
@@ -686,12 +685,12 @@ type Minion struct {
Status
NodeStatus
`json:"status,omitempty"`
}
//
Minion
List is a list of minions.
type
Minion
List
struct
{
//
Node
List is a list of minions.
type
Node
List
struct
{
TypeMeta
`json:",inline"`
ListMeta
`json:"metadata,omitempty"`
Items
[]
Minion
`json:"items"`
Items
[]
Node
`json:"items"`
}
// Binding is written by a scheduler to cause a pod to be bound to a host.
...
...
pkg/api/v1beta1/conversion.go
View file @
19379b5a
...
...
@@ -137,7 +137,7 @@ func init() {
},
// MinionList.Items had a wrong name in v1beta1
func
(
in
*
newer
.
Minion
List
,
out
*
MinionList
,
s
conversion
.
Scope
)
error
{
func
(
in
*
newer
.
Node
List
,
out
*
MinionList
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
...
...
@@ -150,7 +150,7 @@ func init() {
out
.
Minions
=
out
.
Items
return
nil
},
func
(
in
*
MinionList
,
out
*
newer
.
Minion
List
,
s
conversion
.
Scope
)
error
{
func
(
in
*
MinionList
,
out
*
newer
.
Node
List
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
...
...
@@ -444,7 +444,7 @@ func init() {
return
nil
},
func
(
in
*
newer
.
Minion
,
out
*
Minion
,
s
conversion
.
Scope
)
error
{
func
(
in
*
newer
.
Node
,
out
*
Minion
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
...
...
@@ -458,7 +458,7 @@ func init() {
out
.
HostIP
=
in
.
Status
.
HostIP
return
s
.
Convert
(
&
in
.
Spec
.
Capacity
,
&
out
.
NodeResources
.
Capacity
,
0
)
},
func
(
in
*
Minion
,
out
*
newer
.
Minion
,
s
conversion
.
Scope
)
error
{
func
(
in
*
Minion
,
out
*
newer
.
Node
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
...
...
pkg/api/v1beta1/conversion_test.go
View file @
19379b5a
...
...
@@ -31,7 +31,7 @@ func TestNodeConversion(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
);
!
ok
{
if
_
,
ok
:=
obj
.
(
*
newer
.
Node
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
...
...
@@ -39,7 +39,7 @@ func TestNodeConversion(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
List
);
!
ok
{
if
_
,
ok
:=
obj
.
(
*
newer
.
Node
List
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
...
...
@@ -141,39 +141,39 @@ func TestMinionListConversionToNew(t *testing.T) {
oldMinion
:=
func
(
id
string
)
current
.
Minion
{
return
current
.
Minion
{
TypeMeta
:
current
.
TypeMeta
{
ID
:
id
}}
}
newMinion
:=
func
(
id
string
)
newer
.
Minion
{
return
newer
.
Minion
{
ObjectMeta
:
newer
.
ObjectMeta
{
Name
:
id
}}
newMinion
:=
func
(
id
string
)
newer
.
Node
{
return
newer
.
Node
{
ObjectMeta
:
newer
.
ObjectMeta
{
Name
:
id
}}
}
oldMinions
:=
[]
current
.
Minion
{
oldMinion
(
"foo"
),
oldMinion
(
"bar"
),
}
newMinions
:=
[]
newer
.
Minion
{
newMinions
:=
[]
newer
.
Node
{
newMinion
(
"foo"
),
newMinion
(
"bar"
),
}
table
:=
[]
struct
{
oldML
*
current
.
MinionList
newML
*
newer
.
Minion
List
newML
*
newer
.
Node
List
}{
{
oldML
:
&
current
.
MinionList
{
Items
:
oldMinions
},
newML
:
&
newer
.
Minion
List
{
Items
:
newMinions
},
newML
:
&
newer
.
Node
List
{
Items
:
newMinions
},
},
{
oldML
:
&
current
.
MinionList
{
Minions
:
oldMinions
},
newML
:
&
newer
.
Minion
List
{
Items
:
newMinions
},
newML
:
&
newer
.
Node
List
{
Items
:
newMinions
},
},
{
oldML
:
&
current
.
MinionList
{
Items
:
oldMinions
,
Minions
:
[]
current
.
Minion
{
oldMinion
(
"baz"
)},
},
newML
:
&
newer
.
Minion
List
{
Items
:
newMinions
},
newML
:
&
newer
.
Node
List
{
Items
:
newMinions
},
},
}
for
_
,
item
:=
range
table
{
got
:=
&
newer
.
Minion
List
{}
got
:=
&
newer
.
Node
List
{}
err
:=
Convert
(
item
.
oldML
,
got
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -188,19 +188,19 @@ func TestMinionListConversionToOld(t *testing.T) {
oldMinion
:=
func
(
id
string
)
current
.
Minion
{
return
current
.
Minion
{
TypeMeta
:
current
.
TypeMeta
{
ID
:
id
}}
}
newMinion
:=
func
(
id
string
)
newer
.
Minion
{
return
newer
.
Minion
{
ObjectMeta
:
newer
.
ObjectMeta
{
Name
:
id
}}
newMinion
:=
func
(
id
string
)
newer
.
Node
{
return
newer
.
Node
{
ObjectMeta
:
newer
.
ObjectMeta
{
Name
:
id
}}
}
oldMinions
:=
[]
current
.
Minion
{
oldMinion
(
"foo"
),
oldMinion
(
"bar"
),
}
newMinions
:=
[]
newer
.
Minion
{
newMinions
:=
[]
newer
.
Node
{
newMinion
(
"foo"
),
newMinion
(
"bar"
),
}
newML
:=
&
newer
.
Minion
List
{
Items
:
newMinions
}
newML
:=
&
newer
.
Node
List
{
Items
:
newMinions
}
oldML
:=
&
current
.
MinionList
{
Items
:
oldMinions
,
Minions
:
oldMinions
,
...
...
pkg/api/v1beta2/conversion.go
View file @
19379b5a
...
...
@@ -374,7 +374,7 @@ func init() {
return
nil
},
func
(
in
*
newer
.
Minion
,
out
*
Minion
,
s
conversion
.
Scope
)
error
{
func
(
in
*
newer
.
Node
,
out
*
Minion
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
...
...
@@ -388,7 +388,7 @@ func init() {
out
.
HostIP
=
in
.
Status
.
HostIP
return
s
.
Convert
(
&
in
.
Spec
.
Capacity
,
&
out
.
NodeResources
.
Capacity
,
0
)
},
func
(
in
*
Minion
,
out
*
newer
.
Minion
,
s
conversion
.
Scope
)
error
{
func
(
in
*
Minion
,
out
*
newer
.
Node
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
...
...
pkg/api/v1beta2/conversion_test.go
View file @
19379b5a
...
...
@@ -60,7 +60,7 @@ func TestNodeConversion(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
);
!
ok
{
if
_
,
ok
:=
obj
.
(
*
newer
.
Node
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
...
...
@@ -68,7 +68,7 @@ func TestNodeConversion(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
List
);
!
ok
{
if
_
,
ok
:=
obj
.
(
*
newer
.
Node
List
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
...
...
pkg/api/v1beta3/conversion_test.go
View file @
19379b5a
...
...
@@ -28,7 +28,7 @@ func TestNodeConversion(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
);
!
ok
{
if
_
,
ok
:=
obj
.
(
*
newer
.
Node
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
...
...
@@ -36,7 +36,7 @@ func TestNodeConversion(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
List
);
!
ok
{
if
_
,
ok
:=
obj
.
(
*
newer
.
Node
List
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
...
...
pkg/api/validation/validation.go
View file @
19379b5a
...
...
@@ -550,7 +550,7 @@ func ValidateBoundPod(pod *api.BoundPod) (errors []error) {
}
// ValidateMinion tests if required fields in the minion are set.
func
ValidateMinion
(
minion
*
api
.
Minion
)
errs
.
ValidationErrorList
{
func
ValidateMinion
(
minion
*
api
.
Node
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
if
len
(
minion
.
Namespace
)
!=
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
minion
.
Namespace
,
""
))
...
...
@@ -563,7 +563,7 @@ func ValidateMinion(minion *api.Minion) errs.ValidationErrorList {
}
// ValidateMinionUpdate tests to make sure a minion update can be applied. Modifies oldMinion.
func
ValidateMinionUpdate
(
oldMinion
*
api
.
Minion
,
minion
*
api
.
Minion
)
errs
.
ValidationErrorList
{
func
ValidateMinionUpdate
(
oldMinion
*
api
.
Node
,
minion
*
api
.
Node
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
oldMinion
.
Labels
=
minion
.
Labels
if
!
reflect
.
DeepEqual
(
oldMinion
,
minion
)
{
...
...
pkg/api/validation/validation_test.go
View file @
19379b5a
...
...
@@ -1077,7 +1077,7 @@ func TestValidateBoundPodNoName(t *testing.T) {
func
TestValidateMinion
(
t
*
testing
.
T
)
{
validSelector
:=
map
[
string
]
string
{
"a"
:
"b"
}
invalidSelector
:=
map
[
string
]
string
{
"NoUppercaseOrSpecialCharsLike=Equals"
:
"b"
}
successCases
:=
[]
api
.
Minion
{
successCases
:=
[]
api
.
Node
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
...
...
@@ -1100,7 +1100,7 @@ func TestValidateMinion(t *testing.T) {
}
}
errorCases
:=
map
[
string
]
api
.
Minion
{
errorCases
:=
map
[
string
]
api
.
Node
{
"zero-length Name"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
...
...
@@ -1134,45 +1134,45 @@ func TestValidateMinion(t *testing.T) {
func
TestValidateMinionUpdate
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
oldMinion
api
.
Minion
minion
api
.
Minion
oldMinion
api
.
Node
minion
api
.
Node
valid
bool
}{
{
api
.
Minion
{},
api
.
Minion
{},
true
},
{
api
.
Minion
{
{
api
.
Node
{},
api
.
Node
{},
true
},
{
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}},
api
.
Minion
{
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
},
false
},
{
api
.
Minion
{
{
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Labels
:
map
[
string
]
string
{
"foo"
:
"bar"
},
},
},
api
.
Minion
{
},
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Labels
:
map
[
string
]
string
{
"foo"
:
"baz"
},
},
},
true
},
{
api
.
Minion
{
{
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
},
},
api
.
Minion
{
},
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Labels
:
map
[
string
]
string
{
"foo"
:
"baz"
},
},
},
true
},
{
api
.
Minion
{
{
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Labels
:
map
[
string
]
string
{
"bar"
:
"foo"
},
},
},
api
.
Minion
{
},
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Labels
:
map
[
string
]
string
{
"foo"
:
"baz"
},
...
...
pkg/client/client_test.go
View file @
19379b5a
...
...
@@ -604,7 +604,7 @@ func TestGetServerAPIVersions(t *testing.T) {
func
TestListMinions
(
t
*
testing
.
T
)
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"GET"
,
Path
:
"/minions"
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
&
api
.
Minion
List
{
ListMeta
:
api
.
ListMeta
{
ResourceVersion
:
"1"
}}},
Response
:
Response
{
StatusCode
:
200
,
Body
:
&
api
.
Node
List
{
ListMeta
:
api
.
ListMeta
{
ResourceVersion
:
"1"
}}},
}
response
,
err
:=
c
.
Setup
()
.
Minions
()
.
List
()
c
.
Validate
(
t
,
response
,
err
)
...
...
@@ -613,14 +613,14 @@ func TestListMinions(t *testing.T) {
func
TestGetMinion
(
t
*
testing
.
T
)
{
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"GET"
,
Path
:
"/minions/1"
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"minion-1"
}}},
Response
:
Response
{
StatusCode
:
200
,
Body
:
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"minion-1"
}}},
}
response
,
err
:=
c
.
Setup
()
.
Minions
()
.
Get
(
"1"
)
c
.
Validate
(
t
,
response
,
err
)
}
func
TestCreateMinion
(
t
*
testing
.
T
)
{
requestMinion
:=
&
api
.
Minion
{
requestMinion
:=
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"minion-1"
,
},
...
...
pkg/client/fake.go
View file @
19379b5a
...
...
@@ -39,7 +39,7 @@ type Fake struct {
Ctrl
api
.
ReplicationController
ServiceList
api
.
ServiceList
EndpointsList
api
.
EndpointsList
MinionsList
api
.
Minion
List
MinionsList
api
.
Node
List
EventsList
api
.
EventList
Err
error
Watch
watch
.
Interface
...
...
pkg/client/fake_minions.go
View file @
19379b5a
...
...
@@ -26,19 +26,19 @@ type FakeMinions struct {
Fake
*
Fake
}
func
(
c
*
FakeMinions
)
Get
(
name
string
)
(
*
api
.
Minion
,
error
)
{
func
(
c
*
FakeMinions
)
Get
(
name
string
)
(
*
api
.
Node
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"get-minion"
,
Value
:
name
})
return
&
api
.
Minion
{},
nil
return
&
api
.
Node
{},
nil
}
func
(
c
*
FakeMinions
)
List
()
(
*
api
.
Minion
List
,
error
)
{
func
(
c
*
FakeMinions
)
List
()
(
*
api
.
Node
List
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"list-minions"
,
Value
:
nil
})
return
&
c
.
Fake
.
MinionsList
,
nil
}
func
(
c
*
FakeMinions
)
Create
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
{
func
(
c
*
FakeMinions
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"create-minion"
,
Value
:
minion
})
return
&
api
.
Minion
{},
nil
return
&
api
.
Node
{},
nil
}
func
(
c
*
FakeMinions
)
Delete
(
id
string
)
error
{
...
...
pkg/client/minions.go
View file @
19379b5a
...
...
@@ -23,9 +23,9 @@ type MinionsInterface interface {
}
type
MinionInterface
interface
{
Get
(
id
string
)
(
result
*
api
.
Minion
,
err
error
)
Create
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
List
()
(
*
api
.
Minion
List
,
error
)
Get
(
id
string
)
(
result
*
api
.
Node
,
err
error
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
List
()
(
*
api
.
Node
List
,
error
)
Delete
(
id
string
)
error
}
...
...
@@ -40,22 +40,22 @@ func newMinions(c *Client) *minions {
}
// Create creates a new minion.
func
(
c
*
minions
)
Create
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
{
result
:=
&
api
.
Minion
{}
func
(
c
*
minions
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
{
result
:=
&
api
.
Node
{}
err
:=
c
.
r
.
Post
()
.
Path
(
"minions"
)
.
Body
(
minion
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
// List lists all the minions in the cluster.
func
(
c
*
minions
)
List
()
(
*
api
.
Minion
List
,
error
)
{
result
:=
&
api
.
Minion
List
{}
func
(
c
*
minions
)
List
()
(
*
api
.
Node
List
,
error
)
{
result
:=
&
api
.
Node
List
{}
err
:=
c
.
r
.
Get
()
.
Path
(
"minions"
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
// Get gets an existing minion
func
(
c
*
minions
)
Get
(
id
string
)
(
*
api
.
Minion
,
error
)
{
result
:=
&
api
.
Minion
{}
func
(
c
*
minions
)
Get
(
id
string
)
(
*
api
.
Node
,
error
)
{
result
:=
&
api
.
Node
{}
err
:=
c
.
r
.
Get
()
.
Path
(
"minions"
)
.
Path
(
id
)
.
Do
()
.
Into
(
result
)
return
result
,
err
}
...
...
pkg/cloudprovider/controller/minioncontroller.go
View file @
19379b5a
...
...
@@ -73,7 +73,7 @@ func (s *MinionController) SyncStatic(period time.Duration) error {
if
registered
.
Has
(
minionID
)
{
continue
}
_
,
err
:=
s
.
kubeClient
.
Minions
()
.
Create
(
&
api
.
Minion
{
_
,
err
:=
s
.
kubeClient
.
Minions
()
.
Create
(
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
minionID
},
Spec
:
api
.
NodeSpec
{
Capacity
:
s
.
staticResources
.
Capacity
,
...
...
@@ -101,7 +101,7 @@ func (s *MinionController) SyncCloud() error {
if
err
!=
nil
{
return
err
}
minionMap
:=
make
(
map
[
string
]
*
api
.
Minion
)
minionMap
:=
make
(
map
[
string
]
*
api
.
Node
)
for
_
,
minion
:=
range
minions
.
Items
{
minionMap
[
minion
.
Name
]
=
&
minion
}
...
...
@@ -128,8 +128,8 @@ func (s *MinionController) SyncCloud() error {
return
nil
}
// cloudMinions constructs and returns api.
Minion
List from cloudprovider.
func
(
s
*
MinionController
)
cloudMinions
()
(
*
api
.
Minion
List
,
error
)
{
// cloudMinions constructs and returns api.
Node
List from cloudprovider.
func
(
s
*
MinionController
)
cloudMinions
()
(
*
api
.
Node
List
,
error
)
{
instances
,
ok
:=
s
.
cloud
.
Instances
()
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"cloud doesn't support instances"
)
...
...
@@ -138,8 +138,8 @@ func (s *MinionController) cloudMinions() (*api.MinionList, error) {
if
err
!=
nil
{
return
nil
,
err
}
result
:=
&
api
.
Minion
List
{
Items
:
make
([]
api
.
Minion
,
len
(
matches
)),
result
:=
&
api
.
Node
List
{
Items
:
make
([]
api
.
Node
,
len
(
matches
)),
}
for
i
:=
range
matches
{
result
.
Items
[
i
]
.
Name
=
matches
[
i
]
...
...
pkg/cloudprovider/controller/minioncontroller_test.go
View file @
19379b5a
...
...
@@ -26,8 +26,8 @@ import (
fake_cloud
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
)
func
newMinion
(
name
string
)
*
api
.
Minion
{
return
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}}
func
newMinion
(
name
string
)
*
api
.
Node
{
return
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}}
}
type
FakeMinionHandler
struct
{
...
...
@@ -35,12 +35,12 @@ type FakeMinionHandler struct {
client
.
FakeMinions
// Input: Hooks determine if request is valid or not
CreateHook
func
(
*
FakeMinionHandler
,
*
api
.
Minion
)
bool
Existing
[]
*
api
.
Minion
CreateHook
func
(
*
FakeMinionHandler
,
*
api
.
Node
)
bool
Existing
[]
*
api
.
Node
// Output
CreatedMinions
[]
*
api
.
Minion
DeletedMinions
[]
*
api
.
Minion
CreatedMinions
[]
*
api
.
Node
DeletedMinions
[]
*
api
.
Node
RequestCount
int
}
...
...
@@ -48,7 +48,7 @@ func (c *FakeMinionHandler) Minions() client.MinionInterface {
return
c
}
func
(
m
*
FakeMinionHandler
)
Create
(
minion
*
api
.
Minion
)
(
*
api
.
Minion
,
error
)
{
func
(
m
*
FakeMinionHandler
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
{
defer
func
()
{
m
.
RequestCount
++
}()
if
m
.
CreateHook
==
nil
||
m
.
CreateHook
(
m
,
minion
)
{
m
.
CreatedMinions
=
append
(
m
.
CreatedMinions
,
minion
)
...
...
@@ -58,9 +58,9 @@ func (m *FakeMinionHandler) Create(minion *api.Minion) (*api.Minion, error) {
}
}
func
(
m
*
FakeMinionHandler
)
List
()
(
*
api
.
Minion
List
,
error
)
{
func
(
m
*
FakeMinionHandler
)
List
()
(
*
api
.
Node
List
,
error
)
{
defer
func
()
{
m
.
RequestCount
++
}()
minions
:=
[]
api
.
Minion
{}
minions
:=
[]
api
.
Node
{}
for
i
:=
0
;
i
<
len
(
m
.
Existing
);
i
++
{
if
!
contains
(
m
.
Existing
[
i
],
m
.
DeletedMinions
)
{
minions
=
append
(
minions
,
*
m
.
Existing
[
i
])
...
...
@@ -71,7 +71,7 @@ func (m *FakeMinionHandler) List() (*api.MinionList, error) {
minions
=
append
(
minions
,
*
m
.
CreatedMinions
[
i
])
}
}
return
&
api
.
Minion
List
{
Items
:
minions
},
nil
return
&
api
.
Node
List
{
Items
:
minions
},
nil
}
func
(
m
*
FakeMinionHandler
)
Delete
(
id
string
)
error
{
...
...
@@ -82,7 +82,7 @@ func (m *FakeMinionHandler) Delete(id string) error {
func
TestSyncStaticCreateMinion
(
t
*
testing
.
T
)
{
fakeMinionHandler
:=
&
FakeMinionHandler
{
CreateHook
:
func
(
fake
*
FakeMinionHandler
,
minion
*
api
.
Minion
)
bool
{
CreateHook
:
func
(
fake
*
FakeMinionHandler
,
minion
*
api
.
Node
)
bool
{
return
true
},
}
...
...
@@ -104,7 +104,7 @@ func TestSyncStaticCreateMinion(t *testing.T) {
func
TestSyncStaticCreateMinionWithError
(
t
*
testing
.
T
)
{
fakeMinionHandler
:=
&
FakeMinionHandler
{
CreateHook
:
func
(
fake
*
FakeMinionHandler
,
minion
*
api
.
Minion
)
bool
{
CreateHook
:
func
(
fake
*
FakeMinionHandler
,
minion
*
api
.
Node
)
bool
{
if
fake
.
RequestCount
==
0
{
return
false
}
...
...
@@ -129,7 +129,7 @@ func TestSyncStaticCreateMinionWithError(t *testing.T) {
func
TestSyncCloudCreateMinion
(
t
*
testing
.
T
)
{
fakeMinionHandler
:=
&
FakeMinionHandler
{
Existing
:
[]
*
api
.
Minion
{
newMinion
(
"minion0"
)},
Existing
:
[]
*
api
.
Node
{
newMinion
(
"minion0"
)},
}
instances
:=
[]
string
{
"minion0"
,
"minion1"
}
fakeCloud
:=
fake_cloud
.
FakeCloud
{
...
...
@@ -153,7 +153,7 @@ func TestSyncCloudCreateMinion(t *testing.T) {
func
TestSyncCloudDeleteMinion
(
t
*
testing
.
T
)
{
fakeMinionHandler
:=
&
FakeMinionHandler
{
Existing
:
[]
*
api
.
Minion
{
newMinion
(
"minion0"
),
newMinion
(
"minion1"
)},
Existing
:
[]
*
api
.
Node
{
newMinion
(
"minion0"
),
newMinion
(
"minion1"
)},
}
instances
:=
[]
string
{
"minion0"
}
fakeCloud
:=
fake_cloud
.
FakeCloud
{
...
...
@@ -177,7 +177,7 @@ func TestSyncCloudDeleteMinion(t *testing.T) {
func
TestSyncCloudRegexp
(
t
*
testing
.
T
)
{
fakeMinionHandler
:=
&
FakeMinionHandler
{
Existing
:
[]
*
api
.
Minion
{
newMinion
(
"minion0"
)},
Existing
:
[]
*
api
.
Node
{
newMinion
(
"minion0"
)},
}
instances
:=
[]
string
{
"minion0"
,
"minion1"
,
"node0"
}
fakeCloud
:=
fake_cloud
.
FakeCloud
{
...
...
@@ -199,7 +199,7 @@ func TestSyncCloudRegexp(t *testing.T) {
}
}
func
contains
(
minion
*
api
.
Minion
,
minions
[]
*
api
.
Minion
)
bool
{
func
contains
(
minion
*
api
.
Node
,
minions
[]
*
api
.
Node
)
bool
{
for
i
:=
0
;
i
<
len
(
minions
);
i
++
{
if
minion
.
Name
==
minions
[
i
]
.
Name
{
return
true
...
...
pkg/kubecfg/resource_printer.go
View file @
19379b5a
...
...
@@ -248,12 +248,12 @@ func printServiceList(list *api.ServiceList, w io.Writer) error {
return
nil
}
func
printMinion
(
minion
*
api
.
Minion
,
w
io
.
Writer
)
error
{
func
printMinion
(
minion
*
api
.
Node
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\n
"
,
minion
.
Name
,
labels
.
Set
(
minion
.
Labels
))
return
err
}
func
printMinionList
(
list
*
api
.
Minion
List
,
w
io
.
Writer
)
error
{
func
printMinionList
(
list
*
api
.
Node
List
,
w
io
.
Writer
)
error
{
for
_
,
minion
:=
range
list
.
Items
{
if
err
:=
printMinion
(
&
minion
,
w
);
err
!=
nil
{
return
err
...
...
pkg/kubectl/resource_printer.go
View file @
19379b5a
...
...
@@ -296,12 +296,12 @@ func printServiceList(list *api.ServiceList, w io.Writer) error {
return
nil
}
func
printMinion
(
minion
*
api
.
Minion
,
w
io
.
Writer
)
error
{
func
printMinion
(
minion
*
api
.
Node
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\n
"
,
minion
.
Name
,
formatLabels
(
minion
.
Labels
))
return
err
}
func
printMinionList
(
list
*
api
.
Minion
List
,
w
io
.
Writer
)
error
{
func
printMinionList
(
list
*
api
.
Node
List
,
w
io
.
Writer
)
error
{
for
_
,
minion
:=
range
list
.
Items
{
if
err
:=
printMinion
(
&
minion
,
w
);
err
!=
nil
{
return
err
...
...
pkg/registry/etcd/etcd.go
View file @
19379b5a
...
...
@@ -559,26 +559,26 @@ func makeMinionKey(minionID string) string {
return
"/registry/minions/"
+
minionID
}
func
(
r
*
Registry
)
ListMinions
(
ctx
api
.
Context
)
(
*
api
.
Minion
List
,
error
)
{
minions
:=
&
api
.
Minion
List
{}
func
(
r
*
Registry
)
ListMinions
(
ctx
api
.
Context
)
(
*
api
.
Node
List
,
error
)
{
minions
:=
&
api
.
Node
List
{}
err
:=
r
.
ExtractToList
(
"/registry/minions"
,
minions
)
return
minions
,
err
}
func
(
r
*
Registry
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
{
func
(
r
*
Registry
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
{
// TODO: Add some validations.
err
:=
r
.
CreateObj
(
makeMinionKey
(
minion
.
Name
),
minion
,
0
)
return
etcderr
.
InterpretCreateError
(
err
,
"minion"
,
minion
.
Name
)
}
func
(
r
*
Registry
)
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
{
func
(
r
*
Registry
)
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
{
// TODO: Add some validations.
err
:=
r
.
SetObj
(
makeMinionKey
(
minion
.
Name
),
minion
)
return
etcderr
.
InterpretUpdateError
(
err
,
"minion"
,
minion
.
Name
)
}
func
(
r
*
Registry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Minion
,
error
)
{
var
minion
api
.
Minion
func
(
r
*
Registry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
var
minion
api
.
Node
key
:=
makeMinionKey
(
minionID
)
err
:=
r
.
ExtractObj
(
key
,
&
minion
,
false
)
if
err
!=
nil
{
...
...
pkg/registry/etcd/etcd_test.go
View file @
19379b5a
...
...
@@ -1364,12 +1364,12 @@ func TestEtcdListMinions(t *testing.T) {
Node
:
&
etcd
.
Node
{
Nodes
:
[]
*
etcd
.
Node
{
{
Value
:
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
Minion
{
Value
:
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
}),
},
{
Value
:
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
Minion
{
Value
:
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
}),
},
...
...
@@ -1393,7 +1393,7 @@ func TestEtcdCreateMinion(t *testing.T) {
ctx
:=
api
.
NewContext
()
fakeClient
:=
tools
.
NewFakeEtcdClient
(
t
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
err
:=
registry
.
CreateMinion
(
ctx
,
&
api
.
Minion
{
err
:=
registry
.
CreateMinion
(
ctx
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
})
if
err
!=
nil
{
...
...
@@ -1405,7 +1405,7 @@ func TestEtcdCreateMinion(t *testing.T) {
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
var
minion
api
.
Minion
var
minion
api
.
Node
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
minion
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
...
@@ -1419,7 +1419,7 @@ func TestEtcdCreateMinion(t *testing.T) {
func
TestEtcdGetMinion
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewContext
()
fakeClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeClient
.
Set
(
"/registry/minions/foo"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
0
)
fakeClient
.
Set
(
"/registry/minions/foo"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
minion
,
err
:=
registry
.
GetMinion
(
ctx
,
"foo"
)
if
err
!=
nil
{
...
...
pkg/registry/minion/healthy_registry.go
View file @
19379b5a
...
...
@@ -36,7 +36,7 @@ func NewHealthyRegistry(delegate Registry, client client.KubeletHealthChecker) R
}
}
func
(
r
*
HealthyRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Minion
,
error
)
{
func
(
r
*
HealthyRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
minion
,
err
:=
r
.
delegate
.
GetMinion
(
ctx
,
minionID
)
if
minion
==
nil
{
return
nil
,
ErrDoesNotExist
...
...
@@ -58,16 +58,16 @@ func (r *HealthyRegistry) DeleteMinion(ctx api.Context, minionID string) error {
return
r
.
delegate
.
DeleteMinion
(
ctx
,
minionID
)
}
func
(
r
*
HealthyRegistry
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
{
func
(
r
*
HealthyRegistry
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
{
return
r
.
delegate
.
CreateMinion
(
ctx
,
minion
)
}
func
(
r
*
HealthyRegistry
)
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
{
func
(
r
*
HealthyRegistry
)
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
{
return
r
.
delegate
.
UpdateMinion
(
ctx
,
minion
)
}
func
(
r
*
HealthyRegistry
)
ListMinions
(
ctx
api
.
Context
)
(
currentMinions
*
api
.
Minion
List
,
err
error
)
{
result
:=
&
api
.
Minion
List
{}
func
(
r
*
HealthyRegistry
)
ListMinions
(
ctx
api
.
Context
)
(
currentMinions
*
api
.
Node
List
,
err
error
)
{
result
:=
&
api
.
Node
List
{}
list
,
err
:=
r
.
delegate
.
ListMinions
(
ctx
)
if
err
!=
nil
{
return
result
,
err
...
...
pkg/registry/minion/healthy_registry_test.go
View file @
19379b5a
...
...
@@ -45,7 +45,7 @@ func TestBasicDelegation(t *testing.T) {
if
!
reflect
.
DeepEqual
(
list
,
&
mockMinionRegistry
.
Minions
)
{
t
.
Errorf
(
"Expected %v, Got %v"
,
mockMinionRegistry
.
Minions
,
list
)
}
err
=
healthy
.
CreateMinion
(
ctx
,
&
api
.
Minion
{
err
=
healthy
.
CreateMinion
(
ctx
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
})
if
err
!=
nil
{
...
...
pkg/registry/minion/registry.go
View file @
19379b5a
...
...
@@ -20,9 +20,9 @@ import "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
// MinionRegistry is an interface for things that know how to store minions.
type
Registry
interface
{
ListMinions
(
ctx
api
.
Context
)
(
*
api
.
Minion
List
,
error
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Minion
,
error
)
ListMinions
(
ctx
api
.
Context
)
(
*
api
.
Node
List
,
error
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
DeleteMinion
(
ctx
api
.
Context
,
minionID
string
)
error
}
pkg/registry/minion/rest.go
View file @
19379b5a
...
...
@@ -47,7 +47,7 @@ var ErrDoesNotExist = errors.New("The requested resource does not exist.")
var
ErrNotHealty
=
errors
.
New
(
"The requested minion is not healthy."
)
func
(
rs
*
REST
)
Create
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
<-
chan
apiserver
.
RESTResult
,
error
)
{
minion
,
ok
:=
obj
.
(
*
api
.
Minion
)
minion
,
ok
:=
obj
.
(
*
api
.
Node
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"not a minion: %#v"
,
obj
)
}
...
...
@@ -93,11 +93,11 @@ func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Obj
}
func
(
rs
*
REST
)
New
()
runtime
.
Object
{
return
&
api
.
Minion
{}
return
&
api
.
Node
{}
}
func
(
rs
*
REST
)
Update
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
<-
chan
apiserver
.
RESTResult
,
error
)
{
minion
,
ok
:=
obj
.
(
*
api
.
Minion
)
minion
,
ok
:=
obj
.
(
*
api
.
Node
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"not a minion: %#v"
,
obj
)
}
...
...
@@ -121,8 +121,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
}),
nil
}
func
(
rs
*
REST
)
toApiMinion
(
name
string
)
*
api
.
Minion
{
return
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}}
func
(
rs
*
REST
)
toApiMinion
(
name
string
)
*
api
.
Node
{
return
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}}
}
// ResourceLocation returns a URL to which one can send traffic for the specified minion.
...
...
pkg/registry/minion/rest_test.go
View file @
19379b5a
...
...
@@ -28,28 +28,28 @@ import (
func
TestMinionREST
(
t
*
testing
.
T
)
{
ms
:=
NewREST
(
registrytest
.
NewMinionRegistry
([]
string
{
"foo"
,
"bar"
},
api
.
NodeResources
{}))
ctx
:=
api
.
NewContext
()
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"foo"
);
err
!=
nil
||
obj
.
(
*
api
.
Minion
)
.
Name
!=
"foo"
{
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"foo"
);
err
!=
nil
||
obj
.
(
*
api
.
Node
)
.
Name
!=
"foo"
{
t
.
Errorf
(
"missing expected object"
)
}
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"bar"
);
err
!=
nil
||
obj
.
(
*
api
.
Minion
)
.
Name
!=
"bar"
{
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"bar"
);
err
!=
nil
||
obj
.
(
*
api
.
Node
)
.
Name
!=
"bar"
{
t
.
Errorf
(
"missing expected object"
)
}
if
_
,
err
:=
ms
.
Get
(
ctx
,
"baz"
);
err
!=
ErrDoesNotExist
{
t
.
Errorf
(
"has unexpected object"
)
}
c
,
err
:=
ms
.
Create
(
ctx
,
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
}})
c
,
err
:=
ms
.
Create
(
ctx
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
}})
if
err
!=
nil
{
t
.
Errorf
(
"insert failed"
)
}
obj
:=
<-
c
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
obj
.
Object
.
(
*
api
.
Minion
)
.
ObjectMeta
)
{
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
obj
.
Object
.
(
*
api
.
Node
)
.
ObjectMeta
)
{
t
.
Errorf
(
"storage did not populate object meta field values"
)
}
if
m
,
ok
:=
obj
.
Object
.
(
*
api
.
Minion
);
!
ok
||
m
.
Name
!=
"baz"
{
if
m
,
ok
:=
obj
.
Object
.
(
*
api
.
Node
);
!
ok
||
m
.
Name
!=
"baz"
{
t
.
Errorf
(
"insert return value was weird: %#v"
,
obj
)
}
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"baz"
);
err
!=
nil
||
obj
.
(
*
api
.
Minion
)
.
Name
!=
"baz"
{
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"baz"
);
err
!=
nil
||
obj
.
(
*
api
.
Node
)
.
Name
!=
"baz"
{
t
.
Errorf
(
"insert didn't actually insert"
)
}
...
...
@@ -74,14 +74,14 @@ func TestMinionREST(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"got error calling List"
)
}
expect
:=
[]
api
.
Minion
{
expect
:=
[]
api
.
Node
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
},
},
}
nodeList
:=
list
.
(
*
api
.
Minion
List
)
nodeList
:=
list
.
(
*
api
.
Node
List
)
if
len
(
expect
)
!=
len
(
nodeList
.
Items
)
||
!
contains
(
nodeList
,
"foo"
)
||
!
contains
(
nodeList
,
"baz"
)
{
t
.
Errorf
(
"Unexpected list value: %#v"
,
list
)
}
...
...
@@ -97,12 +97,12 @@ func TestMinionStorageWithHealthCheck(t *testing.T) {
ms
:=
NewREST
(
&
minionHealthRegistry
)
ctx
:=
api
.
NewContext
()
c
,
err
:=
ms
.
Create
(
ctx
,
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"m1"
}})
c
,
err
:=
ms
.
Create
(
ctx
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"m1"
}})
if
err
!=
nil
{
t
.
Errorf
(
"insert failed"
)
}
result
:=
<-
c
if
m
,
ok
:=
result
.
Object
.
(
*
api
.
Minion
);
!
ok
||
m
.
Name
!=
"m1"
{
if
m
,
ok
:=
result
.
Object
.
(
*
api
.
Node
);
!
ok
||
m
.
Name
!=
"m1"
{
t
.
Errorf
(
"insert return value was weird: %#v"
,
result
)
}
if
_
,
err
:=
ms
.
Get
(
ctx
,
"m1"
);
err
==
nil
{
...
...
@@ -110,7 +110,7 @@ func TestMinionStorageWithHealthCheck(t *testing.T) {
}
}
func
contains
(
nodes
*
api
.
Minion
List
,
nodeID
string
)
bool
{
func
contains
(
nodes
*
api
.
Node
List
,
nodeID
string
)
bool
{
for
_
,
node
:=
range
nodes
.
Items
{
if
node
.
Name
==
nodeID
{
return
true
...
...
@@ -126,7 +126,7 @@ func TestMinionStorageInvalidUpdate(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
minion
,
ok
:=
obj
.
(
*
api
.
Minion
)
minion
,
ok
:=
obj
.
(
*
api
.
Node
)
if
!
ok
{
t
.
Fatalf
(
"Object is not a minion: %#v"
,
obj
)
}
...
...
@@ -143,7 +143,7 @@ func TestMinionStorageValidUpdate(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
minion
,
ok
:=
obj
.
(
*
api
.
Minion
)
minion
,
ok
:=
obj
.
(
*
api
.
Node
)
if
!
ok
{
t
.
Fatalf
(
"Object is not a minion: %#v"
,
obj
)
}
...
...
@@ -161,7 +161,7 @@ func TestMinionStorageValidatesCreate(t *testing.T) {
ctx
:=
api
.
NewContext
()
validSelector
:=
map
[
string
]
string
{
"a"
:
"b"
}
invalidSelector
:=
map
[
string
]
string
{
"NoUppercaseOrSpecialCharsLike=Equals"
:
"b"
}
failureCases
:=
map
[
string
]
api
.
Minion
{
failureCases
:=
map
[
string
]
api
.
Node
{
"zero-length Name"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
...
...
pkg/registry/pod/rest_test.go
View file @
19379b5a
...
...
@@ -370,8 +370,8 @@ func TestGetPodCloud(t *testing.T) {
func
TestMakePodStatus
(
t
*
testing
.
T
)
{
fakeClient
:=
client
.
Fake
{
MinionsList
:
api
.
Minion
List
{
Items
:
[]
api
.
Minion
{
MinionsList
:
api
.
Node
List
{
Items
:
[]
api
.
Node
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"machine"
},
},
...
...
pkg/registry/registrytest/minion.go
View file @
19379b5a
...
...
@@ -25,13 +25,13 @@ import (
type
MinionRegistry
struct
{
Err
error
Minion
string
Minions
api
.
Minion
List
Minions
api
.
Node
List
sync
.
Mutex
}
func
MakeMinionList
(
minions
[]
string
,
nodeResources
api
.
NodeResources
)
*
api
.
Minion
List
{
list
:=
api
.
Minion
List
{
Items
:
make
([]
api
.
Minion
,
len
(
minions
)),
func
MakeMinionList
(
minions
[]
string
,
nodeResources
api
.
NodeResources
)
*
api
.
Node
List
{
list
:=
api
.
Node
List
{
Items
:
make
([]
api
.
Node
,
len
(
minions
)),
}
for
i
:=
range
minions
{
list
.
Items
[
i
]
.
Name
=
minions
[
i
]
...
...
@@ -46,13 +46,13 @@ func NewMinionRegistry(minions []string, nodeResources api.NodeResources) *Minio
}
}
func
(
r
*
MinionRegistry
)
ListMinions
(
ctx
api
.
Context
)
(
*
api
.
Minion
List
,
error
)
{
func
(
r
*
MinionRegistry
)
ListMinions
(
ctx
api
.
Context
)
(
*
api
.
Node
List
,
error
)
{
r
.
Lock
()
defer
r
.
Unlock
()
return
&
r
.
Minions
,
r
.
Err
}
func
(
r
*
MinionRegistry
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
{
func
(
r
*
MinionRegistry
)
CreateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
{
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Minion
=
minion
.
Name
...
...
@@ -60,7 +60,7 @@ func (r *MinionRegistry) CreateMinion(ctx api.Context, minion *api.Minion) error
return
r
.
Err
}
func
(
r
*
MinionRegistry
)
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Minion
)
error
{
func
(
r
*
MinionRegistry
)
UpdateMinion
(
ctx
api
.
Context
,
minion
*
api
.
Node
)
error
{
r
.
Lock
()
defer
r
.
Unlock
()
for
i
,
node
:=
range
r
.
Minions
.
Items
{
...
...
@@ -72,7 +72,7 @@ func (r *MinionRegistry) UpdateMinion(ctx api.Context, minion *api.Minion) error
return
r
.
Err
}
func
(
r
*
MinionRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Minion
,
error
)
{
func
(
r
*
MinionRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
r
.
Lock
()
defer
r
.
Unlock
()
for
_
,
node
:=
range
r
.
Minions
.
Items
{
...
...
@@ -86,10 +86,10 @@ func (r *MinionRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minio
func
(
r
*
MinionRegistry
)
DeleteMinion
(
ctx
api
.
Context
,
minionID
string
)
error
{
r
.
Lock
()
defer
r
.
Unlock
()
var
newList
[]
api
.
Minion
var
newList
[]
api
.
Node
for
_
,
node
:=
range
r
.
Minions
.
Items
{
if
node
.
Name
!=
minionID
{
newList
=
append
(
newList
,
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
node
.
Name
}})
newList
=
append
(
newList
,
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
node
.
Name
}})
}
}
r
.
Minions
.
Items
=
newList
...
...
pkg/registry/service/rest.go
View file @
19379b5a
...
...
@@ -154,7 +154,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
}),
nil
}
func
hostsFromMinionList
(
list
*
api
.
Minion
List
)
[]
string
{
func
hostsFromMinionList
(
list
*
api
.
Node
List
)
[]
string
{
result
:=
make
([]
string
,
len
(
list
.
Items
))
for
ix
:=
range
list
.
Items
{
result
[
ix
]
=
list
.
Items
[
ix
]
.
Name
...
...
pkg/scheduler/generic_scheduler.go
View file @
19379b5a
...
...
@@ -76,18 +76,18 @@ func (g *genericScheduler) selectHost(priorityList HostPriorityList) (string, er
// Filters the minions to find the ones that fit based on the given predicate functions
// Each minion is passed through the predicate functions to determine if it is a fit
func
findNodesThatFit
(
pod
api
.
Pod
,
podLister
PodLister
,
predicates
[]
FitPredicate
,
nodes
api
.
MinionList
)
(
api
.
Minion
List
,
error
)
{
filtered
:=
[]
api
.
Minion
{}
func
findNodesThatFit
(
pod
api
.
Pod
,
podLister
PodLister
,
predicates
[]
FitPredicate
,
nodes
api
.
NodeList
)
(
api
.
Node
List
,
error
)
{
filtered
:=
[]
api
.
Node
{}
machineToPods
,
err
:=
MapPodsToMachines
(
podLister
)
if
err
!=
nil
{
return
api
.
Minion
List
{},
err
return
api
.
Node
List
{},
err
}
for
_
,
node
:=
range
nodes
.
Items
{
fits
:=
true
for
_
,
predicate
:=
range
predicates
{
fit
,
err
:=
predicate
(
pod
,
machineToPods
[
node
.
Name
],
node
.
Name
)
if
err
!=
nil
{
return
api
.
Minion
List
{},
err
return
api
.
Node
List
{},
err
}
if
!
fit
{
fits
=
false
...
...
@@ -98,7 +98,7 @@ func findNodesThatFit(pod api.Pod, podLister PodLister, predicates []FitPredicat
filtered
=
append
(
filtered
,
node
)
}
}
return
api
.
Minion
List
{
Items
:
filtered
},
nil
return
api
.
Node
List
{
Items
:
filtered
},
nil
}
// Prioritizes the minions by running the individual priority functions sequentially.
...
...
pkg/scheduler/generic_scheduler_test.go
View file @
19379b5a
...
...
@@ -83,9 +83,9 @@ func reverseNumericPriority(pod api.Pod, podLister PodLister, minionLister Minio
return
reverseResult
,
nil
}
func
makeMinionList
(
nodeNames
[]
string
)
api
.
Minion
List
{
result
:=
api
.
Minion
List
{
Items
:
make
([]
api
.
Minion
,
len
(
nodeNames
)),
func
makeMinionList
(
nodeNames
[]
string
)
api
.
Node
List
{
result
:=
api
.
Node
List
{
Items
:
make
([]
api
.
Node
,
len
(
nodeNames
)),
}
for
ix
:=
range
nodeNames
{
result
.
Items
[
ix
]
.
Name
=
nodeNames
[
ix
]
...
...
pkg/scheduler/listers.go
View file @
19379b5a
...
...
@@ -23,15 +23,15 @@ import (
// MinionLister interface represents anything that can list minions for a scheduler.
type
MinionLister
interface
{
List
()
(
list
api
.
Minion
List
,
err
error
)
List
()
(
list
api
.
Node
List
,
err
error
)
}
// FakeMinionLister implements MinionLister on a []string for test purposes.
type
FakeMinionLister
api
.
Minion
List
type
FakeMinionLister
api
.
Node
List
// List returns minions as a []string.
func
(
f
FakeMinionLister
)
List
()
(
api
.
Minion
List
,
error
)
{
return
api
.
Minion
List
(
f
),
nil
func
(
f
FakeMinionLister
)
List
()
(
api
.
Node
List
,
error
)
{
return
api
.
Node
List
(
f
),
nil
}
// PodLister interface represents anything that can list pods for a scheduler.
...
...
pkg/scheduler/predicates.go
View file @
19379b5a
...
...
@@ -27,14 +27,14 @@ import (
)
type
NodeInfo
interface
{
GetNodeInfo
(
nodeID
string
)
(
*
api
.
Minion
,
error
)
GetNodeInfo
(
nodeID
string
)
(
*
api
.
Node
,
error
)
}
type
StaticNodeInfo
struct
{
*
api
.
Minion
List
*
api
.
Node
List
}
func
(
nodes
StaticNodeInfo
)
GetNodeInfo
(
nodeID
string
)
(
*
api
.
Minion
,
error
)
{
func
(
nodes
StaticNodeInfo
)
GetNodeInfo
(
nodeID
string
)
(
*
api
.
Node
,
error
)
{
for
ix
:=
range
nodes
.
Items
{
if
nodes
.
Items
[
ix
]
.
Name
==
nodeID
{
return
&
nodes
.
Items
[
ix
],
nil
...
...
@@ -47,7 +47,7 @@ type ClientNodeInfo struct {
*
client
.
Client
}
func
(
nodes
ClientNodeInfo
)
GetNodeInfo
(
nodeID
string
)
(
*
api
.
Minion
,
error
)
{
func
(
nodes
ClientNodeInfo
)
GetNodeInfo
(
nodeID
string
)
(
*
api
.
Node
,
error
)
{
return
nodes
.
Minions
()
.
Get
(
nodeID
)
}
...
...
pkg/scheduler/predicates_test.go
View file @
19379b5a
...
...
@@ -25,10 +25,10 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
type
FakeNodeInfo
api
.
Minion
type
FakeNodeInfo
api
.
Node
func
(
n
FakeNodeInfo
)
GetNodeInfo
(
nodeName
string
)
(
*
api
.
Minion
,
error
)
{
node
:=
api
.
Minion
(
n
)
func
(
n
FakeNodeInfo
)
GetNodeInfo
(
nodeName
string
)
(
*
api
.
Node
,
error
)
{
node
:=
api
.
Node
(
n
)
return
&
node
,
nil
}
...
...
@@ -111,7 +111,7 @@ func TestPodFitsResources(t *testing.T) {
},
}
for
_
,
test
:=
range
tests
{
node
:=
api
.
Minion
{
Spec
:
api
.
NodeSpec
{
Capacity
:
makeResources
(
10
,
20
)
.
Capacity
}}
node
:=
api
.
Node
{
Spec
:
api
.
NodeSpec
{
Capacity
:
makeResources
(
10
,
20
)
.
Capacity
}}
fit
:=
ResourceFit
{
FakeNodeInfo
(
node
)}
fits
,
err
:=
fit
.
PodFitsResources
(
test
.
pod
,
test
.
existingPods
,
"machine"
)
...
...
@@ -335,7 +335,7 @@ func TestPodFitsSelector(t *testing.T) {
},
}
for
_
,
test
:=
range
tests
{
node
:=
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
test
.
labels
}}
node
:=
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
test
.
labels
}}
fit
:=
NodeSelector
{
FakeNodeInfo
(
node
)}
fits
,
err
:=
fit
.
PodSelectorMatches
(
test
.
pod
,
[]
api
.
Pod
{},
"machine"
)
...
...
pkg/scheduler/priorities.go
View file @
19379b5a
...
...
@@ -37,7 +37,7 @@ func calculateScore(requested, capacity int, node string) int {
// 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
.
Minion
,
pods
[]
api
.
Pod
)
HostPriority
{
func
calculateOccupancy
(
pod
api
.
Pod
,
node
api
.
Node
,
pods
[]
api
.
Pod
)
HostPriority
{
totalCPU
:=
0
totalMemory
:=
0
for
_
,
existingPod
:=
range
pods
{
...
...
pkg/scheduler/priorities_test.go
View file @
19379b5a
...
...
@@ -25,8 +25,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
func
makeMinion
(
node
string
,
cpu
,
memory
int
)
api
.
Minion
{
return
api
.
Minion
{
func
makeMinion
(
node
string
,
cpu
,
memory
int
)
api
.
Node
{
return
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
node
},
Spec
:
api
.
NodeSpec
{
Capacity
:
api
.
ResourceList
{
...
...
@@ -70,7 +70,7 @@ func TestLeastRequested(t *testing.T) {
tests
:=
[]
struct
{
pod
api
.
Pod
pods
[]
api
.
Pod
nodes
[]
api
.
Minion
nodes
[]
api
.
Node
expectedList
HostPriorityList
test
string
}{
...
...
@@ -87,7 +87,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (10 + 10) / 2 = 10
*/
pod
:
api
.
Pod
{
Spec
:
noResources
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
4000
,
10000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
4000
,
10000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
10
},
{
"machine2"
,
10
}},
test
:
"nothing scheduled, nothing requested"
,
},
...
...
@@ -104,7 +104,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (5 + 5) / 2 = 5
*/
pod
:
api
.
Pod
{
Spec
:
cpuAndMemory
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
6000
,
10000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
6000
,
10000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
3
},
{
"machine2"
,
5
}},
test
:
"nothing scheduled, resources requested, differently sized machines"
,
},
...
...
@@ -121,7 +121,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (10 + 10) / 2 = 10
*/
pod
:
api
.
Pod
{
Spec
:
noResources
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
4000
,
10000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
4000
,
10000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
10
},
{
"machine2"
,
10
}},
test
:
"no resources requested, pods scheduled"
,
pods
:
[]
api
.
Pod
{
...
...
@@ -144,7 +144,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (4 + 7.5) / 2 = 5
*/
pod
:
api
.
Pod
{
Spec
:
noResources
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
10000
,
20000
),
makeMinion
(
"machine2"
,
10000
,
20000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
10000
,
20000
),
makeMinion
(
"machine2"
,
10000
,
20000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
7
},
{
"machine2"
,
5
}},
test
:
"no resources requested, pods scheduled with resources"
,
pods
:
[]
api
.
Pod
{
...
...
@@ -167,7 +167,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (4 + 5) / 2 = 4
*/
pod
:
api
.
Pod
{
Spec
:
cpuAndMemory
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
10000
,
20000
),
makeMinion
(
"machine2"
,
10000
,
20000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
10000
,
20000
),
makeMinion
(
"machine2"
,
10000
,
20000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
5
},
{
"machine2"
,
4
}},
test
:
"resources requested, pods scheduled with resources"
,
pods
:
[]
api
.
Pod
{
...
...
@@ -188,7 +188,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (4 + 8) / 2 = 6
*/
pod
:
api
.
Pod
{
Spec
:
cpuAndMemory
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
10000
,
20000
),
makeMinion
(
"machine2"
,
10000
,
50000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
10000
,
20000
),
makeMinion
(
"machine2"
,
10000
,
50000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
5
},
{
"machine2"
,
6
}},
test
:
"resources requested, pods scheduled with resources, differently sized machines"
,
pods
:
[]
api
.
Pod
{
...
...
@@ -209,7 +209,7 @@ func TestLeastRequested(t *testing.T) {
Minion2 Score: (0 + 5) / 2 = 2
*/
pod
:
api
.
Pod
{
Spec
:
cpuOnly
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
4000
,
10000
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
4000
,
10000
),
makeMinion
(
"machine2"
,
4000
,
10000
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
5
},
{
"machine2"
,
2
}},
test
:
"requested resources exceed minion capacity"
,
pods
:
[]
api
.
Pod
{
...
...
@@ -219,7 +219,7 @@ func TestLeastRequested(t *testing.T) {
},
{
pod
:
api
.
Pod
{
Spec
:
noResources
},
nodes
:
[]
api
.
Minion
{
makeMinion
(
"machine1"
,
0
,
0
),
makeMinion
(
"machine2"
,
0
,
0
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
0
,
0
),
makeMinion
(
"machine2"
,
0
,
0
)},
expectedList
:
[]
HostPriority
{{
"machine1"
,
0
},
{
"machine2"
,
0
}},
test
:
"zero minion resources, pods scheduled with resources"
,
pods
:
[]
api
.
Pod
{
...
...
@@ -230,7 +230,7 @@ func TestLeastRequested(t *testing.T) {
}
for
_
,
test
:=
range
tests
{
list
,
err
:=
LeastRequestedPriority
(
test
.
pod
,
FakePodLister
(
test
.
pods
),
FakeMinionLister
(
api
.
Minion
List
{
Items
:
test
.
nodes
}))
list
,
err
:=
LeastRequestedPriority
(
test
.
pod
,
FakePodLister
(
test
.
pods
),
FakeMinionLister
(
api
.
Node
List
{
Items
:
test
.
nodes
}))
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
...
...
plugin/pkg/scheduler/factory/factory.go
View file @
19379b5a
...
...
@@ -45,7 +45,7 @@ type ConfigFactory struct {
// a means to list all scheduled pods
PodLister
*
storeToPodLister
// a means to list all minions
MinionLister
*
storeTo
Minion
Lister
MinionLister
*
storeTo
Node
Lister
// map of strings to predicate functions to be used
// to filter the minions for scheduling pods
PredicateMap
map
[
string
]
algorithm
.
FitPredicate
...
...
@@ -61,7 +61,7 @@ func NewConfigFactory(client *client.Client) *ConfigFactory {
Client
:
client
,
PodQueue
:
cache
.
NewFIFO
(),
PodLister
:
&
storeToPodLister
{
cache
.
NewStore
()},
MinionLister
:
&
storeTo
Minion
Lister
{
cache
.
NewStore
()},
MinionLister
:
&
storeTo
Node
Lister
{
cache
.
NewStore
()},
PredicateMap
:
make
(
map
[
string
]
algorithm
.
FitPredicate
),
PriorityMap
:
make
(
map
[
string
]
algorithm
.
PriorityConfig
),
}
...
...
@@ -103,7 +103,7 @@ func (factory *ConfigFactory) Create(predicateKeys, priorityKeys []string) (*sch
// Minions may be listed frequently, so provide a local up-to-date cache.
if
false
{
// Disable this code until minions support watches.
cache
.
NewReflector
(
factory
.
createMinionLW
(),
&
api
.
Minion
{},
factory
.
MinionLister
.
Store
)
.
Run
()
cache
.
NewReflector
(
factory
.
createMinionLW
(),
&
api
.
Node
{},
factory
.
MinionLister
.
Store
)
.
Run
()
}
else
{
cache
.
NewPoller
(
factory
.
pollMinions
,
10
*
time
.
Second
,
factory
.
MinionLister
.
Store
)
.
Run
()
}
...
...
@@ -255,12 +255,12 @@ func (factory *ConfigFactory) createMinionLW() *listWatch {
// pollMinions lists all minions and returns an enumerator for cache.Poller.
func
(
factory
*
ConfigFactory
)
pollMinions
()
(
cache
.
Enumerator
,
error
)
{
list
:=
&
api
.
Minion
List
{}
list
:=
&
api
.
Node
List
{}
err
:=
factory
.
Client
.
Get
()
.
Path
(
"minions"
)
.
Do
()
.
Into
(
list
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
minion
Enumerator
{
list
},
nil
return
&
node
Enumerator
{
list
},
nil
}
func
(
factory
*
ConfigFactory
)
makeDefaultErrorFunc
(
backoff
*
podBackoff
,
podQueue
*
cache
.
FIFO
)
func
(
pod
*
api
.
Pod
,
err
error
)
{
...
...
@@ -288,22 +288,22 @@ func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue
}
}
// storeTo
Minion
Lister turns a store into a minion lister. The store must contain (only) minions.
type
storeTo
Minion
Lister
struct
{
// storeTo
Node
Lister turns a store into a minion lister. The store must contain (only) minions.
type
storeTo
Node
Lister
struct
{
cache
.
Store
}
func
(
s
*
storeTo
MinionLister
)
List
()
(
machines
api
.
Minion
List
,
err
error
)
{
func
(
s
*
storeTo
NodeLister
)
List
()
(
machines
api
.
Node
List
,
err
error
)
{
for
_
,
m
:=
range
s
.
Store
.
List
()
{
machines
.
Items
=
append
(
machines
.
Items
,
*
(
m
.
(
*
api
.
Minion
)))
machines
.
Items
=
append
(
machines
.
Items
,
*
(
m
.
(
*
api
.
Node
)))
}
return
machines
,
nil
}
// GetNodeInfo returns cached data for the minion 'id'.
func
(
s
*
storeTo
MinionLister
)
GetNodeInfo
(
id
string
)
(
*
api
.
Minion
,
error
)
{
func
(
s
*
storeTo
NodeLister
)
GetNodeInfo
(
id
string
)
(
*
api
.
Node
,
error
)
{
if
minion
,
ok
:=
s
.
Get
(
id
);
ok
{
return
minion
.
(
*
api
.
Minion
),
nil
return
minion
.
(
*
api
.
Node
),
nil
}
return
nil
,
fmt
.
Errorf
(
"minion '%v' is not in cache"
,
id
)
}
...
...
@@ -323,22 +323,22 @@ func (s *storeToPodLister) ListPods(selector labels.Selector) (pods []api.Pod, e
return
pods
,
nil
}
//
minionEnumerator allows a cache.Poller to enumerate items in an api.Pod
List
type
minion
Enumerator
struct
{
*
api
.
Minion
List
//
nodeEnumerator allows a cache.Poller to enumerate items in an api.Node
List
type
node
Enumerator
struct
{
*
api
.
Node
List
}
// Len returns the number of items in the
pod
list.
func
(
me
*
minion
Enumerator
)
Len
()
int
{
if
me
.
Minion
List
==
nil
{
// Len returns the number of items in the
node
list.
func
(
ne
*
node
Enumerator
)
Len
()
int
{
if
ne
.
Node
List
==
nil
{
return
0
}
return
len
(
m
e
.
Items
)
return
len
(
n
e
.
Items
)
}
// Get returns the item (and ID) with the particular index.
func
(
me
*
minion
Enumerator
)
Get
(
index
int
)
(
string
,
interface
{})
{
return
me
.
Items
[
index
]
.
Name
,
&
m
e
.
Items
[
index
]
func
(
ne
*
node
Enumerator
)
Get
(
index
int
)
(
string
,
interface
{})
{
return
ne
.
Items
[
index
]
.
Name
,
&
n
e
.
Items
[
index
]
}
type
binder
struct
{
...
...
plugin/pkg/scheduler/factory/factory_test.go
View file @
19379b5a
...
...
@@ -145,10 +145,10 @@ func TestCreateWatches(t *testing.T) {
func
TestPollMinions
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
minions
[]
api
.
Minion
minions
[]
api
.
Node
}{
{
minions
:
[]
api
.
Minion
{
minions
:
[]
api
.
Node
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
}},
},
...
...
@@ -156,7 +156,7 @@ func TestPollMinions(t *testing.T) {
}
for
_
,
item
:=
range
table
{
ml
:=
&
api
.
Minion
List
{
Items
:
item
.
minions
}
ml
:=
&
api
.
Node
List
{
Items
:
item
.
minions
}
handler
:=
util
.
FakeHandler
{
StatusCode
:
200
,
ResponseBody
:
runtime
.
EncodeOrDie
(
latest
.
Codec
,
ml
),
...
...
@@ -225,9 +225,9 @@ func TestStoreToMinionLister(t *testing.T) {
store
:=
cache
.
NewStore
()
ids
:=
util
.
NewStringSet
(
"foo"
,
"bar"
,
"baz"
)
for
id
:=
range
ids
{
store
.
Add
(
id
,
&
api
.
Minion
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
id
}})
store
.
Add
(
id
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
id
}})
}
sml
:=
storeTo
Minion
Lister
{
store
}
sml
:=
storeTo
Node
Lister
{
store
}
gotNodes
,
err
:=
sml
.
List
()
if
err
!=
nil
{
...
...
@@ -273,14 +273,14 @@ func TestStoreToPodLister(t *testing.T) {
}
func
TestMinionEnumerator
(
t
*
testing
.
T
)
{
testList
:=
&
api
.
Minion
List
{
Items
:
[]
api
.
Minion
{
testList
:=
&
api
.
Node
List
{
Items
:
[]
api
.
Node
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
}},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
}},
},
}
me
:=
minion
Enumerator
{
testList
}
me
:=
node
Enumerator
{
testList
}
if
e
,
a
:=
3
,
me
.
Len
();
e
!=
a
{
t
.
Fatalf
(
"expected %v, got %v"
,
e
,
a
)
...
...
plugin/pkg/scheduler/scheduler_test.go
View file @
19379b5a
...
...
@@ -88,7 +88,7 @@ func TestScheduler(t *testing.T) {
var
gotBinding
*
api
.
Binding
c
:=
&
Config
{
MinionLister
:
scheduler
.
FakeMinionLister
(
api
.
MinionList
{
Items
:
[]
api
.
Minion
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"machine1"
}}}},
api
.
NodeList
{
Items
:
[]
api
.
Node
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"machine1"
}}}},
),
Algorithm
:
item
.
algo
,
Binder
:
fakeBinder
{
func
(
b
*
api
.
Binding
)
error
{
...
...
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