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) {
if
err
!=
nil
{
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
}
var
controller
Request
api
.
ReplicationController
if
err
:=
json
.
Unmarshal
(
data
,
&
controller
Request
);
err
!=
nil
{
var
controller
api
.
ReplicationController
if
err
:=
json
.
Unmarshal
(
data
,
&
controller
);
err
!=
nil
{
glog
.
Fatalf
(
"Unexpected error: %#v"
,
err
)
}
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
.
Infof
(
"Done creating replication controllers"
)
// 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
)
}
// 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
{
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) {
ctx
:=
api
.
NewDefaultContext
()
switch
t
:=
obj
.
(
type
)
{
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
:
for
i
:=
range
t
.
Items
{
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
}
case
*
api
.
Service
:
if
t
.
Namespace
==
""
{
t
.
Namespace
=
api
.
NamespaceDefault
}
api
.
ValidNamespace
(
ctx
,
&
t
.
ObjectMeta
)
errors
=
validation
.
ValidateService
(
t
,
registrytest
.
NewServiceRegistry
(),
api
.
NewDefaultContext
())
case
*
api
.
ServiceList
:
...
...
@@ -49,8 +55,11 @@ func validateObject(obj runtime.Object) (errors []error) {
errors
=
append
(
errors
,
validateObject
(
&
t
.
Items
[
i
])
...
)
}
case
*
api
.
Pod
:
if
t
.
Namespace
==
""
{
t
.
Namespace
=
api
.
NamespaceDefault
}
api
.
ValidNamespace
(
ctx
,
&
t
.
ObjectMeta
)
errors
=
validation
.
Validate
Manifest
(
&
t
.
DesiredState
.
Manifes
t
)
errors
=
validation
.
Validate
Pod
(
t
)
case
*
api
.
PodList
:
for
i
:=
range
t
.
Items
{
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(
statuses
:=
[]
internal
.
PodCondition
{
internal
.
PodPending
,
internal
.
PodRunning
,
internal
.
PodFailed
}
*
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
)
{
// util.IntOrString will panic if its kind is set wrong.
if
c
.
RandBool
()
{
...
...
@@ -127,6 +144,7 @@ func TestInternalRoundTrip(t *testing.T) {
if
err
:=
internal
.
Scheme
.
Convert
(
obj
,
newer
);
err
!=
nil
{
t
.
Errorf
(
"unable to convert %#v to %#v: %v"
,
obj
,
newer
,
err
)
continue
}
actual
,
err
:=
internal
.
Scheme
.
New
(
""
,
k
)
...
...
@@ -137,6 +155,7 @@ func TestInternalRoundTrip(t *testing.T) {
if
err
:=
internal
.
Scheme
.
Convert
(
newer
,
actual
);
err
!=
nil
{
t
.
Errorf
(
"unable to convert %#v to %#v: %v"
,
newer
,
actual
,
err
)
continue
}
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(
statuses
:=
[]
api
.
PodCondition
{
api
.
PodPending
,
api
.
PodRunning
,
api
.
PodFailed
}
*
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
)
{
// util.IntOrString will panic if its kind is set wrong.
if
c
.
RandBool
()
{
...
...
@@ -176,18 +193,21 @@ func TestSpecificKind(t *testing.T) {
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
(
""
)
{
if
nonRoundTrippableTypes
.
Has
(
kind
)
{
continue
}
// Try a few times, since runTest uses random values.
for
i
:=
0
;
i
<
*
fuzzIters
;
i
++
{
item
,
err
:=
api
.
Scheme
.
New
(
""
,
kind
)
if
err
!=
nil
{
t
.
Errorf
(
"Couldn't make a %v? %v"
,
kind
,
err
)
continue
t
.
Fatalf
(
"Couldn't make a %v? %v"
,
kind
,
err
)
}
if
_
,
err
:=
meta
.
Accessor
(
item
);
err
!=
nil
{
t
.
Logf
(
"%s is not a TypeMeta and cannot be round tripped: %v"
,
kind
,
err
)
continue
t
.
Fatalf
(
"%q is not a TypeMeta and cannot be tested - add it to nonRoundTrippableTypes: %v"
,
kind
,
err
)
}
runTest
(
t
,
v1beta1
.
Codec
,
item
)
runTest
(
t
,
v1beta2
.
Codec
,
item
)
...
...
pkg/client/client_test.go
View file @
94c873e7
...
...
@@ -309,8 +309,9 @@ func TestListControllers(t *testing.T) {
"name"
:
"baz"
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
...
...
@@ -335,8 +336,9 @@ func TestGetController(t *testing.T) {
"name"
:
"baz"
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
...
...
@@ -361,8 +363,9 @@ func TestUpdateController(t *testing.T) {
"name"
:
"baz"
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
...
...
@@ -396,8 +399,9 @@ func TestCreateController(t *testing.T) {
"name"
:
"baz"
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Template
:
&
api
.
PodTemplateSpec
{},
},
},
},
...
...
pkg/client/conditions.go
View file @
94c873e7
...
...
@@ -26,10 +26,10 @@ import (
// for a controller's ReplicaSelector equals the Replicas count.
func
(
c
*
Client
)
ControllerHasDesiredReplicas
(
controller
api
.
ReplicationController
)
wait
.
ConditionFunc
{
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
{
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 {
syncTime
<-
chan
time
.
Time
// 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
// created as an interface to allow testing.
type
PodControlInterface
interface
{
// 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
(
namespace
string
,
podID
string
)
error
}
...
...
@@ -52,16 +52,19 @@ type RealPodControl struct {
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
)
for
k
,
v
:=
range
controller
Spec
.
DesiredState
.
Pod
Template
.
Labels
{
for
k
,
v
:=
range
controller
.
Spec
.
Template
.
Labels
{
desiredLabels
[
k
]
=
v
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
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
{
glog
.
Errorf
(
"Unable to create pod replica: %v"
,
err
)
...
...
@@ -142,14 +145,14 @@ func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod {
return
result
}
func
(
rm
*
ReplicationManager
)
syncReplicationController
(
controller
Spec
api
.
ReplicationController
)
error
{
s
:=
labels
.
Set
(
controller
Spec
.
DesiredState
.
Replica
Selector
)
.
AsSelector
()
podList
,
err
:=
rm
.
kubeClient
.
Pods
(
controller
Spec
.
Namespace
)
.
List
(
s
)
func
(
rm
*
ReplicationManager
)
syncReplicationController
(
controller
api
.
ReplicationController
)
error
{
s
:=
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
()
podList
,
err
:=
rm
.
kubeClient
.
Pods
(
controller
.
Namespace
)
.
List
(
s
)
if
err
!=
nil
{
return
err
}
filteredList
:=
rm
.
filterActivePods
(
podList
.
Items
)
diff
:=
len
(
filteredList
)
-
controller
Spec
.
DesiredState
.
Replicas
diff
:=
len
(
filteredList
)
-
controller
.
Spec
.
Replicas
if
diff
<
0
{
diff
*=
-
1
wait
:=
sync
.
WaitGroup
{}
...
...
@@ -158,7 +161,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
for
i
:=
0
;
i
<
diff
;
i
++
{
go
func
()
{
defer
wait
.
Done
()
rm
.
podControl
.
createReplica
(
controller
Spec
.
Namespace
,
controllerSpec
)
rm
.
podControl
.
createReplica
(
controller
.
Namespace
,
controller
)
}()
}
wait
.
Wait
()
...
...
@@ -169,7 +172,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
for
i
:=
0
;
i
<
diff
;
i
++
{
go
func
(
ix
int
)
{
defer
wait
.
Done
()
rm
.
podControl
.
deletePod
(
controller
Spec
.
Namespace
,
filteredList
[
ix
]
.
Name
)
rm
.
podControl
.
deletePod
(
controller
.
Namespace
,
filteredList
[
ix
]
.
Name
)
}(
i
)
}
wait
.
Wait
()
...
...
@@ -180,20 +183,20 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
func
(
rm
*
ReplicationManager
)
synchronize
()
{
// TODO: remove this method completely and rely on the watch.
// 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
())
if
err
!=
nil
{
glog
.
Errorf
(
"Synchronization error: %v (%#v)"
,
err
,
err
)
return
}
controller
Spec
s
=
list
.
Items
controllers
=
list
.
Items
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
len
(
controller
Spec
s
))
for
ix
:=
range
controller
Spec
s
{
wg
.
Add
(
len
(
controllers
))
for
ix
:=
range
controllers
{
go
func
(
ix
int
)
{
defer
wg
.
Done
()
glog
.
V
(
4
)
.
Infof
(
"periodic sync of %v"
,
controller
Spec
s
[
ix
]
.
Name
)
err
:=
rm
.
syncHandler
(
controller
Spec
s
[
ix
])
glog
.
V
(
4
)
.
Infof
(
"periodic sync of %v"
,
controllers
[
ix
]
.
Name
)
err
:=
rm
.
syncHandler
(
controllers
[
ix
])
if
err
!=
nil
{
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 {
func
newReplicationController
(
replicas
int
)
api
.
ReplicationController
{
return
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
replicas
,
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
},
},
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
},
},
},
...
...
@@ -188,21 +188,21 @@ func TestCreateReplica(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
},
DesiredState
:
api
.
ReplicationControllerState
{
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
"replicationController"
:
"test"
,
},
},
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
"replicationController"
:
"test"
,
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
},
},
},
...
...
@@ -210,11 +210,18 @@ func TestCreateReplica(t *testing.T) {
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
{
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
)
actualPod
,
err
:=
client
.
Codec
.
Decode
([]
byte
(
fakeHandler
.
RequestBody
))
...
...
@@ -230,42 +237,42 @@ func TestCreateReplica(t *testing.T) {
func
TestSynchonize
(
t
*
testing
.
T
)
{
controllerSpec1
:=
api
.
ReplicationController
{
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
testapi
.
Version
()},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
4
,
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
},
},
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
},
},
},
}
controllerSpec2
:=
api
.
ReplicationController
{
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
testapi
.
Version
()},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
3
,
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
{
Image
:
"bar/baz"
,
},
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"bar"
,
"type"
:
"production"
,
},
},
Labels
:
map
[
string
]
string
{
"name"
:
"bar"
,
"type"
:
"production"
,
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
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
}
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
)
if
err
!=
nil
{
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
)
if
err
!=
nil
{
...
...
@@ -181,7 +181,7 @@ func ResizeController(ctx api.Context, name string, replicas int, client client.
if
err
!=
nil
{
return
err
}
controller
.
DesiredState
.
Replicas
=
replicas
controller
.
Spec
.
Replicas
=
replicas
controllerOut
,
err
:=
client
.
ReplicationControllers
(
api
.
Namespace
(
ctx
))
.
Update
(
controller
)
if
err
!=
nil
{
return
err
...
...
@@ -251,26 +251,25 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
replicas
,
Replica
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"name"
:
name
,
},
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Version
:
"v1beta2"
,
Containers
:
[]
api
.
Container
{
{
Name
:
strings
.
ToLower
(
name
),
Image
:
image
,
Ports
:
ports
,
},
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
name
,
},
},
Labels
:
map
[
string
]
string
{
"name"
:
name
,
Spec
:
api
.
PodSpec
{
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
if
err
!=
nil
{
return
err
}
if
controller
.
DesiredState
.
Replicas
!=
0
{
return
fmt
.
Errorf
(
"controller has non-zero replicas (%d), please stop it first"
,
controller
.
DesiredState
.
Replicas
)
if
controller
.
Spec
.
Replicas
!=
0
{
return
fmt
.
Errorf
(
"controller has non-zero replicas (%d), please stop it first"
,
controller
.
Spec
.
Replicas
)
}
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) {
},
},
Ctrl
:
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
{
Image
:
"fooImage:1"
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Template
:
&
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Image
:
"fooImage:1"
},
},
},
},
...
...
@@ -94,7 +92,7 @@ func TestUpdateWithNewImage(t *testing.T) {
validateAction
(
client
.
FakeAction
{
Action
:
"get-controller"
,
Value
:
"foo"
},
fakeClient
.
Actions
[
0
],
t
)
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
:
"list-pods"
},
fakeClient
.
Actions
[
2
],
t
)
...
...
@@ -115,8 +113,8 @@ func TestRunController(t *testing.T) {
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
Name
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
Spec
.
Replicas
!=
replicas
||
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
!=
image
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
}
}
...
...
@@ -136,8 +134,8 @@ func TestRunControllerWithWrongArgs(t *testing.T) {
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
Name
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
Spec
.
Replicas
!=
replicas
||
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
!=
image
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
}
}
...
...
@@ -155,8 +153,8 @@ func TestRunControllerWithService(t *testing.T) {
}
controller
:=
fakeClient
.
Actions
[
0
]
.
Value
.
(
*
api
.
ReplicationController
)
if
controller
.
Name
!=
name
||
controller
.
DesiredState
.
Replicas
!=
replicas
||
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
.
Containers
[
0
]
.
Image
!=
image
{
controller
.
Spec
.
Replicas
!=
replicas
||
controller
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
!=
image
{
t
.
Errorf
(
"Unexpected controller: %#v"
,
controller
)
}
}
...
...
@@ -174,7 +172,7 @@ func TestStopController(t *testing.T) {
}
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
controller
.
DesiredState
.
Replicas
!=
0
{
controller
.
Spec
.
Replicas
!=
0
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
}
}
...
...
@@ -193,7 +191,7 @@ func TestResizeController(t *testing.T) {
}
controller
:=
fakeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
if
fakeClient
.
Actions
[
1
]
.
Action
!=
"update-controller"
||
controller
.
DesiredState
.
Replicas
!=
17
{
controller
.
Spec
.
Replicas
!=
17
{
t
.
Errorf
(
"Unexpected Action: %#v"
,
fakeClient
.
Actions
[
1
])
}
}
...
...
@@ -221,7 +219,7 @@ func TestCloudCfgDeleteController(t *testing.T) {
func
TestCloudCfgDeleteControllerWithReplicas
(
t
*
testing
.
T
)
{
fakeClient
:=
client
.
Fake
{
Ctrl
:
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
},
},
...
...
pkg/kubecfg/parse_test.go
View file @
94c873e7
...
...
@@ -107,18 +107,15 @@ func TestParseController(t *testing.T) {
DoParseTest
(
t
,
"replicationControllers"
,
&
api
.
ReplicationController
{
TypeMeta
:
api
.
TypeMeta
{
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicationController"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"my controller"
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
9001
,
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
ID
:
"My manifest"
,
Containers
:
[]
api
.
Container
{
{
Name
:
"my container"
},
},
Volumes
:
[]
api
.
Volume
{
{
Name
:
"volume"
},
},
Template
:
&
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"my container"
},
},
Volumes
:
[]
api
.
Volume
{
{
Name
:
"volume"
},
},
},
},
...
...
pkg/kubecfg/resource_printer.go
View file @
94c873e7
...
...
@@ -185,6 +185,14 @@ func makeImageList(manifest api.ContainerManifest) string {
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
{
if
host
==
""
&&
ip
==
""
{
return
"<unassigned>"
...
...
@@ -211,8 +219,8 @@ func printPodList(podList *api.PodList, 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
"
,
controller
.
Name
,
makeImageList
(
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
),
labels
.
Set
(
controller
.
DesiredState
.
ReplicaSelector
),
controller
.
DesiredState
.
Replicas
)
controller
.
Name
,
makeImageList
PodSpec
(
controller
.
Spec
.
Template
.
Spec
),
labels
.
Set
(
controller
.
Spec
.
Selector
),
controller
.
Spec
.
Replicas
)
return
err
}
...
...
pkg/kubectl/describe.go
View file @
94c873e7
...
...
@@ -87,9 +87,15 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) {
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
{
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
,
"Labels:
\t
%s
\n
"
,
formatLabels
(
pod
.
Labels
))
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
string
(
pod
.
CurrentState
.
Status
))
...
...
@@ -127,10 +133,10 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string) (strin
return
tabbedString
(
func
(
out
*
tabwriter
.
Writer
)
error
{
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
,
"Selector:
\t
%s
\n
"
,
formatLabels
(
controller
.
DesiredState
.
Replica
Selector
))
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
&
controller
.
Spec
.
Template
.
Spec
))
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
formatLabels
(
controller
.
Spec
.
Selector
))
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
)
return
nil
})
...
...
@@ -197,7 +203,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
// Find the ones that match labelsToMatch.
var
matchingRCs
[]
api
.
ReplicationController
for
_
,
controller
:=
range
rcs
.
Items
{
selector
:=
labels
.
SelectorFromSet
(
controller
.
DesiredState
.
Replica
Selector
)
selector
:=
labels
.
SelectorFromSet
(
controller
.
Spec
.
Selector
)
if
selector
.
Matches
(
labelsToMatch
)
{
matchingRCs
=
append
(
matchingRCs
,
controller
)
}
...
...
@@ -206,7 +212,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
// Format the matching RC's into strings.
var
rcStrings
[]
string
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
,
", "
)
...
...
@@ -217,7 +223,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
}
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
{
return
}
...
...
pkg/kubectl/kubectl.go
View file @
94c873e7
...
...
@@ -139,9 +139,9 @@ func formatLabels(labelMap map[string]string) string {
return
l
}
func
makeImageList
(
manifest
api
.
ContainerManifest
)
string
{
func
makeImageList
(
spec
*
api
.
PodSpec
)
string
{
var
images
[]
string
for
_
,
container
:=
range
manifest
.
Containers
{
for
_
,
container
:=
range
spec
.
Containers
{
images
=
append
(
images
,
container
.
Image
)
}
return
strings
.
Join
(
images
,
","
)
...
...
pkg/kubectl/resource_printer.go
View file @
94c873e7
...
...
@@ -206,8 +206,14 @@ func podHostString(host, ip string) string {
}
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
"
,
pod
.
Name
,
makeImageList
(
pod
.
DesiredState
.
Manifest
),
pod
.
Name
,
makeImageList
(
spec
),
podHostString
(
pod
.
CurrentState
.
Host
,
pod
.
CurrentState
.
HostIP
),
labels
.
Set
(
pod
.
Labels
),
pod
.
CurrentState
.
Status
)
return
err
...
...
@@ -224,8 +230,8 @@ func printPodList(podList *api.PodList, 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
"
,
controller
.
Name
,
makeImageList
(
controller
.
DesiredState
.
PodTemplate
.
DesiredState
.
Manifest
),
labels
.
Set
(
controller
.
DesiredState
.
ReplicaSelector
),
controller
.
DesiredState
.
Replicas
)
controller
.
Name
,
makeImageList
(
&
controller
.
Spec
.
Template
.
Spec
),
labels
.
Set
(
controller
.
Spec
.
Selector
),
controller
.
Spec
.
Replicas
)
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
if
len
(
controller
.
Name
)
==
0
{
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
{
return
nil
,
errors
.
NewInvalid
(
"replicationController"
,
controller
.
Name
,
errs
)
}
...
...
@@ -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): this watch method needs a test.
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
{
// must be an error event-- pass it on
return
e
,
true
}
match
:=
label
.
Matches
(
labels
.
Set
(
repC
ontroller
.
Labels
))
match
:=
label
.
Matches
(
labels
.
Set
(
c
ontroller
.
Labels
))
if
match
{
rs
.
fillCurrentState
(
ctx
,
repC
ontroller
)
rs
.
fillCurrentState
(
ctx
,
c
ontroller
)
}
return
e
,
match
}),
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
{
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
{
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
}
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
{
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
{
return
err
}
c
trl
.
CurrentState
.
Replicas
=
len
(
list
.
Items
)
c
ontroller
.
Status
.
Replicas
=
len
(
list
.
Items
)
return
nil
}
pkg/registry/controller/rest_test.go
View file @
94c873e7
...
...
@@ -116,6 +116,15 @@ func TestControllerDecode(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"nginx"
,
},
},
},
},
}
body
,
err
:=
latest
.
Codec
.
Encode
(
controller
)
if
err
!=
nil
{
...
...
@@ -140,30 +149,30 @@ func TestControllerParsing(t *testing.T) {
"name"
:
"nginx"
,
},
},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Replica
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"name"
:
"nginx"
,
},
PodTemplate
:
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
{
Image
:
"dockerfile/nginx"
,
Ports
:
[]
api
.
Port
{
{
ContainerPort
:
80
,
HostPort
:
8080
,
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"nginx"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
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) {
}
var
validPodTemplate
=
api
.
PodTemplate
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Version
:
"v1beta1"
,
Spec
:
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
"b"
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"test"
,
...
...
@@ -216,7 +227,6 @@ var validPodTemplate = api.PodTemplate{
},
},
},
Labels
:
map
[
string
]
string
{
"a"
:
"b"
},
}
func
TestCreateController
(
t
*
testing
.
T
)
{
...
...
@@ -240,10 +250,10 @@ func TestCreateController(t *testing.T) {
}
controller
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
},
DesiredState
:
api
.
ReplicationControllerState
{
Replicas
:
2
,
Replica
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
PodTemplate
:
validPodTemplate
,
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
Selector
:
map
[
string
]
string
{
"a"
:
"b"
},
Template
:
&
validPodTemplate
.
Spec
,
},
}
ctx
:=
api
.
NewDefaultContext
()
...
...
@@ -273,13 +283,13 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
failureCases
:=
map
[
string
]
api
.
ReplicationController
{
"empty ID"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
},
DesiredState
:
api
.
ReplicationControllerState
{
Replica
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
},
},
"empty selector"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
DesiredState
:
api
.
ReplicationControllerState
{},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
Spec
:
api
.
ReplicationControllerSpec
{},
},
}
ctx
:=
api
.
NewDefaultContext
()
...
...
@@ -304,13 +314,13 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
failureCases
:=
map
[
string
]
api
.
ReplicationController
{
"empty ID"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
},
DesiredState
:
api
.
ReplicationControllerState
{
Replica
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
"bar"
:
"baz"
},
},
},
"empty selector"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
DesiredState
:
api
.
ReplicationControllerState
{},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
},
Spec
:
api
.
ReplicationControllerSpec
{},
},
}
ctx
:=
api
.
NewDefaultContext
()
...
...
@@ -351,19 +361,19 @@ func TestFillCurrentState(t *testing.T) {
podLister
:
&
fakeLister
,
}
controller
:=
api
.
ReplicationController
{
DesiredState
:
api
.
ReplicationControllerState
{
Replica
Selector
:
map
[
string
]
string
{
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
,
},
},
}
ctx
:=
api
.
NewContext
()
storage
.
fillCurrentState
(
ctx
,
&
controller
)
if
controller
.
CurrentState
.
Replicas
!=
2
{
t
.
Errorf
(
"expected 2, got: %d"
,
controller
.
CurrentState
.
Replicas
)
if
controller
.
Status
.
Replicas
!=
2
{
t
.
Errorf
(
"expected 2, got: %d"
,
controller
.
Status
.
Replicas
)
}
if
!
reflect
.
DeepEqual
(
fakeLister
.
s
,
labels
.
Set
(
controller
.
DesiredState
.
Replica
Selector
)
.
AsSelector
())
{
t
.
Errorf
(
"unexpected output: %#v %#v"
,
labels
.
Set
(
controller
.
DesiredState
.
Replica
Selector
)
.
AsSelector
(),
fakeLister
.
s
)
if
!
reflect
.
DeepEqual
(
fakeLister
.
s
,
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
())
{
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) {
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
err
:=
registry
.
UpdateController
(
ctx
,
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
strconv
.
FormatUint
(
resp
.
Node
.
ModifiedIndex
,
10
)},
DesiredState
:
api
.
ReplicationControllerState
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
2
,
},
})
...
...
@@ -969,7 +969,7 @@ func TestEtcdUpdateController(t *testing.T) {
}
ctrl
,
err
:=
registry
.
GetController
(
ctx
,
"foo"
)
if
ctrl
.
DesiredState
.
Replicas
!=
2
{
if
ctrl
.
Spec
.
Replicas
!=
2
{
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