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
94c873e7
Commit
94c873e7
authored
Nov 06, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remaining refactor for PodTemplateSpec and fixing test cases
parent
72bf12c8
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
285 additions
and
201 deletions
+285
-201
integration.go
cmd/integration/integration.go
+5
-5
examples_test.go
examples/examples_test.go
+11
-2
latest_test.go
pkg/api/latest/latest_test.go
+19
-0
serialization_test.go
pkg/api/serialization_test.go
+25
-5
client_test.go
pkg/client/client_test.go
+8
-4
conditions.go
pkg/client/conditions.go
+2
-2
replication_controller.go
pkg/controller/replication_controller.go
+20
-17
replication_controller_test.go
pkg/controller/replication_controller_test.go
+58
-51
kubecfg.go
pkg/kubecfg/kubecfg.go
+19
-20
kubecfg_test.go
pkg/kubecfg/kubecfg_test.go
+15
-17
parse_test.go
pkg/kubecfg/parse_test.go
+8
-11
resource_printer.go
pkg/kubecfg/resource_printer.go
+10
-2
describe.go
pkg/kubectl/describe.go
+13
-7
kubectl.go
pkg/kubectl/kubectl.go
+2
-2
resource_printer.go
pkg/kubectl/resource_printer.go
+9
-3
rest.go
pkg/registry/controller/rest.go
+11
-13
rest_test.go
pkg/registry/controller/rest_test.go
+48
-38
etcd_test.go
pkg/registry/etcd/etcd_test.go
+2
-2
No files found.
cmd/integration/integration.go
View file @
94c873e7
...
@@ -237,24 +237,24 @@ func runReplicationControllerTest(c *client.Client) {
...
@@ -237,24 +237,24 @@ func runReplicationControllerTest(c *client.Client) {
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
}
}
var
controller
Request
api
.
ReplicationController
var
controller
api
.
ReplicationController
if
err
:=
json
.
Unmarshal
(
data
,
&
controller
Request
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
data
,
&
controller
);
err
!=
nil
{
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
}
}
glog
.
Infof
(
"Creating replication controllers"
)
glog
.
Infof
(
"Creating replication controllers"
)
if
_
,
err
:=
c
.
ReplicationControllers
(
api
.
NamespaceDefault
)
.
Create
(
&
controller
Request
);
err
!=
nil
{
if
_
,
err
:=
c
.
ReplicationControllers
(
api
.
NamespaceDefault
)
.
Create
(
&
controller
);
err
!=
nil
{
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
}
}
glog
.
Infof
(
"Done creating replication controllers"
)
glog
.
Infof
(
"Done creating replication controllers"
)
// Give the controllers some time to actually create the pods
// Give the controllers some time to actually create the pods
if
err
:=
wait
.
Poll
(
time
.
Second
,
time
.
Second
*
30
,
c
.
ControllerHasDesiredReplicas
(
controller
Request
));
err
!=
nil
{
if
err
:=
wait
.
Poll
(
time
.
Second
,
time
.
Second
*
30
,
c
.
ControllerHasDesiredReplicas
(
controller
));
err
!=
nil
{
glog
.
Fatalf
(
"FAILED: pods never created %v"
,
err
)
glog
.
Fatalf
(
"FAILED: pods never created %v"
,
err
)
}
}
// wait for minions to indicate they have info about the desired pods
// wait for minions to indicate they have info about the desired pods
pods
,
err
:=
c
.
Pods
(
api
.
NamespaceDefault
)
.
List
(
labels
.
Set
(
controller
Request
.
DesiredState
.
Replica
Selector
)
.
AsSelector
())
pods
,
err
:=
c
.
Pods
(
api
.
NamespaceDefault
)
.
List
(
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
())
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"FAILED: unable to get pods to list: %v"
,
err
)
glog
.
Fatalf
(
"FAILED: unable to get pods to list: %v"
,
err
)
}
}
...
...
examples/examples_test.go
View file @
94c873e7
...
@@ -36,12 +36,18 @@ func validateObject(obj runtime.Object) (errors []error) {
...
@@ -36,12 +36,18 @@ func validateObject(obj runtime.Object) (errors []error) {
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
switch
t
:=
obj
.
(
type
)
{
switch
t
:=
obj
.
(
type
)
{
case
*
api
.
ReplicationController
:
case
*
api
.
ReplicationController
:
errors
=
validation
.
ValidateManifest
(
&
t
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
)
if
t
.
Namespace
==
""
{
t
.
Namespace
=
api
.
NamespaceDefault
}
errors
=
validation
.
ValidateReplicationController
(
t
)
case
*
api
.
ReplicationControllerList
:
case
*
api
.
ReplicationControllerList
:
for
i
:=
range
t
.
Items
{
for
i
:=
range
t
.
Items
{
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
}
}
case
*
api
.
Service
:
case
*
api
.
Service
:
if
t
.
Namespace
==
""
{
t
.
Namespace
=
api
.
NamespaceDefault
}
api
.
ValidNamespace
(
ctx
,
&
t
.
ObjectMeta
)
api
.
ValidNamespace
(
ctx
,
&
t
.
ObjectMeta
)
errors
=
validation
.
ValidateService
(
t
,
registrytest
.
NewServiceRegistry
(),
api
.
NewDefaultContext
())
errors
=
validation
.
ValidateService
(
t
,
registrytest
.
NewServiceRegistry
(),
api
.
NewDefaultContext
())
case
*
api
.
ServiceList
:
case
*
api
.
ServiceList
:
...
@@ -49,8 +55,11 @@ func validateObject(obj runtime.Object) (errors []error) {
...
@@ -49,8 +55,11 @@ func validateObject(obj runtime.Object) (errors []error) {
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
}
}
case
*
api
.
Pod
:
case
*
api
.
Pod
:
if
t
.
Namespace
==
""
{
t
.
Namespace
=
api
.
NamespaceDefault
}
api
.
ValidNamespace
(
ctx
,
&
t
.
ObjectMeta
)
api
.
ValidNamespace
(
ctx
,
&
t
.
ObjectMeta
)
errors
=
validation
.
Validate
Manifest
(
&
t
.
DesiredState
.
Manifes
t
)
errors
=
validation
.
Validate
Pod
(
t
)
case
*
api
.
PodList
:
case
*
api
.
PodList
:
for
i
:=
range
t
.
Items
{
for
i
:=
range
t
.
Items
{
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
...
...
pkg/api/latest/latest_test.go
View file @
94c873e7
...
@@ -75,6 +75,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
...
@@ -75,6 +75,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
statuses
:=
[]
internal
.
PodCondition
{
internal
.
PodPending
,
internal
.
PodRunning
,
internal
.
PodFailed
}
statuses
:=
[]
internal
.
PodCondition
{
internal
.
PodPending
,
internal
.
PodRunning
,
internal
.
PodFailed
}
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
},
},
func
(
j
*
internal
.
ReplicationControllerSpec
,
c
fuzz
.
Continue
)
{
// TemplateRef must be nil for round trip
c
.
Fuzz
(
&
j
.
Template
)
if
j
.
Template
==
nil
{
// TODO: v1beta1/2 can't round trip a nil template correctly, fix by having v1beta1/2
// conversion compare converted object to nil via DeepEqual
j
.
Template
=
&
internal
.
PodTemplateSpec
{}
}
j
.
Template
.
ObjectMeta
=
internal
.
ObjectMeta
{
Labels
:
j
.
Template
.
ObjectMeta
.
Labels
}
j
.
Template
.
Spec
.
NodeSelector
=
nil
c
.
Fuzz
(
&
j
.
Selector
)
j
.
Replicas
=
int
(
c
.
RandUint64
())
},
func
(
j
*
internal
.
ReplicationControllerStatus
,
c
fuzz
.
Continue
)
{
// only replicas round trips
j
.
Replicas
=
int
(
c
.
RandUint64
())
},
func
(
intstr
*
util
.
IntOrString
,
c
fuzz
.
Continue
)
{
func
(
intstr
*
util
.
IntOrString
,
c
fuzz
.
Continue
)
{
// util.IntOrString will panic if its kind is set wrong.
// util.IntOrString will panic if its kind is set wrong.
if
c
.
RandBool
()
{
if
c
.
RandBool
()
{
...
@@ -127,6 +144,7 @@ func TestInternalRoundTrip(t *testing.T) {
...
@@ -127,6 +144,7 @@ func TestInternalRoundTrip(t *testing.T) {
if
err
:=
internal
.
Scheme
.
Convert
(
obj
,
newer
);
err
!=
nil
{
if
err
:=
internal
.
Scheme
.
Convert
(
obj
,
newer
);
err
!=
nil
{
t
.
Errorf
(
"unable to convert %#v to %#v: %v"
,
obj
,
newer
,
err
)
t
.
Errorf
(
"unable to convert %#v to %#v: %v"
,
obj
,
newer
,
err
)
continue
}
}
actual
,
err
:=
internal
.
Scheme
.
New
(
""
,
k
)
actual
,
err
:=
internal
.
Scheme
.
New
(
""
,
k
)
...
@@ -137,6 +155,7 @@ func TestInternalRoundTrip(t *testing.T) {
...
@@ -137,6 +155,7 @@ func TestInternalRoundTrip(t *testing.T) {
if
err
:=
internal
.
Scheme
.
Convert
(
newer
,
actual
);
err
!=
nil
{
if
err
:=
internal
.
Scheme
.
Convert
(
newer
,
actual
);
err
!=
nil
{
t
.
Errorf
(
"unable to convert %#v to %#v: %v"
,
newer
,
actual
,
err
)
t
.
Errorf
(
"unable to convert %#v to %#v: %v"
,
newer
,
actual
,
err
)
continue
}
}
if
!
reflect
.
DeepEqual
(
obj
,
actual
)
{
if
!
reflect
.
DeepEqual
(
obj
,
actual
)
{
...
...
pkg/api/serialization_test.go
View file @
94c873e7
...
@@ -90,6 +90,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
...
@@ -90,6 +90,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
statuses
:=
[]
api
.
PodCondition
{
api
.
PodPending
,
api
.
PodRunning
,
api
.
PodFailed
}
statuses
:=
[]
api
.
PodCondition
{
api
.
PodPending
,
api
.
PodRunning
,
api
.
PodFailed
}
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
},
},
func
(
j
*
api
.
ReplicationControllerSpec
,
c
fuzz
.
Continue
)
{
// TemplateRef must be nil for round trip
c
.
Fuzz
(
&
j
.
Template
)
if
j
.
Template
==
nil
{
// TODO: v1beta1/2 can't round trip a nil template correctly, fix by having v1beta1/2
// conversion compare converted object to nil via DeepEqual
j
.
Template
=
&
api
.
PodTemplateSpec
{}
}
j
.
Template
.
ObjectMeta
=
api
.
ObjectMeta
{
Labels
:
j
.
Template
.
ObjectMeta
.
Labels
}
j
.
Template
.
Spec
.
NodeSelector
=
nil
c
.
Fuzz
(
&
j
.
Selector
)
j
.
Replicas
=
int
(
c
.
RandUint64
())
},
func
(
j
*
api
.
ReplicationControllerStatus
,
c
fuzz
.
Continue
)
{
// only replicas round trips
j
.
Replicas
=
int
(
c
.
RandUint64
())
},
func
(
intstr
*
util
.
IntOrString
,
c
fuzz
.
Continue
)
{
func
(
intstr
*
util
.
IntOrString
,
c
fuzz
.
Continue
)
{
// util.IntOrString will panic if its kind is set wrong.
// util.IntOrString will panic if its kind is set wrong.
if
c
.
RandBool
()
{
if
c
.
RandBool
()
{
...
@@ -176,18 +193,21 @@ func TestSpecificKind(t *testing.T) {
...
@@ -176,18 +193,21 @@ func TestSpecificKind(t *testing.T) {
api
.
Scheme
.
Log
(
nil
)
api
.
Scheme
.
Log
(
nil
)
}
}
func
TestTypes
(
t
*
testing
.
T
)
{
var
nonRoundTrippableTypes
=
util
.
NewStringSet
(
"ContainerManifest"
)
func
TestRoundTripTypes
(
t
*
testing
.
T
)
{
for
kind
:=
range
api
.
Scheme
.
KnownTypes
(
""
)
{
for
kind
:=
range
api
.
Scheme
.
KnownTypes
(
""
)
{
if
nonRoundTrippableTypes
.
Has
(
kind
)
{
continue
}
// Try a few times, since runTest uses random values.
// Try a few times, since runTest uses random values.
for
i
:=
0
;
i
<
*
fuzzIters
;
i
++
{
for
i
:=
0
;
i
<
*
fuzzIters
;
i
++
{
item
,
err
:=
api
.
Scheme
.
New
(
""
,
kind
)
item
,
err
:=
api
.
Scheme
.
New
(
""
,
kind
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Couldn't make a %v? %v"
,
kind
,
err
)
t
.
Fatalf
(
"Couldn't make a %v? %v"
,
kind
,
err
)
continue
}
}
if
_
,
err
:=
meta
.
Accessor
(
item
);
err
!=
nil
{
if
_
,
err
:=
meta
.
Accessor
(
item
);
err
!=
nil
{
t
.
Logf
(
"%s is not a TypeMeta and cannot be round tripped: %v"
,
kind
,
err
)
t
.
Fatalf
(
"%q is not a TypeMeta and cannot be tested - add it to nonRoundTrippableTypes: %v"
,
kind
,
err
)
continue
}
}
runTest
(
t
,
v1beta1
.
Codec
,
item
)
runTest
(
t
,
v1beta1
.
Codec
,
item
)
runTest
(
t
,
v1beta2
.
Codec
,
item
)
runTest
(
t
,
v1beta2
.
Codec
,
item
)
...
...
pkg/client/client_test.go
View file @
94c873e7
...
@@ -309,8 +309,9 @@ func TestListControllers(t *testing.T) {
...
@@ -309,8 +309,9 @@ func TestListControllers(t *testing.T) {
"name"
:
"baz"
,
"name"
:
"baz"
,
},
},
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
},
},
},
...
@@ -335,8 +336,9 @@ func TestGetController(t *testing.T) {
...
@@ -335,8 +336,9 @@ func TestGetController(t *testing.T) {
"name"
:
"baz"
,
"name"
:
"baz"
,
},
},
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
},
},
},
...
@@ -361,8 +363,9 @@ func TestUpdateController(t *testing.T) {
...
@@ -361,8 +363,9 @@ func TestUpdateController(t *testing.T) {
"name"
:
"baz"
,
"name"
:
"baz"
,
},
},
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
},
},
},
...
@@ -396,8 +399,9 @@ func TestCreateController(t *testing.T) {
...
@@ -396,8 +399,9 @@ func TestCreateController(t *testing.T) {
"name"
:
"baz"
,
"name"
:
"baz"
,
},
},
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
},
},
},
...
...
pkg/client/conditions.go
View file @
94c873e7
...
@@ -26,10 +26,10 @@ import (
...
@@ -26,10 +26,10 @@ import (
// for a controller's ReplicaSelector equals the Replicas count.
// for a controller's ReplicaSelector equals the Replicas count.
func
(
c
*
Client
)
ControllerHasDesiredReplicas
(
controller
api
.
ReplicationController
)
wait
.
ConditionFunc
{
func
(
c
*
Client
)
ControllerHasDesiredReplicas
(
controller
api
.
ReplicationController
)
wait
.
ConditionFunc
{
return
func
()
(
bool
,
error
)
{
return
func
()
(
bool
,
error
)
{
pods
,
err
:=
c
.
Pods
(
controller
.
Namespace
)
.
List
(
labels
.
Set
(
controller
.
DesiredState
.
Replica
Selector
)
.
AsSelector
())
pods
,
err
:=
c
.
Pods
(
controller
.
Namespace
)
.
List
(
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
())
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
return
len
(
pods
.
Items
)
==
controller
.
DesiredState
.
Replicas
,
nil
return
len
(
pods
.
Items
)
==
controller
.
Spec
.
Replicas
,
nil
}
}
}
}
pkg/controller/replication_controller.go
View file @
94c873e7
...
@@ -35,14 +35,14 @@ type ReplicationManager struct {
...
@@ -35,14 +35,14 @@ type ReplicationManager struct {
syncTime
<-
chan
time
.
Time
syncTime
<-
chan
time
.
Time
// To allow injection of syncReplicationController for testing.
// To allow injection of syncReplicationController for testing.
syncHandler
func
(
controller
Spec
api
.
ReplicationController
)
error
syncHandler
func
(
controller
api
.
ReplicationController
)
error
}
}
// PodControlInterface is an interface that knows how to add or delete pods
// PodControlInterface is an interface that knows how to add or delete pods
// created as an interface to allow testing.
// created as an interface to allow testing.
type
PodControlInterface
interface
{
type
PodControlInterface
interface
{
// createReplica creates new replicated pods according to the spec.
// createReplica creates new replicated pods according to the spec.
createReplica
(
namespace
string
,
controller
Spec
api
.
ReplicationController
)
createReplica
(
namespace
string
,
controller
api
.
ReplicationController
)
// deletePod deletes the pod identified by podID.
// deletePod deletes the pod identified by podID.
deletePod
(
namespace
string
,
podID
string
)
error
deletePod
(
namespace
string
,
podID
string
)
error
}
}
...
@@ -52,16 +52,19 @@ type RealPodControl struct {
...
@@ -52,16 +52,19 @@ type RealPodControl struct {
kubeClient
client
.
Interface
kubeClient
client
.
Interface
}
}
func
(
r
RealPodControl
)
createReplica
(
namespace
string
,
controller
Spec
api
.
ReplicationController
)
{
func
(
r
RealPodControl
)
createReplica
(
namespace
string
,
controller
api
.
ReplicationController
)
{
desiredLabels
:=
make
(
labels
.
Set
)
desiredLabels
:=
make
(
labels
.
Set
)
for
k
,
v
:=
range
controller
Spec
.
DesiredState
.
Pod
Template
.
Labels
{
for
k
,
v
:=
range
controller
.
Spec
.
Template
.
Labels
{
desiredLabels
[
k
]
=
v
desiredLabels
[
k
]
=
v
}
}
pod
:=
&
api
.
Pod
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
desiredLabels
,
Labels
:
desiredLabels
,
},
},
DesiredState
:
controllerSpec
.
DesiredState
.
PodTemplate
.
DesiredState
,
}
if
err
:=
api
.
Scheme
.
Convert
(
&
controller
.
Spec
.
Template
.
Spec
,
&
pod
.
DesiredState
.
Manifest
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to convert pod template: %v"
,
err
)
return
}
}
if
_
,
err
:=
r
.
kubeClient
.
Pods
(
namespace
)
.
Create
(
pod
);
err
!=
nil
{
if
_
,
err
:=
r
.
kubeClient
.
Pods
(
namespace
)
.
Create
(
pod
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to create pod replica: %v"
,
err
)
glog
.
Errorf
(
"Unable to create pod replica: %v"
,
err
)
...
@@ -142,14 +145,14 @@ func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod {
...
@@ -142,14 +145,14 @@ func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod {
return
result
return
result
}
}
func
(
rm
*
ReplicationManager
)
syncReplicationController
(
controller
Spec
api
.
ReplicationController
)
error
{
func
(
rm
*
ReplicationManager
)
syncReplicationController
(
controller
api
.
ReplicationController
)
error
{
s
:=
labels
.
Set
(
controller
Spec
.
DesiredState
.
Replica
Selector
)
.
AsSelector
()
s
:=
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
()
podList
,
err
:=
rm
.
kubeClient
.
Pods
(
controller
Spec
.
Namespace
)
.
List
(
s
)
podList
,
err
:=
rm
.
kubeClient
.
Pods
(
controller
.
Namespace
)
.
List
(
s
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
filteredList
:=
rm
.
filterActivePods
(
podList
.
Items
)
filteredList
:=
rm
.
filterActivePods
(
podList
.
Items
)
diff
:=
len
(
filteredList
)
-
controller
Spec
.
DesiredState
.
Replicas
diff
:=
len
(
filteredList
)
-
controller
.
Spec
.
Replicas
if
diff
<
0
{
if
diff
<
0
{
diff
*=
-
1
diff
*=
-
1
wait
:=
sync
.
WaitGroup
{}
wait
:=
sync
.
WaitGroup
{}
...
@@ -158,7 +161,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
...
@@ -158,7 +161,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
for
i
:=
0
;
i
<
diff
;
i
++
{
for
i
:=
0
;
i
<
diff
;
i
++
{
go
func
()
{
go
func
()
{
defer
wait
.
Done
()
defer
wait
.
Done
()
rm
.
podControl
.
createReplica
(
controller
Spec
.
Namespace
,
controllerSpec
)
rm
.
podControl
.
createReplica
(
controller
.
Namespace
,
controller
)
}()
}()
}
}
wait
.
Wait
()
wait
.
Wait
()
...
@@ -169,7 +172,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
...
@@ -169,7 +172,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
for
i
:=
0
;
i
<
diff
;
i
++
{
for
i
:=
0
;
i
<
diff
;
i
++
{
go
func
(
ix
int
)
{
go
func
(
ix
int
)
{
defer
wait
.
Done
()
defer
wait
.
Done
()
rm
.
podControl
.
deletePod
(
controller
Spec
.
Namespace
,
filteredList
[
ix
]
.
Name
)
rm
.
podControl
.
deletePod
(
controller
.
Namespace
,
filteredList
[
ix
]
.
Name
)
}(
i
)
}(
i
)
}
}
wait
.
Wait
()
wait
.
Wait
()
...
@@ -180,20 +183,20 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
...
@@ -180,20 +183,20 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
func
(
rm
*
ReplicationManager
)
synchronize
()
{
func
(
rm
*
ReplicationManager
)
synchronize
()
{
// TODO: remove this method completely and rely on the watch.
// TODO: remove this method completely and rely on the watch.
// Add resource version tracking to watch to make this work.
// Add resource version tracking to watch to make this work.
var
controller
Spec
s
[]
api
.
ReplicationController
var
controllers
[]
api
.
ReplicationController
list
,
err
:=
rm
.
kubeClient
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
labels
.
Everything
())
list
,
err
:=
rm
.
kubeClient
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Synchronization error: %v (%#v)"
,
err
,
err
)
glog
.
Errorf
(
"Synchronization error: %v (%#v)"
,
err
,
err
)
return
return
}
}
controller
Spec
s
=
list
.
Items
controllers
=
list
.
Items
wg
:=
sync
.
WaitGroup
{}
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
len
(
controller
Spec
s
))
wg
.
Add
(
len
(
controllers
))
for
ix
:=
range
controller
Spec
s
{
for
ix
:=
range
controllers
{
go
func
(
ix
int
)
{
go
func
(
ix
int
)
{
defer
wg
.
Done
()
defer
wg
.
Done
()
glog
.
V
(
4
)
.
Infof
(
"periodic sync of %v"
,
controller
Spec
s
[
ix
]
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"periodic sync of %v"
,
controllers
[
ix
]
.
Name
)
err
:=
rm
.
syncHandler
(
controller
Spec
s
[
ix
])
err
:=
rm
.
syncHandler
(
controllers
[
ix
])
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error synchronizing: %#v"
,
err
)
glog
.
Errorf
(
"Error synchronizing: %#v"
,
err
)
}
}
...
...
pkg/controller/replication_controller_test.go
View file @
94c873e7
...
@@ -62,21 +62,21 @@ func (f *FakePodControl) deletePod(namespace string, podName string) error {
...
@@ -62,21 +62,21 @@ func (f *FakePodControl) deletePod(namespace string, podName string) error {
func
newReplicationController
(
replicas
int
)
api
.
ReplicationController
{
func
newReplicationController
(
replicas
int
)
api
.
ReplicationController
{
return
api
.
ReplicationController
{
return
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
replicas
,
Replicas
:
replicas
,
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
ObjectMeta
:
api
.
ObjectMeta
{
Manifest
:
api
.
ContainerManifest
{
Labels
:
map
[
string
]
string
{
Containers
:
[]
api
.
Container
{
"name"
:
"foo"
,
{
"type"
:
"production"
,
Image
:
"foo/bar"
,
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
Spec
:
api
.
PodSpec
{
"name"
:
"foo"
,
Containers
:
[]
api
.
Container
{
"type"
:
"production"
,
{
Image
:
"foo/bar"
,
},
},
},
},
},
},
},
},
...
@@ -188,21 +188,21 @@ func TestCreateReplica(t *testing.T) {
...
@@ -188,21 +188,21 @@ func TestCreateReplica(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Name
:
"test"
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
ObjectMeta
:
api
.
ObjectMeta
{
Manifest
:
api
.
ContainerManifest
{
Labels
:
map
[
string
]
string
{
Containers
:
[]
api
.
Container
{
"name"
:
"foo"
,
{
"type"
:
"production"
,
Image
:
"foo/bar"
,
"replicationController"
:
"test"
,
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
Spec
:
api
.
PodSpec
{
"name"
:
"foo"
,
Containers
:
[]
api
.
Container
{
"type"
:
"production"
,
{
"replicationController"
:
"test"
,
Image
:
"foo/bar"
,
},
},
},
},
},
},
},
},
...
@@ -210,11 +210,18 @@ func TestCreateReplica(t *testing.T) {
...
@@ -210,11 +210,18 @@ func TestCreateReplica(t *testing.T) {
podControl
.
createReplica
(
ns
,
controllerSpec
)
podControl
.
createReplica
(
ns
,
controllerSpec
)
manifest
:=
api
.
ContainerManifest
{}
if
err
:=
api
.
Scheme
.
Convert
(
&
controllerSpec
.
Spec
.
Template
.
Spec
,
&
manifest
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error"
,
err
)
}
expectedPod
:=
api
.
Pod
{
expectedPod
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
controllerSpec
.
DesiredState
.
PodTemplate
.
Labels
,
Labels
:
controllerSpec
.
Spec
.
Template
.
Labels
,
},
DesiredState
:
api
.
PodState
{
Manifest
:
manifest
,
},
},
DesiredState
:
controllerSpec
.
DesiredState
.
PodTemplate
.
DesiredState
,
}
}
fakeHandler
.
ValidateRequest
(
t
,
makeURL
(
"/pods?namespace=default"
),
"POST"
,
nil
)
fakeHandler
.
ValidateRequest
(
t
,
makeURL
(
"/pods?namespace=default"
),
"POST"
,
nil
)
actualPod
,
err
:=
client
.
Codec
.
Decode
([]
byte
(
fakeHandler
.
RequestBody
))
actualPod
,
err
:=
client
.
Codec
.
Decode
([]
byte
(
fakeHandler
.
RequestBody
))
...
@@ -230,42 +237,42 @@ func TestCreateReplica(t *testing.T) {
...
@@ -230,42 +237,42 @@ func TestCreateReplica(t *testing.T) {
func
TestSynchonize
(
t
*
testing
.
T
)
{
func
TestSynchonize
(
t
*
testing
.
T
)
{
controllerSpec1
:=
api
.
ReplicationController
{
controllerSpec1
:=
api
.
ReplicationController
{
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
testapi
.
Version
()},
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
testapi
.
Version
()},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
4
,
Replicas
:
4
,
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
ObjectMeta
:
api
.
ObjectMeta
{
Manifest
:
api
.
ContainerManifest
{
Labels
:
map
[
string
]
string
{
Containers
:
[]
api
.
Container
{
"name"
:
"foo"
,
{
"type"
:
"production"
,
Image
:
"foo/bar"
,
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
Spec
:
api
.
PodSpec
{
"name"
:
"foo"
,
Containers
:
[]
api
.
Container
{
"type"
:
"production"
,
{
Image
:
"foo/bar"
,
},
},
},
},
},
},
},
},
}
}
controllerSpec2
:=
api
.
ReplicationController
{
controllerSpec2
:=
api
.
ReplicationController
{
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
testapi
.
Version
()},
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
testapi
.
Version
()},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
3
,
Replicas
:
3
,
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
ObjectMeta
:
api
.
ObjectMeta
{
Manifest
:
api
.
ContainerManifest
{
Labels
:
map
[
string
]
string
{
Containers
:
[]
api
.
Container
{
"name"
:
"bar"
,
{
"type"
:
"production"
,
Image
:
"bar/baz"
,
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
Spec
:
api
.
PodSpec
{
"name"
:
"bar"
,
Containers
:
[]
api
.
Container
{
"type"
:
"production"
,
{
Image
:
"bar/baz"
,
},
},
},
},
},
},
},
},
...
...
pkg/kubecfg/kubecfg.go
View file @
94c873e7
...
@@ -134,14 +134,14 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
...
@@ -134,14 +134,14 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
}
}
if
len
(
imageName
)
!=
0
{
if
len
(
imageName
)
!=
0
{
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
=
imageName
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
imageName
controller
,
err
=
client
.
ReplicationControllers
(
controller
.
Namespace
)
.
Update
(
controller
)
controller
,
err
=
client
.
ReplicationControllers
(
controller
.
Namespace
)
.
Update
(
controller
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
}
}
s
:=
labels
.
Set
(
controller
.
DesiredState
.
Replica
Selector
)
.
AsSelector
()
s
:=
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
()
podList
,
err
:=
client
.
Pods
(
api
.
Namespace
(
ctx
))
.
List
(
s
)
podList
,
err
:=
client
.
Pods
(
api
.
Namespace
(
ctx
))
.
List
(
s
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -181,7 +181,7 @@ func ResizeController(ctx api.Context, name string, replicas int, client client.
...
@@ -181,7 +181,7 @@ func ResizeController(ctx api.Context, name string, replicas int, client client.
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
controller
.
DesiredState
.
Replicas
=
replicas
controller
.
Spec
.
Replicas
=
replicas
controllerOut
,
err
:=
client
.
ReplicationControllers
(
api
.
Namespace
(
ctx
))
.
Update
(
controller
)
controllerOut
,
err
:=
client
.
ReplicationControllers
(
api
.
Namespace
(
ctx
))
.
Update
(
controller
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -251,26 +251,25 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli
...
@@ -251,26 +251,25 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
replicas
,
Replicas
:
replicas
,
Replica
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"name"
:
name
,
"name"
:
name
,
},
},
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
ObjectMeta
:
api
.
ObjectMeta
{
Manifest
:
api
.
ContainerManifest
{
Labels
:
map
[
string
]
string
{
Version
:
"v1beta2"
,
"name"
:
name
,
Containers
:
[]
api
.
Container
{
{
Name
:
strings
.
ToLower
(
name
),
Image
:
image
,
Ports
:
ports
,
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
Spec
:
api
.
PodSpec
{
"name"
:
name
,
Containers
:
[]
api
.
Container
{
{
Name
:
strings
.
ToLower
(
name
),
Image
:
image
,
Ports
:
ports
,
},
},
},
},
},
},
},
},
...
@@ -328,8 +327,8 @@ func DeleteController(ctx api.Context, name string, client client.Interface) err
...
@@ -328,8 +327,8 @@ func DeleteController(ctx api.Context, name string, client client.Interface) err
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
controller
.
DesiredState
.
Replicas
!=
0
{
if
controller
.
Spec
.
Replicas
!=
0
{
return
fmt
.
Errorf
(
"controller has non-zero replicas (%d), please stop it first"
,
controller
.
DesiredState
.
Replicas
)
return
fmt
.
Errorf
(
"controller has non-zero replicas (%d), please stop it first"
,
controller
.
Spec
.
Replicas
)
}
}
return
client
.
ReplicationControllers
(
api
.
Namespace
(
ctx
))
.
Delete
(
name
)
return
client
.
ReplicationControllers
(
api
.
Namespace
(
ctx
))
.
Delete
(
name
)
}
}
pkg/kubecfg/kubecfg_test.go
View file @
94c873e7
...
@@ -74,13 +74,11 @@ func TestUpdateWithNewImage(t *testing.T) {
...
@@ -74,13 +74,11 @@ func TestUpdateWithNewImage(t *testing.T) {
},
},
},
},
Ctrl
:
api
.
ReplicationController
{
Ctrl
:
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
Spec
:
api
.
PodSpec
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
Image
:
"fooImage:1"
},
{
Image
:
"fooImage:1"
},
},
},
},
},
},
},
},
...
@@ -94,7 +92,7 @@ func TestUpdateWithNewImage(t *testing.T) {
...
@@ -94,7 +92,7 @@ func TestUpdateWithNewImage(t *testing.T) {
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
newCtrl
:=
api
.
Scheme
.
CopyOrDie
(
&
fakeClient
.
Ctrl
)
.
(
*
api
.
ReplicationController
)
newCtrl
:=
api
.
Scheme
.
CopyOrDie
(
&
fakeClient
.
Ctrl
)
.
(
*
api
.
ReplicationController
)
newCtrl
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
=
"fooImage:2"
newCtrl
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"fooImage:2"
validateAction
(
client
.
FakeAction
{
Action
:
"update-controller"
,
Value
:
newCtrl
},
fakeClient
.
Actions
[
1
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"update-controller"
,
Value
:
newCtrl
},
fakeClient
.
Actions
[
1
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"list-pods"
},
fakeClient
.
Actions
[
2
],
t
)
validateAction
(
client
.
FakeAction
{
Action
:
"list-pods"
},
fakeClient
.
Actions
[
2
],
t
)
...
@@ -115,8 +113,8 @@ func TestRunController(t *testing.T) {
...
@@ -115,8 +113,8 @@ func TestRunController(t *testing.T) {
}
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
Name
!=
name
||
if
controller
.
Name
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
Spec
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
!=
image
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
}
}
}
}
...
@@ -136,8 +134,8 @@ func TestRunControllerWithWrongArgs(t *testing.T) {
...
@@ -136,8 +134,8 @@ func TestRunControllerWithWrongArgs(t *testing.T) {
}
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
Name
!=
name
||
if
controller
.
Name
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
Spec
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
!=
image
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
}
}
}
}
...
@@ -155,8 +153,8 @@ func TestRunControllerWithService(t *testing.T) {
...
@@ -155,8 +153,8 @@ func TestRunControllerWithService(t *testing.T) {
}
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
Name
!=
name
||
if
controller
.
Name
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
Spec
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
!=
image
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
}
}
}
}
...
@@ -174,7 +172,7 @@ func TestStopController(t *testing.T) {
...
@@ -174,7 +172,7 @@ func TestStopController(t *testing.T) {
}
}
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
controller
.
DesiredState
.
Replicas
!=
0
{
controller
.
Spec
.
Replicas
!=
0
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
}
}
}
}
...
@@ -193,7 +191,7 @@ func TestResizeController(t *testing.T) {
...
@@ -193,7 +191,7 @@ func TestResizeController(t *testing.T) {
}
}
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
controller
.
DesiredState
.
Replicas
!=
17
{
controller
.
Spec
.
Replicas
!=
17
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
}
}
}
}
...
@@ -221,7 +219,7 @@ func TestCloudCfgDeleteController(t *testing.T) {
...
@@ -221,7 +219,7 @@ func TestCloudCfgDeleteController(t *testing.T) {
func
TestCloudCfgDeleteControllerWithReplicas
(
t
*
testing
.
T
)
{
func
TestCloudCfgDeleteControllerWithReplicas
(
t
*
testing
.
T
)
{
fakeClient
:=
client
.
Fake
{
fakeClient
:=
client
.
Fake
{
Ctrl
:
api
.
ReplicationController
{
Ctrl
:
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
},
},
},
},
...
...
pkg/kubecfg/parse_test.go
View file @
94c873e7
...
@@ -107,18 +107,15 @@ func TestParseController(t *testing.T) {
...
@@ -107,18 +107,15 @@ func TestParseController(t *testing.T) {
DoParseTest
(
t
,
"replicationControllers"
,
&
api
.
ReplicationController
{
DoParseTest
(
t
,
"replicationControllers"
,
&
api
.
ReplicationController
{
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicationController"
},
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicationController"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"my controller"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"my controller"
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
9001
,
Replicas
:
9001
,
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
Spec
:
api
.
PodSpec
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
ID
:
"My manifest"
,
{
Name
:
"my container"
},
Containers
:
[]
api
.
Container
{
},
{
Name
:
"my container"
},
Volumes
:
[]
api
.
Volume
{
},
{
Name
:
"volume"
},
Volumes
:
[]
api
.
Volume
{
{
Name
:
"volume"
},
},
},
},
},
},
},
},
...
...
pkg/kubecfg/resource_printer.go
View file @
94c873e7
...
@@ -185,6 +185,14 @@ func makeImageList(manifest api.ContainerManifest) string {
...
@@ -185,6 +185,14 @@ func makeImageList(manifest api.ContainerManifest) string {
return
strings
.
Join
(
images
,
","
)
return
strings
.
Join
(
images
,
","
)
}
}
func
makeImageListPodSpec
(
spec
api
.
PodSpec
)
string
{
var
images
[]
string
for
_
,
container
:=
range
spec
.
Containers
{
images
=
append
(
images
,
container
.
Image
)
}
return
strings
.
Join
(
images
,
","
)
}
func
podHostString
(
host
,
ip
string
)
string
{
func
podHostString
(
host
,
ip
string
)
string
{
if
host
==
""
&&
ip
==
""
{
if
host
==
""
&&
ip
==
""
{
return
"<unassigned>"
return
"<unassigned>"
...
@@ -211,8 +219,8 @@ func printPodList(podList *api.PodList, w io.Writer) error {
...
@@ -211,8 +219,8 @@ func printPodList(podList *api.PodList, w io.Writer) error {
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
)
error
{
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%d
\n
"
,
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%d
\n
"
,
controller
.
Name
,
makeImageList
(
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
),
controller
.
Name
,
makeImageList
PodSpec
(
controller
.
Spec
.
Template
.
Spec
),
labels
.
Set
(
controller
.
DesiredState
.
ReplicaSelector
),
controller
.
DesiredState
.
Replicas
)
labels
.
Set
(
controller
.
Spec
.
Selector
),
controller
.
Spec
.
Replicas
)
return
err
return
err
}
}
...
...
pkg/kubectl/describe.go
View file @
94c873e7
...
@@ -87,9 +87,15 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) {
...
@@ -87,9 +87,15 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) {
return
""
,
err
return
""
,
err
}
}
// TODO: remove me when pods are converted
spec
:=
&
api
.
PodSpec
{}
if
err
:=
api
.
Scheme
.
Convert
(
&
pod
.
DesiredState
.
Manifest
,
spec
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to convert pod manifest: %v"
,
err
)
}
return
tabbedString
(
func
(
out
*
tabwriter
.
Writer
)
error
{
return
tabbedString
(
func
(
out
*
tabwriter
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pod
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pod
.
Name
)
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
pod
.
DesiredState
.
Manifest
))
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
spec
))
fmt
.
Fprintf
(
out
,
"Host:
\t
%s
\n
"
,
pod
.
CurrentState
.
Host
+
"/"
+
pod
.
CurrentState
.
HostIP
)
fmt
.
Fprintf
(
out
,
"Host:
\t
%s
\n
"
,
pod
.
CurrentState
.
Host
+
"/"
+
pod
.
CurrentState
.
HostIP
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
formatLabels
(
pod
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
formatLabels
(
pod
.
Labels
))
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
string
(
pod
.
CurrentState
.
Status
))
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
string
(
pod
.
CurrentState
.
Status
))
...
@@ -127,10 +133,10 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string) (strin
...
@@ -127,10 +133,10 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string) (strin
return
tabbedString
(
func
(
out
*
tabwriter
.
Writer
)
error
{
return
tabbedString
(
func
(
out
*
tabwriter
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
controller
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
controller
.
Name
)
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
))
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
&
controller
.
Spec
.
Template
.
Spec
))
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
formatLabels
(
controller
.
DesiredState
.
Replica
Selector
))
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
formatLabels
(
controller
.
Spec
.
Selector
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
formatLabels
(
controller
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
formatLabels
(
controller
.
Labels
))
fmt
.
Fprintf
(
out
,
"Replicas:
\t
%d current / %d desired
\n
"
,
controller
.
CurrentState
.
Replicas
,
controller
.
DesiredState
.
Replicas
)
fmt
.
Fprintf
(
out
,
"Replicas:
\t
%d current / %d desired
\n
"
,
controller
.
Status
.
Replicas
,
controller
.
Spec
.
Replicas
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
failed
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
failed
)
return
nil
return
nil
})
})
...
@@ -197,7 +203,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
...
@@ -197,7 +203,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
// Find the ones that match labelsToMatch.
// Find the ones that match labelsToMatch.
var
matchingRCs
[]
api
.
ReplicationController
var
matchingRCs
[]
api
.
ReplicationController
for
_
,
controller
:=
range
rcs
.
Items
{
for
_
,
controller
:=
range
rcs
.
Items
{
selector
:=
labels
.
SelectorFromSet
(
controller
.
DesiredState
.
Replica
Selector
)
selector
:=
labels
.
SelectorFromSet
(
controller
.
Spec
.
Selector
)
if
selector
.
Matches
(
labelsToMatch
)
{
if
selector
.
Matches
(
labelsToMatch
)
{
matchingRCs
=
append
(
matchingRCs
,
controller
)
matchingRCs
=
append
(
matchingRCs
,
controller
)
}
}
...
@@ -206,7 +212,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
...
@@ -206,7 +212,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
// Format the matching RC's into strings.
// Format the matching RC's into strings.
var
rcStrings
[]
string
var
rcStrings
[]
string
for
_
,
controller
:=
range
matchingRCs
{
for
_
,
controller
:=
range
matchingRCs
{
rcStrings
=
append
(
rcStrings
,
fmt
.
Sprintf
(
"%s (%d/%d replicas created)"
,
controller
.
Name
,
controller
.
CurrentState
.
Replicas
,
controller
.
DesiredState
.
Replicas
))
rcStrings
=
append
(
rcStrings
,
fmt
.
Sprintf
(
"%s (%d/%d replicas created)"
,
controller
.
Name
,
controller
.
Status
.
Replicas
,
controller
.
Spec
.
Replicas
))
}
}
list
:=
strings
.
Join
(
rcStrings
,
", "
)
list
:=
strings
.
Join
(
rcStrings
,
", "
)
...
@@ -217,7 +223,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
...
@@ -217,7 +223,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
}
}
func
getPodStatusForReplicationController
(
c
client
.
PodInterface
,
controller
*
api
.
ReplicationController
)
(
running
,
waiting
,
succeeded
,
failed
int
,
err
error
)
{
func
getPodStatusForReplicationController
(
c
client
.
PodInterface
,
controller
*
api
.
ReplicationController
)
(
running
,
waiting
,
succeeded
,
failed
int
,
err
error
)
{
rcPods
,
err
:=
c
.
List
(
labels
.
SelectorFromSet
(
controller
.
DesiredState
.
Replica
Selector
))
rcPods
,
err
:=
c
.
List
(
labels
.
SelectorFromSet
(
controller
.
Spec
.
Selector
))
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
...
pkg/kubectl/kubectl.go
View file @
94c873e7
...
@@ -139,9 +139,9 @@ func formatLabels(labelMap map[string]string) string {
...
@@ -139,9 +139,9 @@ func formatLabels(labelMap map[string]string) string {
return
l
return
l
}
}
func
makeImageList
(
manifest
api
.
ContainerManifest
)
string
{
func
makeImageList
(
spec
*
api
.
PodSpec
)
string
{
var
images
[]
string
var
images
[]
string
for
_
,
container
:=
range
manifest
.
Containers
{
for
_
,
container
:=
range
spec
.
Containers
{
images
=
append
(
images
,
container
.
Image
)
images
=
append
(
images
,
container
.
Image
)
}
}
return
strings
.
Join
(
images
,
","
)
return
strings
.
Join
(
images
,
","
)
...
...
pkg/kubectl/resource_printer.go
View file @
94c873e7
...
@@ -206,8 +206,14 @@ func podHostString(host, ip string) string {
...
@@ -206,8 +206,14 @@ func podHostString(host, ip string) string {
}
}
func
printPod
(
pod
*
api
.
Pod
,
w
io
.
Writer
)
error
{
func
printPod
(
pod
*
api
.
Pod
,
w
io
.
Writer
)
error
{
// TODO: remove me when pods are converted
spec
:=
&
api
.
PodSpec
{}
if
err
:=
api
.
Scheme
.
Convert
(
&
pod
.
DesiredState
.
Manifest
,
spec
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to convert pod manifest: %v"
,
err
)
}
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
,
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
,
pod
.
Name
,
makeImageList
(
pod
.
DesiredState
.
Manifest
),
pod
.
Name
,
makeImageList
(
spec
),
podHostString
(
pod
.
CurrentState
.
Host
,
pod
.
CurrentState
.
HostIP
),
podHostString
(
pod
.
CurrentState
.
Host
,
pod
.
CurrentState
.
HostIP
),
labels
.
Set
(
pod
.
Labels
),
pod
.
CurrentState
.
Status
)
labels
.
Set
(
pod
.
Labels
),
pod
.
CurrentState
.
Status
)
return
err
return
err
...
@@ -224,8 +230,8 @@ func printPodList(podList *api.PodList, w io.Writer) error {
...
@@ -224,8 +230,8 @@ func printPodList(podList *api.PodList, w io.Writer) error {
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
)
error
{
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%d
\n
"
,
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%d
\n
"
,
controller
.
Name
,
makeImageList
(
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
),
controller
.
Name
,
makeImageList
(
&
controller
.
Spec
.
Template
.
Spec
),
labels
.
Set
(
controller
.
DesiredState
.
ReplicaSelector
),
controller
.
DesiredState
.
Replicas
)
labels
.
Set
(
controller
.
Spec
.
Selector
),
controller
.
Spec
.
Replicas
)
return
err
return
err
}
}
...
...
pkg/registry/controller/rest.go
View file @
94c873e7
...
@@ -64,8 +64,6 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -64,8 +64,6 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if
len
(
controller
.
Name
)
==
0
{
if
len
(
controller
.
Name
)
==
0
{
controller
.
Name
=
util
.
NewUUID
()
.
String
()
controller
.
Name
=
util
.
NewUUID
()
.
String
()
}
}
// Pod Manifest ID should be assigned by the pod API
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
ID
=
""
if
errs
:=
validation
.
ValidateReplicationController
(
controller
);
len
(
errs
)
>
0
{
if
errs
:=
validation
.
ValidateReplicationController
(
controller
);
len
(
errs
)
>
0
{
return
nil
,
errors
.
NewInvalid
(
"replicationController"
,
controller
.
Name
,
errs
)
return
nil
,
errors
.
NewInvalid
(
"replicationController"
,
controller
.
Name
,
errs
)
}
}
...
@@ -158,41 +156,41 @@ func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVer
...
@@ -158,41 +156,41 @@ func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVer
// TODO(lavalamp): remove watch.Filter, which is broken. Implement consistent way of filtering.
// TODO(lavalamp): remove watch.Filter, which is broken. Implement consistent way of filtering.
// TODO(lavalamp): this watch method needs a test.
// TODO(lavalamp): this watch method needs a test.
return
watch
.
Filter
(
incoming
,
func
(
e
watch
.
Event
)
(
watch
.
Event
,
bool
)
{
return
watch
.
Filter
(
incoming
,
func
(
e
watch
.
Event
)
(
watch
.
Event
,
bool
)
{
repC
ontroller
,
ok
:=
e
.
Object
.
(
*
api
.
ReplicationController
)
c
ontroller
,
ok
:=
e
.
Object
.
(
*
api
.
ReplicationController
)
if
!
ok
{
if
!
ok
{
// must be an error event-- pass it on
// must be an error event-- pass it on
return
e
,
true
return
e
,
true
}
}
match
:=
label
.
Matches
(
labels
.
Set
(
repC
ontroller
.
Labels
))
match
:=
label
.
Matches
(
labels
.
Set
(
c
ontroller
.
Labels
))
if
match
{
if
match
{
rs
.
fillCurrentState
(
ctx
,
repC
ontroller
)
rs
.
fillCurrentState
(
ctx
,
c
ontroller
)
}
}
return
e
,
match
return
e
,
match
}),
nil
}),
nil
}
}
func
(
rs
*
REST
)
waitForController
(
ctx
api
.
Context
,
c
trl
*
api
.
ReplicationController
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
waitForController
(
ctx
api
.
Context
,
c
ontroller
*
api
.
ReplicationController
)
(
runtime
.
Object
,
error
)
{
for
{
for
{
pods
,
err
:=
rs
.
podLister
.
ListPods
(
ctx
,
labels
.
Set
(
c
trl
.
DesiredState
.
Replica
Selector
)
.
AsSelector
())
pods
,
err
:=
rs
.
podLister
.
ListPods
(
ctx
,
labels
.
Set
(
c
ontroller
.
Spec
.
Selector
)
.
AsSelector
())
if
err
!=
nil
{
if
err
!=
nil
{
return
c
trl
,
err
return
c
ontroller
,
err
}
}
if
len
(
pods
.
Items
)
==
c
trl
.
DesiredState
.
Replicas
{
if
len
(
pods
.
Items
)
==
c
ontroller
.
Spec
.
Replicas
{
break
break
}
}
time
.
Sleep
(
rs
.
pollPeriod
)
time
.
Sleep
(
rs
.
pollPeriod
)
}
}
return
c
trl
,
nil
return
c
ontroller
,
nil
}
}
func
(
rs
*
REST
)
fillCurrentState
(
ctx
api
.
Context
,
c
trl
*
api
.
ReplicationController
)
error
{
func
(
rs
*
REST
)
fillCurrentState
(
ctx
api
.
Context
,
c
ontroller
*
api
.
ReplicationController
)
error
{
if
rs
.
podLister
==
nil
{
if
rs
.
podLister
==
nil
{
return
nil
return
nil
}
}
list
,
err
:=
rs
.
podLister
.
ListPods
(
ctx
,
labels
.
Set
(
c
trl
.
DesiredState
.
Replica
Selector
)
.
AsSelector
())
list
,
err
:=
rs
.
podLister
.
ListPods
(
ctx
,
labels
.
Set
(
c
ontroller
.
Spec
.
Selector
)
.
AsSelector
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
c
trl
.
CurrentState
.
Replicas
=
len
(
list
.
Items
)
c
ontroller
.
Status
.
Replicas
=
len
(
list
.
Items
)
return
nil
return
nil
}
}
pkg/registry/controller/rest_test.go
View file @
94c873e7
...
@@ -116,6 +116,15 @@ func TestControllerDecode(t *testing.T) {
...
@@ -116,6 +116,15 @@ func TestControllerDecode(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"nginx"
,
},
},
},
},
}
}
body
,
err
:=
latest
.
Codec
.
Encode
(
controller
)
body
,
err
:=
latest
.
Codec
.
Encode
(
controller
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -140,30 +149,30 @@ func TestControllerParsing(t *testing.T) {
...
@@ -140,30 +149,30 @@ func TestControllerParsing(t *testing.T) {
"name"
:
"nginx"
,
"name"
:
"nginx"
,
},
},
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
Replica
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"name"
:
"nginx"
,
"name"
:
"nginx"
,
},
},
PodTemplate
:
api
.
PodTemplate
{
Template
:
&
api
.
PodTemplateSpec
{
DesiredState
:
api
.
PodState
{
ObjectMeta
:
api
.
ObjectMeta
{
Manifest
:
api
.
ContainerManifest
{
Labels
:
map
[
string
]
string
{
Containers
:
[]
api
.
Container
{
"name"
:
"nginx"
,
{
},
Image
:
"dockerfile/nginx"
,
},
Ports
:
[]
api
.
Port
{
Spec
:
api
.
PodSpec
{
{
Containers
:
[]
api
.
Container
{
ContainerPort
:
80
,
{
HostPort
:
8080
,
Image
:
"dockerfile/nginx"
,
},
Ports
:
[]
api
.
Port
{
{
ContainerPort
:
80
,
HostPort
:
8080
,
},
},
},
},
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
"name"
:
"nginx"
,
},
},
},
},
},
}
}
...
@@ -205,9 +214,11 @@ func TestControllerParsing(t *testing.T) {
...
@@ -205,9 +214,11 @@ func TestControllerParsing(t *testing.T) {
}
}
var
validPodTemplate
=
api
.
PodTemplate
{
var
validPodTemplate
=
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Spec
:
api
.
PodTemplateSpec
{
Manifest
:
api
.
ContainerManifest
{
ObjectMeta
:
api
.
ObjectMeta
{
Version
:
"v1beta1"
,
Labels
:
map
[
string
]
string
{
"a"
:
"b"
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Name
:
"test"
,
Name
:
"test"
,
...
@@ -216,7 +227,6 @@ var validPodTemplate = api.PodTemplate{
...
@@ -216,7 +227,6 @@ var validPodTemplate = api.PodTemplate{
},
},
},
},
},
},
Labels
:
map
[
string
]
string
{
"a"
:
"b"
},
}
}
func
TestCreateController
(
t
*
testing
.
T
)
{
func
TestCreateController
(
t
*
testing
.
T
)
{
...
@@ -240,10 +250,10 @@ func TestCreateController(t *testing.T) {
...
@@ -240,10 +250,10 @@ func TestCreateController(t *testing.T) {
}
}
controller
:=
&
api
.
ReplicationController
{
controller
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
Replica
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
PodTemplate
:
validPodTemplate
,
Template
:
&
validPodTemplate
.
Spec
,
},
},
}
}
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
...
@@ -273,13 +283,13 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
...
@@ -273,13 +283,13 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
failureCases
:=
map
[
string
]
api
.
ReplicationController
{
failureCases
:=
map
[
string
]
api
.
ReplicationController
{
"empty ID"
:
{
"empty ID"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replica
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
},
},
},
},
"empty selector"
:
{
"empty selector"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
DesiredState
:
api
.
ReplicationControllerState
{},
Spec
:
api
.
ReplicationControllerSpec
{},
},
},
}
}
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
...
@@ -304,13 +314,13 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
...
@@ -304,13 +314,13 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
failureCases
:=
map
[
string
]
api
.
ReplicationController
{
failureCases
:=
map
[
string
]
api
.
ReplicationController
{
"empty ID"
:
{
"empty ID"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replica
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
},
},
},
},
"empty selector"
:
{
"empty selector"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
DesiredState
:
api
.
ReplicationControllerState
{},
Spec
:
api
.
ReplicationControllerSpec
{},
},
},
}
}
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
...
@@ -351,19 +361,19 @@ func TestFillCurrentState(t *testing.T) {
...
@@ -351,19 +361,19 @@ func TestFillCurrentState(t *testing.T) {
podLister
:
&
fakeLister
,
podLister
:
&
fakeLister
,
}
}
controller
:=
api
.
ReplicationController
{
controller
:=
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replica
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
,
"foo"
:
"bar"
,
},
},
},
},
}
}
ctx
:=
api
.
NewContext
()
ctx
:=
api
.
NewContext
()
storage
.
fillCurrentState
(
ctx
,
&
controller
)
storage
.
fillCurrentState
(
ctx
,
&
controller
)
if
controller
.
CurrentState
.
Replicas
!=
2
{
if
controller
.
Status
.
Replicas
!=
2
{
t
.
Errorf
(
"expected 2, got: %d"
,
controller
.
CurrentState
.
Replicas
)
t
.
Errorf
(
"expected 2, got: %d"
,
controller
.
Status
.
Replicas
)
}
}
if
!
reflect
.
DeepEqual
(
fakeLister
.
s
,
labels
.
Set
(
controller
.
DesiredState
.
Replica
Selector
)
.
AsSelector
())
{
if
!
reflect
.
DeepEqual
(
fakeLister
.
s
,
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
())
{
t
.
Errorf
(
"unexpected output: %#v %#v"
,
labels
.
Set
(
controller
.
DesiredState
.
Replica
Selector
)
.
AsSelector
(),
fakeLister
.
s
)
t
.
Errorf
(
"unexpected output: %#v %#v"
,
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
(),
fakeLister
.
s
)
}
}
}
}
...
...
pkg/registry/etcd/etcd_test.go
View file @
94c873e7
...
@@ -960,7 +960,7 @@ func TestEtcdUpdateController(t *testing.T) {
...
@@ -960,7 +960,7 @@ func TestEtcdUpdateController(t *testing.T) {
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
err
:=
registry
.
UpdateController
(
ctx
,
&
api
.
ReplicationController
{
err
:=
registry
.
UpdateController
(
ctx
,
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
strconv
.
FormatUint
(
resp
.
Node
.
ModifiedIndex
,
10
)},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
strconv
.
FormatUint
(
resp
.
Node
.
ModifiedIndex
,
10
)},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replicas
:
2
,
},
},
})
})
...
@@ -969,7 +969,7 @@ func TestEtcdUpdateController(t *testing.T) {
...
@@ -969,7 +969,7 @@ func TestEtcdUpdateController(t *testing.T) {
}
}
ctrl
,
err
:=
registry
.
GetController
(
ctx
,
"foo"
)
ctrl
,
err
:=
registry
.
GetController
(
ctx
,
"foo"
)
if
ctrl
.
DesiredState
.
Replicas
!=
2
{
if
ctrl
.
Spec
.
Replicas
!=
2
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
ctrl
)
t
.
Errorf
(
"Unexpected controller: %#v"
,
ctrl
)
}
}
}
}
...
...
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