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
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
131 additions
and
113 deletions
+131
-113
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
+18
-18
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() {
}
out
.
ResourceVersion
=
in
.
ResourceVersion
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 (
)
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
etcdregistry
.
Registry
{
registry
:=
etcdregistry
.
NewRegistry
(
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
&
pod
.
BasicManifestFactory
{
registry
:=
etcdregistry
.
NewRegistry
(
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
&
pod
.
BasicBoundPodFactory
{
ServiceRegistry
:
&
registrytest
.
ServiceRegistry
{},
})
},
)
return
registry
}
...
...
pkg/constraint/constraint.go
View file @
6ae611ae
...
...
@@ -20,8 +20,8 @@ import (
"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.
func
Allowed
(
manifests
[]
api
.
ContainerManifest
)
bool
{
return
!
PortsConflict
(
manifest
s
)
func
Allowed
(
pods
[]
api
.
BoundPod
)
bool
{
return
!
PortsConflict
(
pod
s
)
}
pkg/constraint/constraint_test.go
View file @
6ae611ae
...
...
@@ -30,27 +30,27 @@ func containerWithHostPorts(ports ...int) api.Container {
return
c
}
func
manifestWithContainers
(
containers
...
api
.
Container
)
api
.
ContainerManifest
{
m
:=
api
.
ContainerManifest
{}
func
podWithContainers
(
containers
...
api
.
Container
)
api
.
BoundPod
{
m
:=
api
.
BoundPod
{}
for
_
,
c
:=
range
containers
{
m
.
Containers
=
append
(
m
.
Containers
,
c
)
m
.
Spec
.
Containers
=
append
(
m
.
Spec
.
Containers
,
c
)
}
return
m
}
func
TestAllowed
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
allowed
bool
manifests
[]
api
.
ContainerManifest
allowed
bool
pods
[]
api
.
BoundPod
}{
{
allowed
:
true
,
manifests
:
[]
api
.
ContainerManifest
{
manifest
WithContainers
(
pods
:
[]
api
.
BoundPod
{
pod
WithContainers
(
containerWithHostPorts
(
1
,
2
,
3
),
containerWithHostPorts
(
4
,
5
,
6
),
),
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
7
,
8
,
9
),
containerWithHostPorts
(
10
,
11
,
12
),
),
...
...
@@ -58,12 +58,12 @@ func TestAllowed(t *testing.T) {
},
{
allowed
:
true
,
manifests
:
[]
api
.
ContainerManifest
{
manifest
WithContainers
(
pods
:
[]
api
.
BoundPod
{
pod
WithContainers
(
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
),
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
),
...
...
@@ -71,19 +71,19 @@ func TestAllowed(t *testing.T) {
},
{
allowed
:
false
,
manifests
:
[]
api
.
ContainerManifest
{
manifest
WithContainers
(
pods
:
[]
api
.
BoundPod
{
pod
WithContainers
(
containerWithHostPorts
(
3
,
3
),
),
},
},
{
allowed
:
false
,
manifests
:
[]
api
.
ContainerManifest
{
manifest
WithContainers
(
pods
:
[]
api
.
BoundPod
{
pod
WithContainers
(
containerWithHostPorts
(
6
),
),
manifest
WithContainers
(
pod
WithContainers
(
containerWithHostPorts
(
6
),
),
},
...
...
@@ -91,8 +91,8 @@ func TestAllowed(t *testing.T) {
}
for
_
,
item
:=
range
table
{
if
e
,
a
:=
item
.
allowed
,
Allowed
(
item
.
manifest
s
);
e
!=
a
{
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
manifest
s
)
if
e
,
a
:=
item
.
allowed
,
Allowed
(
item
.
pod
s
);
e
!=
a
{
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 (
// PortsConflict returns true iff two containers attempt to expose
// the same host port.
func
PortsConflict
(
manifests
[]
api
.
ContainerManifest
)
bool
{
func
PortsConflict
(
pods
[]
api
.
BoundPod
)
bool
{
hostPorts
:=
map
[
int
]
struct
{}{}
for
_
,
manifest
:=
range
manifest
s
{
for
_
,
container
:=
range
manifest
.
Containers
{
for
_
,
pod
:=
range
pod
s
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
port
:=
range
container
.
Ports
{
if
port
.
HostPort
==
0
{
continue
...
...
pkg/master/master.go
View file @
6ae611ae
...
...
@@ -89,15 +89,15 @@ func NewEtcdHelper(client tools.EtcdGetSet, version string) (helper tools.EtcdHe
func
New
(
c
*
Config
)
*
Master
{
minionRegistry
:=
makeMinionRegistry
(
c
)
serviceRegistry
:=
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
)
manifestFactory
:=
&
pod
.
BasicManifest
Factory
{
boundPodFactory
:=
&
pod
.
BasicBoundPod
Factory
{
ServiceRegistry
:
serviceRegistry
,
}
m
:=
&
Master
{
podRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
manifest
Factory
),
podRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
boundPod
Factory
),
controllerRegistry
:
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
nil
),
serviceRegistry
:
serviceRegistry
,
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
())),
minionRegistry
:
minionRegistry
,
client
:
c
.
Client
,
...
...
pkg/registry/etcd/etcd.go
View file @
6ae611ae
...
...
@@ -51,15 +51,15 @@ const (
// Registry implements PodRegistry, ControllerRegistry, ServiceRegistry and MinionRegistry, backed by etcd.
type
Registry
struct
{
tools
.
EtcdHelper
manifestFactory
pod
.
Manifest
Factory
boundPodFactory
pod
.
BoundPod
Factory
}
// 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
{
EtcdHelper
:
helper
,
}
registry
.
manifestFactory
=
manifest
Factory
registry
.
boundPodFactory
=
boundPod
Factory
return
registry
}
...
...
@@ -230,18 +230,18 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
return
err
}
// 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
{
return
err
}
contKey
:=
makeContainerKey
(
machine
)
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
ContainerManifestList
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
manifests
:=
*
in
.
(
*
api
.
ContainerManifestList
)
manifests
.
Items
=
append
(
manifests
.
Items
,
manifest
)
if
!
constraint
.
Allowed
(
manifest
s
.
Items
)
{
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
pods
:=
*
in
.
(
*
api
.
BoundPods
)
pods
.
Items
=
append
(
pods
.
Items
,
*
pod
)
if
!
constraint
.
Allowed
(
pod
s
.
Items
)
{
return
nil
,
fmt
.
Errorf
(
"The assignment would cause a constraint violation"
)
}
return
&
manifest
s
,
nil
return
&
pod
s
,
nil
})
if
err
!=
nil
{
// 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 {
}
// Next, remove the pod from the machine atomically.
contKey
:=
makeContainerKey
(
machine
)
return
r
.
AtomicUpdate
(
contKey
,
&
api
.
ContainerManifestList
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
manifests
:=
in
.
(
*
api
.
ContainerManifestList
)
new
Manifests
:=
make
([]
api
.
ContainerManifest
,
0
,
len
(
manifest
s
.
Items
))
return
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
pods
:=
in
.
(
*
api
.
BoundPods
)
new
Pods
:=
make
([]
api
.
BoundPod
,
0
,
len
(
pod
s
.
Items
))
found
:=
false
for
_
,
manifest
:=
range
manifest
s
.
Items
{
if
manifest
.
ID
!=
podID
{
new
Manifests
=
append
(
newManifests
,
manifest
)
for
_
,
pod
:=
range
pod
s
.
Items
{
if
pod
.
ID
!=
podID
{
new
Pods
=
append
(
newPods
,
pod
)
}
else
{
found
=
true
}
...
...
@@ -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
// there is a lost pod somewhere.
// 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
return
manifest
s
,
nil
pods
.
Items
=
newPod
s
return
pod
s
,
nil
})
}
...
...
pkg/registry/etcd/etcd_test.go
View file @
6ae611ae
...
...
@@ -36,7 +36,7 @@ import (
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
Registry
{
registry
:=
NewRegistry
(
tools
.
EtcdHelper
{
client
,
latest
.
Codec
,
tools
.
RuntimeVersionAdapter
{
latest
.
ResourceVersioner
}},
&
pod
.
Basic
Manifest
Factory
{
&
pod
.
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registrytest
.
ServiceRegistry
{},
})
return
registry
...
...
@@ -160,7 +160,7 @@ func TestEtcdCreatePod(t *testing.T) {
},
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
)
err
:=
registry
.
CreatePod
(
ctx
,
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
...
...
@@ -199,15 +199,15 @@ func TestEtcdCreatePod(t *testing.T) {
if
pod
.
ID
!=
"foo"
{
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
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
manifest
s
)
if
len
(
manifests
.
Items
)
!=
1
||
manifest
s
.
Items
[
0
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
manifest list: %#v"
,
manifest
s
)
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
boundPods
.
Items
)
!=
1
||
boundPod
s
.
Items
[
0
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
boundPod list: %#v"
,
boundPod
s
)
}
}
...
...
@@ -355,15 +355,15 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
if
pod
.
ID
!=
"foo"
{
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
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
manifest
s
)
if
len
(
manifests
.
Items
)
!=
1
||
manifest
s
.
Items
[
0
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
manifest list: %#v"
,
manifest
s
)
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
boundPods
.
Items
)
!=
1
||
boundPod
s
.
Items
[
0
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
boundPod list: %#v"
,
boundPod
s
)
}
}
...
...
@@ -378,9 +378,9 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
},
E
:
tools
.
EtcdErrorNotFound
,
}
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{
Items
:
[]
api
.
ContainerManifest
{
{
ID
:
"bar"
},
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{
Items
:
[]
api
.
BoundPod
{
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"bar"
}
},
},
}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
...
...
@@ -422,15 +422,15 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
if
pod
.
ID
!=
"foo"
{
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
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
manifest
s
)
if
len
(
manifests
.
Items
)
!=
2
||
manifest
s
.
Items
[
1
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
manifest list: %#v"
,
manifest
s
)
err
=
latest
.
Codec
.
DecodeInto
([]
byte
(
resp
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
boundPods
.
Items
)
!=
2
||
boundPod
s
.
Items
[
1
]
.
ID
!=
"foo"
{
t
.
Errorf
(
"Unexpected
boundPod list: %#v"
,
boundPod
s
)
}
}
...
...
@@ -586,9 +586,9 @@ func TestEtcdDeletePod(t *testing.T) {
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
},
DesiredState
:
api
.
PodState
{
Host
:
"machine"
},
}),
0
)
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{
Items
:
[]
api
.
ContainerManifest
{
{
ID
:
"foo"
},
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{
Items
:
[]
api
.
BoundPod
{
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
}
},
},
}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
...
...
@@ -606,9 +606,9 @@ func TestEtcdDeletePod(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
var
manifests
api
.
ContainerManifestList
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
manifest
s
)
if
len
(
manifest
s
.
Items
)
!=
0
{
var
boundPods
api
.
BoundPods
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
boundPod
s
.
Items
)
!=
0
{
t
.
Errorf
(
"Unexpected container set: %s, expected empty"
,
response
.
Node
.
Value
)
}
}
...
...
@@ -622,10 +622,10 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
},
DesiredState
:
api
.
PodState
{
Host
:
"machine"
},
}),
0
)
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
ContainerManifestList
{
Items
:
[]
api
.
ContainerManifest
{
{
ID
:
"foo"
},
{
ID
:
"bar"
},
fakeClient
.
Set
(
"/registry/hosts/machine/kubelet"
,
runtime
.
EncodeOrDie
(
latest
.
Codec
,
&
api
.
BoundPods
{
Items
:
[]
api
.
BoundPod
{
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
}
},
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"bar"
}
},
},
}),
0
)
registry
:=
NewTestEtcdRegistry
(
fakeClient
)
...
...
@@ -644,13 +644,13 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
var
manifests
api
.
ContainerManifestList
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
manifest
s
)
if
len
(
manifest
s
.
Items
)
!=
1
{
t
.
Fatalf
(
"Unexpected
manifest set: %#v, expected empty"
,
manifest
s
)
var
boundPods
api
.
BoundPods
latest
.
Codec
.
DecodeInto
([]
byte
(
response
.
Node
.
Value
),
&
boundPod
s
)
if
len
(
boundPod
s
.
Items
)
!=
1
{
t
.
Fatalf
(
"Unexpected
boundPod set: %#v, expected empty"
,
boundPod
s
)
}
if
manifest
s
.
Items
[
0
]
.
ID
!=
"bar"
{
t
.
Errorf
(
"Deleted wrong
manifest: %#v"
,
manifest
s
)
if
boundPod
s
.
Items
[
0
]
.
ID
!=
"bar"
{
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 (
"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
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
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
)
if
err
!=
nil
{
return
api
.
ContainerManifest
{}
,
err
return
nil
,
err
}
for
ix
,
container
:=
range
pod
.
DesiredState
.
Manifest
.
Containers
{
pod
.
DesiredState
.
Manifest
.
ID
=
pod
.
ID
pod
.
DesiredState
.
Manifest
.
Containers
[
ix
]
.
Env
=
append
(
container
.
Env
,
envVars
...
)
boundPod
:=
&
api
.
BoundPod
{}
if
err
:=
api
.
Scheme
.
Convert
(
pod
,
boundPod
);
err
!=
nil
{
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 (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
func
TestMake
Manifest
NoServices
(
t
*
testing
.
T
)
{
func
TestMake
BoundPod
NoServices
(
t
*
testing
.
T
)
{
registry
:=
registrytest
.
ServiceRegistry
{}
factory
:=
&
Basic
Manifest
Factory
{
factory
:=
&
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registry
,
}
manifest
,
err
:=
factory
.
MakeManifest
(
"machine"
,
api
.
Pod
{
pod
,
err
:=
factory
.
MakeBoundPod
(
"machine"
,
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foobar"
},
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
...
...
@@ -44,19 +44,19 @@ func TestMakeManifestNoServices(t *testing.T) {
},
})
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
{
t
.
Errorf
(
"Expected zero env vars, got: %#v"
,
manifest
)
t
.
Errorf
(
"Expected zero env vars, got: %#v"
,
pod
)
}
if
manifest
.
ID
!=
"foobar"
{
t
.
Errorf
(
"Failed to assign ID to
manifest: %#v"
,
manifest
.
ID
)
if
pod
.
ID
!=
"foobar"
{
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
{
List
:
api
.
ServiceList
{
Items
:
[]
api
.
Service
{
...
...
@@ -72,11 +72,11 @@ func TestMakeManifestServices(t *testing.T) {
},
},
}
factory
:=
&
Basic
Manifest
Factory
{
factory
:=
&
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registry
,
}
manifest
,
err
:=
factory
.
MakeManifest
(
"machine"
,
api
.
Pod
{
pod
,
err
:=
factory
.
MakeBoundPod
(
"machine"
,
&
api
.
Pod
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
...
...
@@ -88,10 +88,10 @@ func TestMakeManifestServices(t *testing.T) {
},
})
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
{
{
Name
:
"TEST_SERVICE_HOST"
,
...
...
@@ -123,8 +123,7 @@ func TestMakeManifestServices(t *testing.T) {
},
}
if
len
(
container
.
Env
)
!=
len
(
envs
)
{
t
.
Errorf
(
"Expected %d env vars, got %d: %#v"
,
len
(
envs
),
len
(
container
.
Env
),
manifest
)
return
t
.
Fatalf
(
"Expected %d env vars, got %d: %#v"
,
len
(
envs
),
len
(
container
.
Env
),
pod
)
}
for
ix
:=
range
container
.
Env
{
if
!
reflect
.
DeepEqual
(
envs
[
ix
],
container
.
Env
[
ix
])
{
...
...
@@ -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
{
List
:
api
.
ServiceList
{
Items
:
[]
api
.
Service
{
...
...
@@ -149,11 +148,11 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
},
},
}
factory
:=
&
Basic
Manifest
Factory
{
factory
:=
&
Basic
BoundPod
Factory
{
ServiceRegistry
:
&
registry
,
}
manifest
,
err
:=
factory
.
MakeManifest
(
"machine"
,
api
.
Pod
{
pod
,
err
:=
factory
.
MakeBoundPod
(
"machine"
,
&
api
.
Pod
{
DesiredState
:
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
Containers
:
[]
api
.
Container
{
...
...
@@ -170,10 +169,10 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
},
})
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
{
{
...
...
@@ -210,8 +209,7 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
},
}
if
len
(
container
.
Env
)
!=
len
(
envs
)
{
t
.
Errorf
(
"Expected %d env vars, got: %#v"
,
len
(
envs
),
manifest
)
return
t
.
Fatalf
(
"Expected %d env vars, got: %#v"
,
len
(
envs
),
pod
)
}
for
ix
:=
range
container
.
Env
{
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