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
6ae611ae
Commit
6ae611ae
authored
Oct 09, 2014
by
Clayton Coleman
Committed by
Eric Paris
Oct 16, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write BoundPods to etcd instead of ContainerManifestList
Rename ManifestFactory -> BoundPodFactory and change the general structure of the call to focus on BoundPod.
parent
892942af
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
130 additions
and
112 deletions
+130
-112
conversion.go
pkg/api/conversion.go
+16
-1
minioncontroller_test.go
pkg/cloudprovider/controller/minioncontroller_test.go
+5
-3
constraint.go
pkg/constraint/constraint.go
+3
-3
constraint_test.go
pkg/constraint/constraint_test.go
+17
-17
ports.go
pkg/constraint/ports.go
+3
-3
master.go
pkg/master/master.go
+3
-3
etcd.go
pkg/registry/etcd/etcd.go
+18
-18
etcd_test.go
pkg/registry/etcd/etcd_test.go
+33
-33
bound_pod_factory.go
pkg/registry/pod/bound_pod_factory.go
+12
-9
bound_pod_factory_test.go
pkg/registry/pod/bound_pod_factory_test.go
+20
-22
No files found.
pkg/api/conversion.go
View file @
6ae611ae
...
@@ -61,5 +61,20 @@ func init() {
...
@@ -61,5 +61,20 @@ func init() {
}
}
out
.
ResourceVersion
=
in
.
ResourceVersion
out
.
ResourceVersion
=
in
.
ResourceVersion
return
nil
return
nil
})
},
// Convert Pod to BoundPod
func
(
in
*
Pod
,
out
*
BoundPod
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
DesiredState
.
Manifest
,
out
,
0
);
err
!=
nil
{
return
err
}
// Only copy a subset of fields, and override manifest attributes with the pod
// metadata
out
.
UID
=
in
.
UID
out
.
ID
=
in
.
ID
out
.
Namespace
=
in
.
Namespace
out
.
CreationTimestamp
=
in
.
CreationTimestamp
return
nil
},
)
}
}
pkg/cloudprovider/controller/minioncontroller_test.go
View file @
6ae611ae
...
@@ -33,10 +33,12 @@ import (
...
@@ -33,10 +33,12 @@ import (
)
)
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
etcdregistry
.
Registry
{
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
etcdregistry
.
Registry
{
registry
:=
etcdregistry
.
NewRegistry
(
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
registry
:=
etcdregistry
.
NewRegistry
(
&
pod
.
BasicManifestFactory
{
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
&
pod
.
BasicBoundPodFactory
{
ServiceRegistry
:
&
registrytest
.
ServiceRegistry
{},
ServiceRegistry
:
&
registrytest
.
ServiceRegistry
{},
})
},
)
return
registry
return
registry
}
}
...
...
pkg/constraint/constraint.go
View file @
6ae611ae
...
@@ -20,8 +20,8 @@ import (
...
@@ -20,8 +20,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
)
// Allowed returns true if
manifests is a collection of manifest
s
// Allowed returns true if
pods is a collection of bound pod
s
// which can run without conflict on a single minion.
// which can run without conflict on a single minion.
func
Allowed
(
manifests
[]
api
.
ContainerManifest
)
bool
{
func
Allowed
(
pods
[]
api
.
BoundPod
)
bool
{
return
!
PortsConflict
(
manifest
s
)
return
!
PortsConflict
(
pod
s
)
}
}
pkg/constraint/constraint_test.go
View file @
6ae611ae
...
@@ -30,10 +30,10 @@ func containerWithHostPorts(ports ...int) api.Container {
...
@@ -30,10 +30,10 @@ func containerWithHostPorts(ports ...int) api.Container {
return
c
return
c
}
}
func
manifestWithContainers
(
containers
...
api
.
Container
)
api
.
ContainerManifest
{
func
podWithContainers
(
containers
...
api
.
Container
)
api
.
BoundPod
{
m
:=
api
.
ContainerManifest
{}
m
:=
api
.
BoundPod
{}
for
_
,
c
:=
range
containers
{
for
_
,
c
:=
range
containers
{
m
.
Containers
=
append
(
m
.
Containers
,
c
)
m
.
Spec
.
Containers
=
append
(
m
.
Spec
.
Containers
,
c
)
}
}
return
m
return
m
}
}
...
@@ -41,16 +41,16 @@ func manifestWithContainers(containers ...api.Container) api.ContainerManifest {
...
@@ -41,16 +41,16 @@ func manifestWithContainers(containers ...api.Container) api.ContainerManifest {
func
TestAllowed
(
t
*
testing
.
T
)
{
func
TestAllowed
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
allowed
bool
allowed
bool
manifests
[]
api
.
ContainerManifest
pods
[]
api
.
BoundPod
}{
}{
{
{
allowed
:
true
,
allowed
:
true
,
manifests
:
[]
api
.
ContainerManifest
{
pods
:
[]
api
.
BoundPod
{
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
1
,
2
,
3
),
containerWithHostPorts
(
1
,
2
,
3
),
containerWithHostPorts
(
4
,
5
,
6
),
containerWithHostPorts
(
4
,
5
,
6
),
),
),
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
7
,
8
,
9
),
containerWithHostPorts
(
7
,
8
,
9
),
containerWithHostPorts
(
10
,
11
,
12
),
containerWithHostPorts
(
10
,
11
,
12
),
),
),
...
@@ -58,12 +58,12 @@ func TestAllowed(t *testing.T) {
...
@@ -58,12 +58,12 @@ func TestAllowed(t *testing.T) {
},
},
{
{
allowed
:
true
,
allowed
:
true
,
manifests
:
[]
api
.
ContainerManifest
{
pods
:
[]
api
.
BoundPod
{
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
),
),
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
),
),
...
@@ -71,19 +71,19 @@ func TestAllowed(t *testing.T) {
...
@@ -71,19 +71,19 @@ func TestAllowed(t *testing.T) {
},
},
{
{
allowed
:
false
,
allowed
:
false
,
manifests
:
[]
api
.
ContainerManifest
{
pods
:
[]
api
.
BoundPod
{
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
3
,
3
),
containerWithHostPorts
(
3
,
3
),
),
),
},
},
},
},
{
{
allowed
:
false
,
allowed
:
false
,
manifests
:
[]
api
.
ContainerManifest
{
pods
:
[]
api
.
BoundPod
{
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
6
),
containerWithHostPorts
(
6
),
),
),
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
6
),
containerWithHostPorts
(
6
),
),
),
},
},
...
@@ -91,8 +91,8 @@ func TestAllowed(t *testing.T) {
...
@@ -91,8 +91,8 @@ func TestAllowed(t *testing.T) {
}
}
for
_
,
item
:=
range
table
{
for
_
,
item
:=
range
table
{
if
e
,
a
:=
item
.
allowed
,
Allowed
(
item
.
manifest
s
);
e
!=
a
{
if
e
,
a
:=
item
.
allowed
,
Allowed
(
item
.
pod
s
);
e
!=
a
{
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
manifest
s
)
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
pod
s
)
}
}
}
}
}
}
pkg/constraint/ports.go
View file @
6ae611ae
...
@@ -22,10 +22,10 @@ import (
...
@@ -22,10 +22,10 @@ import (
// PortsConflict returns true iff two containers attempt to expose
// PortsConflict returns true iff two containers attempt to expose
// the same host port.
// the same host port.
func
PortsConflict
(
manifests
[]
api
.
ContainerManifest
)
bool
{
func
PortsConflict
(
pods
[]
api
.
BoundPod
)
bool
{
hostPorts
:=
map
[
int
]
struct
{}{}
hostPorts
:=
map
[
int
]
struct
{}{}
for
_
,
manifest
:=
range
manifest
s
{
for
_
,
pod
:=
range
pod
s
{
for
_
,
container
:=
range
manifest
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
port
:=
range
container
.
Ports
{
for
_
,
port
:=
range
container
.
Ports
{
if
port
.
HostPort
==
0
{
if
port
.
HostPort
==
0
{
continue
continue
...
...
pkg/master/master.go
View file @
6ae611ae
...
@@ -89,15 +89,15 @@ func NewEtcdHelper(client tools.EtcdGetSet, version string) (helper tools.EtcdHe
...
@@ -89,15 +89,15 @@ func NewEtcdHelper(client tools.EtcdGetSet, version string) (helper tools.EtcdHe
func
New
(
c
*
Config
)
*
Master
{
func
New
(
c
*
Config
)
*
Master
{
minionRegistry
:=
makeMinionRegistry
(
c
)
minionRegistry
:=
makeMinionRegistry
(
c
)
serviceRegistry
:=
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
)
serviceRegistry
:=
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
)
manifestFactory
:=
&
pod
.
BasicManifest
Factory
{
boundPodFactory
:=
&
pod
.
BasicBoundPod
Factory
{
ServiceRegistry
:
serviceRegistry
,
ServiceRegistry
:
serviceRegistry
,
}
}
m
:=
&
Master
{
m
:=
&
Master
{
podRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
manifest
Factory
),
podRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
boundPod
Factory
),
controllerRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
),
controllerRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
),
serviceRegistry
:
serviceRegistry
,
serviceRegistry
:
serviceRegistry
,
endpointRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
),
endpointRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
),
bindingRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
manifest
Factory
),
bindingRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
boundPod
Factory
),
eventRegistry
:
event
.
NewEtcdRegistry
(
c
.
EtcdHelper
,
uint64
(
c
.
EventTTL
.
Seconds
())),
eventRegistry
:
event
.
NewEtcdRegistry
(
c
.
EtcdHelper
,
uint64
(
c
.
EventTTL
.
Seconds
())),
minionRegistry
:
minionRegistry
,
minionRegistry
:
minionRegistry
,
client
:
c
.
Client
,
client
:
c
.
Client
,
...
...
pkg/registry/etcd/etcd.go
View file @
6ae611ae
...
@@ -51,15 +51,15 @@ const (
...
@@ -51,15 +51,15 @@ const (
// Registry implements PodRegistry, ControllerRegistry, ServiceRegistry and MinionRegistry, backed by etcd.
// Registry implements PodRegistry, ControllerRegistry, ServiceRegistry and MinionRegistry, backed by etcd.
type
Registry
struct
{
type
Registry
struct
{
tools
.
EtcdHelper
tools
.
EtcdHelper
manifestFactory
pod
.
Manifest
Factory
boundPodFactory
pod
.
BoundPod
Factory
}
}
// NewRegistry creates an etcd registry.
// NewRegistry creates an etcd registry.
func
NewRegistry
(
helper
tools
.
EtcdHelper
,
manifestFactory
pod
.
Manifest
Factory
)
*
Registry
{
func
NewRegistry
(
helper
tools
.
EtcdHelper
,
boundPodFactory
pod
.
BoundPod
Factory
)
*
Registry
{
registry
:=
&
Registry
{
registry
:=
&
Registry
{
EtcdHelper
:
helper
,
EtcdHelper
:
helper
,
}
}
registry
.
manifestFactory
=
manifest
Factory
registry
.
boundPodFactory
=
boundPod
Factory
return
registry
return
registry
}
}
...
@@ -230,18 +230,18 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
...
@@ -230,18 +230,18 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
return
err
return
err
}
}
// TODO: move this to a watch/rectification loop.
// TODO: move this to a watch/rectification loop.
manifest
,
err
:=
r
.
manifestFactory
.
MakeManifest
(
machine
,
*
finalPod
)
pod
,
err
:=
r
.
boundPodFactory
.
MakeBoundPod
(
machine
,
finalPod
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
contKey
:=
makeContainerKey
(
machine
)
contKey
:=
makeContainerKey
(
machine
)
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
ContainerManifestList
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
manifests
:=
*
in
.
(
*
api
.
ContainerManifestList
)
pods
:=
*
in
.
(
*
api
.
BoundPods
)
manifests
.
Items
=
append
(
manifests
.
Items
,
manifest
)
pods
.
Items
=
append
(
pods
.
Items
,
*
pod
)
if
!
constraint
.
Allowed
(
manifest
s
.
Items
)
{
if
!
constraint
.
Allowed
(
pod
s
.
Items
)
{
return
nil
,
fmt
.
Errorf
(
"The assignment would cause a constraint violation"
)
return
nil
,
fmt
.
Errorf
(
"The assignment would cause a constraint violation"
)
}
}
return
&
manifest
s
,
nil
return
&
pod
s
,
nil
})
})
if
err
!=
nil
{
if
err
!=
nil
{
// Put the pod's host back the way it was. This is a terrible hack that
// Put the pod's host back the way it was. This is a terrible hack that
...
@@ -321,13 +321,13 @@ func (r *Registry) DeletePod(ctx api.Context, podID string) error {
...
@@ -321,13 +321,13 @@ func (r *Registry) DeletePod(ctx api.Context, podID string) error {
}
}
// Next, remove the pod from the machine atomically.
// Next, remove the pod from the machine atomically.
contKey
:=
makeContainerKey
(
machine
)
contKey
:=
makeContainerKey
(
machine
)
return
r
.
AtomicUpdate
(
contKey
,
&
api
.
ContainerManifestList
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
manifests
:=
in
.
(
*
api
.
ContainerManifestList
)
pods
:=
in
.
(
*
api
.
BoundPods
)
new
Manifests
:=
make
([]
api
.
ContainerManifest
,
0
,
len
(
manifest
s
.
Items
))
new
Pods
:=
make
([]
api
.
BoundPod
,
0
,
len
(
pod
s
.
Items
))
found
:=
false
found
:=
false
for
_
,
manifest
:=
range
manifest
s
.
Items
{
for
_
,
pod
:=
range
pod
s
.
Items
{
if
manifest
.
ID
!=
podID
{
if
pod
.
ID
!=
podID
{
new
Manifests
=
append
(
newManifests
,
manifest
)
new
Pods
=
append
(
newPods
,
pod
)
}
else
{
}
else
{
found
=
true
found
=
true
}
}
...
@@ -336,10 +336,10 @@ func (r *Registry) DeletePod(ctx api.Context, podID string) error {
...
@@ -336,10 +336,10 @@ func (r *Registry) DeletePod(ctx api.Context, podID string) error {
// This really shouldn't happen, it indicates something is broken, and likely
// This really shouldn't happen, it indicates something is broken, and likely
// there is a lost pod somewhere.
// there is a lost pod somewhere.
// However it is "deleted" so log it and move on
// However it is "deleted" so log it and move on
glog
.
Warningf
(
"Couldn't find: %s in %#v"
,
podID
,
manifest
s
)
glog
.
Warningf
(
"Couldn't find: %s in %#v"
,
podID
,
pod
s
)
}
}
manifests
.
Items
=
newManifest
s
pods
.
Items
=
newPod
s
return
manifest
s
,
nil
return
pod
s
,
nil
})
})
}
}
...
...
pkg/registry/etcd/etcd_test.go
View file @
6ae611ae
...
@@ -36,7 +36,7 @@ import (
...
@@ -36,7 +36,7 @@ import (
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
Registry
{
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
Registry
{
registry
:=
NewRegistry
(
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
registry
:=
NewRegistry
(
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
&
pod
.
Basic
Manifest
Factory
{
&
pod
.
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registrytest
.
ServiceRegistry
{},
ServiceRegistry
:
&
registrytest
.
ServiceRegistry
{},
})
})
return
registry
return
registry
...
@@ -160,7 +160,7 @@ func TestEtcdCreatePod(t *testing.T) {
...
@@ -160,7 +160,7 @@ func TestEtcdCreatePod(t *testing.T) {
},
},
E
:
tools
.
EtcdErrorNotFound
,
E
:
tools
.
EtcdErrorNotFound
,
}
}
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{}),
0
)
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
err
:=
registry
.
CreatePod
(
ctx
,
&
api
.
Pod
{
err
:=
registry
.
CreatePod
(
ctx
,
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
TypeMeta
:
api
.
TypeMeta
{
...
@@ -199,15 +199,15 @@ func TestEtcdCreatePod(t *testing.T) {
...
@@ -199,15 +199,15 @@ func TestEtcdCreatePod(t *testing.T) {
if
pod
.
ID
!=
"foo"
{
if
pod
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
}
}
var
manifests
api
.
ContainerManifestList
var
boundPods
api
.
BoundPods
resp
,
err
=
fakeClient
.
Get
(
"/registry/hosts/machine/kubelet"
,
false
,
false
)
resp
,
err
=
fakeClient
.
Get
(
"/registry/hosts/machine/kubelet"
,
false
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
manifest
s
)
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
manifests
.
Items
)
!=
1
||
manifest
s
.
Items
[
0
]
.
ID
!=
"foo"
{
if
len
(
boundPods
.
Items
)
!=
1
||
boundPod
s
.
Items
[
0
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
manifest list: %#v"
,
manifest
s
)
t
.
Errorf
(
"Unexpected
boundPod list: %#v"
,
boundPod
s
)
}
}
}
}
...
@@ -355,15 +355,15 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
...
@@ -355,15 +355,15 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
if
pod
.
ID
!=
"foo"
{
if
pod
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
}
}
var
manifests
api
.
ContainerManifestList
var
boundPods
api
.
BoundPods
resp
,
err
=
fakeClient
.
Get
(
"/registry/hosts/machine/kubelet"
,
false
,
false
)
resp
,
err
=
fakeClient
.
Get
(
"/registry/hosts/machine/kubelet"
,
false
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
manifest
s
)
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
manifests
.
Items
)
!=
1
||
manifest
s
.
Items
[
0
]
.
ID
!=
"foo"
{
if
len
(
boundPods
.
Items
)
!=
1
||
boundPod
s
.
Items
[
0
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
manifest list: %#v"
,
manifest
s
)
t
.
Errorf
(
"Unexpected
boundPod list: %#v"
,
boundPod
s
)
}
}
}
}
...
@@ -378,9 +378,9 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
...
@@ -378,9 +378,9 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
},
},
E
:
tools
.
EtcdErrorNotFound
,
E
:
tools
.
EtcdErrorNotFound
,
}
}
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{
Items
:
[]
api
.
ContainerManifest
{
Items
:
[]
api
.
BoundPod
{
{
ID
:
"bar"
},
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"bar"
}
},
},
},
}),
0
)
}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
...
@@ -422,15 +422,15 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
...
@@ -422,15 +422,15 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
if
pod
.
ID
!=
"foo"
{
if
pod
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
}
}
var
manifests
api
.
ContainerManifestList
var
boundPods
api
.
BoundPods
resp
,
err
=
fakeClient
.
Get
(
"/registry/hosts/machine/kubelet"
,
false
,
false
)
resp
,
err
=
fakeClient
.
Get
(
"/registry/hosts/machine/kubelet"
,
false
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
manifest
s
)
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
manifests
.
Items
)
!=
2
||
manifest
s
.
Items
[
1
]
.
ID
!=
"foo"
{
if
len
(
boundPods
.
Items
)
!=
2
||
boundPod
s
.
Items
[
1
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
manifest list: %#v"
,
manifest
s
)
t
.
Errorf
(
"Unexpected
boundPod list: %#v"
,
boundPod
s
)
}
}
}
}
...
@@ -586,9 +586,9 @@ func TestEtcdDeletePod(t *testing.T) {
...
@@ -586,9 +586,9 @@ func TestEtcdDeletePod(t *testing.T) {
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
},
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
},
DesiredState
:
api
.
PodState
{
Host
:
"machine"
},
DesiredState
:
api
.
PodState
{
Host
:
"machine"
},
}),
0
)
}),
0
)
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{
Items
:
[]
api
.
ContainerManifest
{
Items
:
[]
api
.
BoundPod
{
{
ID
:
"foo"
},
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
}
},
},
},
}),
0
)
}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
...
@@ -606,9 +606,9 @@ func TestEtcdDeletePod(t *testing.T) {
...
@@ -606,9 +606,9 @@ func TestEtcdDeletePod(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
}
var
manifests
api
.
ContainerManifestList
var
boundPods
api
.
BoundPods
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
manifest
s
)
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
manifest
s
.
Items
)
!=
0
{
if
len
(
boundPod
s
.
Items
)
!=
0
{
t
.
Errorf
(
"Unexpected container set: %s, expected empty"
,
response
.
Node
.
Value
)
t
.
Errorf
(
"Unexpected container set: %s, expected empty"
,
response
.
Node
.
Value
)
}
}
}
}
...
@@ -622,10 +622,10 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
...
@@ -622,10 +622,10 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
},
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
},
DesiredState
:
api
.
PodState
{
Host
:
"machine"
},
DesiredState
:
api
.
PodState
{
Host
:
"machine"
},
}),
0
)
}),
0
)
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{
Items
:
[]
api
.
ContainerManifest
{
Items
:
[]
api
.
BoundPod
{
{
ID
:
"foo"
},
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
}
},
{
ID
:
"bar"
},
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"bar"
}
},
},
},
}),
0
)
}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
...
@@ -644,13 +644,13 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
...
@@ -644,13 +644,13 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
}
var
manifests
api
.
ContainerManifestList
var
boundPods
api
.
BoundPods
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
manifest
s
)
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
manifest
s
.
Items
)
!=
1
{
if
len
(
boundPod
s
.
Items
)
!=
1
{
t
.
Fatalf
(
"Unexpected
manifest set: %#v, expected empty"
,
manifest
s
)
t
.
Fatalf
(
"Unexpected
boundPod set: %#v, expected empty"
,
boundPod
s
)
}
}
if
manifest
s
.
Items
[
0
]
.
ID
!=
"bar"
{
if
boundPod
s
.
Items
[
0
]
.
ID
!=
"bar"
{
t
.
Errorf
(
"Deleted wrong
manifest: %#v"
,
manifest
s
)
t
.
Errorf
(
"Deleted wrong
boundPod: %#v"
,
boundPod
s
)
}
}
}
}
...
...
pkg/registry/pod/
manifest
_factory.go
→
pkg/registry/pod/
bound_pod
_factory.go
View file @
6ae611ae
...
@@ -21,24 +21,27 @@ import (
...
@@ -21,24 +21,27 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service"
)
)
type
Manifest
Factory
interface
{
type
BoundPod
Factory
interface
{
// Make a container object for a given pod, given the machine that the pod is running on.
// Make a container object for a given pod, given the machine that the pod is running on.
Make
Manifest
(
machine
string
,
pod
api
.
Pod
)
(
api
.
ContainerManifest
,
error
)
Make
BoundPod
(
machine
string
,
pod
*
api
.
Pod
)
(
*
api
.
BoundPod
,
error
)
}
}
type
Basic
Manifest
Factory
struct
{
type
Basic
BoundPod
Factory
struct
{
// TODO: this should really point at the API rather than a registry
// TODO: this should really point at the API rather than a registry
ServiceRegistry
service
.
Registry
ServiceRegistry
service
.
Registry
}
}
func
(
b
*
Basic
ManifestFactory
)
MakeManifest
(
machine
string
,
pod
api
.
Pod
)
(
api
.
ContainerManifest
,
error
)
{
func
(
b
*
Basic
BoundPodFactory
)
MakeBoundPod
(
machine
string
,
pod
*
api
.
Pod
)
(
*
api
.
BoundPod
,
error
)
{
envVars
,
err
:=
service
.
GetServiceEnvironmentVariables
(
api
.
NewContext
(),
b
.
ServiceRegistry
,
machine
)
envVars
,
err
:=
service
.
GetServiceEnvironmentVariables
(
api
.
NewContext
(),
b
.
ServiceRegistry
,
machine
)
if
err
!=
nil
{
if
err
!=
nil
{
return
api
.
ContainerManifest
{}
,
err
return
nil
,
err
}
}
for
ix
,
container
:=
range
pod
.
DesiredState
.
Manifest
.
Containers
{
boundPod
:=
&
api
.
BoundPod
{}
pod
.
DesiredState
.
Manifest
.
ID
=
pod
.
ID
if
err
:=
api
.
Scheme
.
Convert
(
pod
,
boundPod
);
err
!=
nil
{
pod
.
DesiredState
.
Manifest
.
Containers
[
ix
]
.
Env
=
append
(
container
.
Env
,
envVars
...
)
return
nil
,
err
}
}
return
pod
.
DesiredState
.
Manifest
,
nil
for
ix
,
container
:=
range
boundPod
.
Spec
.
Containers
{
boundPod
.
Spec
.
Containers
[
ix
]
.
Env
=
append
(
container
.
Env
,
envVars
...
)
}
return
boundPod
,
nil
}
}
pkg/registry/pod/
manifest
_factory_test.go
→
pkg/registry/pod/
bound_pod
_factory_test.go
View file @
6ae611ae
...
@@ -25,13 +25,13 @@ import (
...
@@ -25,13 +25,13 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
)
func
TestMake
Manifest
NoServices
(
t
*
testing
.
T
)
{
func
TestMake
BoundPod
NoServices
(
t
*
testing
.
T
)
{
registry
:=
registrytest
.
ServiceRegistry
{}
registry
:=
registrytest
.
ServiceRegistry
{}
factory
:=
&
Basic
Manifest
Factory
{
factory
:=
&
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registry
,
ServiceRegistry
:
&
registry
,
}
}
manifest
,
err
:=
factory
.
MakeManifest
(
"machine"
,
api
.
Pod
{
pod
,
err
:=
factory
.
MakeBoundPod
(
"machine"
,
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foobar"
},
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foobar"
},
DesiredState
:
api
.
PodState
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Manifest
:
api
.
ContainerManifest
{
...
@@ -44,19 +44,19 @@ func TestMakeManifestNoServices(t *testing.T) {
...
@@ -44,19 +44,19 @@ func TestMakeManifestNoServices(t *testing.T) {
},
},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"unexpected error: %v"
,
err
)
t
.
Fatal
f
(
"unexpected error: %v"
,
err
)
}
}
container
:=
manifest
.
Containers
[
0
]
container
:=
pod
.
Spec
.
Containers
[
0
]
if
len
(
container
.
Env
)
!=
0
{
if
len
(
container
.
Env
)
!=
0
{
t
.
Errorf
(
"Expected zero env vars, got: %#v"
,
manifest
)
t
.
Errorf
(
"Expected zero env vars, got: %#v"
,
pod
)
}
}
if
manifest
.
ID
!=
"foobar"
{
if
pod
.
ID
!=
"foobar"
{
t
.
Errorf
(
"Failed to assign ID to
manifest: %#v"
,
manifest
.
ID
)
t
.
Errorf
(
"Failed to assign ID to
pod: %#v"
,
pod
.
ID
)
}
}
}
}
func
TestMake
Manifest
Services
(
t
*
testing
.
T
)
{
func
TestMake
BoundPod
Services
(
t
*
testing
.
T
)
{
registry
:=
registrytest
.
ServiceRegistry
{
registry
:=
registrytest
.
ServiceRegistry
{
List
:
api
.
ServiceList
{
List
:
api
.
ServiceList
{
Items
:
[]
api
.
Service
{
Items
:
[]
api
.
Service
{
...
@@ -72,11 +72,11 @@ func TestMakeManifestServices(t *testing.T) {
...
@@ -72,11 +72,11 @@ func TestMakeManifestServices(t *testing.T) {
},
},
},
},
}
}
factory
:=
&
Basic
Manifest
Factory
{
factory
:=
&
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registry
,
ServiceRegistry
:
&
registry
,
}
}
manifest
,
err
:=
factory
.
MakeManifest
(
"machine"
,
api
.
Pod
{
pod
,
err
:=
factory
.
MakeBoundPod
(
"machine"
,
&
api
.
Pod
{
DesiredState
:
api
.
PodState
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
...
@@ -88,10 +88,10 @@ func TestMakeManifestServices(t *testing.T) {
...
@@ -88,10 +88,10 @@ func TestMakeManifestServices(t *testing.T) {
},
},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"unexpected error: %v"
,
err
)
t
.
Fatal
f
(
"unexpected error: %v"
,
err
)
}
}
container
:=
manifest
.
Containers
[
0
]
container
:=
pod
.
Spec
.
Containers
[
0
]
envs
:=
[]
api
.
EnvVar
{
envs
:=
[]
api
.
EnvVar
{
{
{
Name
:
"TEST_SERVICE_HOST"
,
Name
:
"TEST_SERVICE_HOST"
,
...
@@ -123,8 +123,7 @@ func TestMakeManifestServices(t *testing.T) {
...
@@ -123,8 +123,7 @@ func TestMakeManifestServices(t *testing.T) {
},
},
}
}
if
len
(
container
.
Env
)
!=
len
(
envs
)
{
if
len
(
container
.
Env
)
!=
len
(
envs
)
{
t
.
Errorf
(
"Expected %d env vars, got %d: %#v"
,
len
(
envs
),
len
(
container
.
Env
),
manifest
)
t
.
Fatalf
(
"Expected %d env vars, got %d: %#v"
,
len
(
envs
),
len
(
container
.
Env
),
pod
)
return
}
}
for
ix
:=
range
container
.
Env
{
for
ix
:=
range
container
.
Env
{
if
!
reflect
.
DeepEqual
(
envs
[
ix
],
container
.
Env
[
ix
])
{
if
!
reflect
.
DeepEqual
(
envs
[
ix
],
container
.
Env
[
ix
])
{
...
@@ -133,7 +132,7 @@ func TestMakeManifestServices(t *testing.T) {
...
@@ -133,7 +132,7 @@ func TestMakeManifestServices(t *testing.T) {
}
}
}
}
func
TestMake
Manifest
ServicesExistingEnvVar
(
t
*
testing
.
T
)
{
func
TestMake
BoundPod
ServicesExistingEnvVar
(
t
*
testing
.
T
)
{
registry
:=
registrytest
.
ServiceRegistry
{
registry
:=
registrytest
.
ServiceRegistry
{
List
:
api
.
ServiceList
{
List
:
api
.
ServiceList
{
Items
:
[]
api
.
Service
{
Items
:
[]
api
.
Service
{
...
@@ -149,11 +148,11 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
...
@@ -149,11 +148,11 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
},
},
},
},
}
}
factory
:=
&
Basic
Manifest
Factory
{
factory
:=
&
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registry
,
ServiceRegistry
:
&
registry
,
}
}
manifest
,
err
:=
factory
.
MakeManifest
(
"machine"
,
api
.
Pod
{
pod
,
err
:=
factory
.
MakeBoundPod
(
"machine"
,
&
api
.
Pod
{
DesiredState
:
api
.
PodState
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
...
@@ -170,10 +169,10 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
...
@@ -170,10 +169,10 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
},
},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"unexpected error: %v"
,
err
)
t
.
Fatal
f
(
"unexpected error: %v"
,
err
)
}
}
container
:=
manifest
.
Containers
[
0
]
container
:=
pod
.
Spec
.
Containers
[
0
]
envs
:=
[]
api
.
EnvVar
{
envs
:=
[]
api
.
EnvVar
{
{
{
...
@@ -210,8 +209,7 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
...
@@ -210,8 +209,7 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
},
},
}
}
if
len
(
container
.
Env
)
!=
len
(
envs
)
{
if
len
(
container
.
Env
)
!=
len
(
envs
)
{
t
.
Errorf
(
"Expected %d env vars, got: %#v"
,
len
(
envs
),
manifest
)
t
.
Fatalf
(
"Expected %d env vars, got: %#v"
,
len
(
envs
),
pod
)
return
}
}
for
ix
:=
range
container
.
Env
{
for
ix
:=
range
container
.
Env
{
if
!
reflect
.
DeepEqual
(
envs
[
ix
],
container
.
Env
[
ix
])
{
if
!
reflect
.
DeepEqual
(
envs
[
ix
],
container
.
Env
[
ix
])
{
...
...
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