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
bdc1981e
Commit
bdc1981e
authored
Mar 16, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5433 from wojtek-t/remove_bound_pods
Remove BoundPods from Kubelet
parents
69ce2b0a
5d95e9e6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
193 additions
and
224 deletions
+193
-224
conversion.go
pkg/api/conversion.go
+6
-10
register.go
pkg/api/register.go
+0
-2
types.go
pkg/api/types.go
+4
-15
types.go
pkg/api/v1beta1/types.go
+1
-1
types.go
pkg/api/v1beta2/types.go
+1
-1
types.go
pkg/api/v1beta3/types.go
+1
-1
apiserver.go
pkg/kubelet/config/apiserver.go
+5
-11
apiserver_test.go
pkg/kubelet/config/apiserver_test.go
+12
-12
config.go
pkg/kubelet/config/config.go
+12
-12
config_test.go
pkg/kubelet/config/config_test.go
+7
-7
file.go
pkg/kubelet/config/file.go
+9
-9
file_test.go
pkg/kubelet/config/file_test.go
+7
-7
http.go
pkg/kubelet/config/http.go
+8
-8
http_test.go
pkg/kubelet/config/http_test.go
+10
-10
kubelet.go
pkg/kubelet/kubelet.go
+33
-33
kubelet_test.go
pkg/kubelet/kubelet_test.go
+38
-46
pod_workers.go
pkg/kubelet/pod_workers.go
+3
-3
pod_workers_test.go
pkg/kubelet/pod_workers_test.go
+3
-3
probe.go
pkg/kubelet/probe.go
+6
-6
probe_test.go
pkg/kubelet/probe_test.go
+1
-1
runonce.go
pkg/kubelet/runonce.go
+4
-4
runonce_test.go
pkg/kubelet/runonce_test.go
+1
-1
server.go
pkg/kubelet/server.go
+8
-8
server_test.go
pkg/kubelet/server_test.go
+9
-9
types.go
pkg/kubelet/types.go
+2
-2
volumes.go
pkg/kubelet/volumes.go
+1
-1
events.go
test/e2e/events.go
+1
-1
No files found.
pkg/api/conversion.go
View file @
bdc1981e
...
...
@@ -39,12 +39,8 @@ func init() {
*
out
=
*
in
.
Copy
()
return
nil
},
// Convert ContainerManifest to BoundPod
//
// This function generates a dummy selfLink using the same method as the
// boundPod registry, in order for the Kubelet to work with well-formed
// boundPods during the integration test.
func
(
in
*
ContainerManifest
,
out
*
BoundPod
,
s
conversion
.
Scope
)
error
{
// Convert ContainerManifest to Pod
func
(
in
*
ContainerManifest
,
out
*
Pod
,
s
conversion
.
Scope
)
error
{
out
.
Spec
.
Containers
=
in
.
Containers
out
.
Spec
.
Volumes
=
in
.
Volumes
out
.
Spec
.
RestartPolicy
=
in
.
RestartPolicy
...
...
@@ -53,12 +49,12 @@ func init() {
out
.
UID
=
in
.
UUID
if
in
.
ID
!=
""
{
out
.
SelfLink
=
"/api/v1beta1/
boundP
ods/"
+
in
.
ID
out
.
SelfLink
=
"/api/v1beta1/
p
ods/"
+
in
.
ID
}
return
nil
},
func
(
in
*
Bound
Pod
,
out
*
ContainerManifest
,
s
conversion
.
Scope
)
error
{
func
(
in
*
Pod
,
out
*
ContainerManifest
,
s
conversion
.
Scope
)
error
{
out
.
Containers
=
in
.
Spec
.
Containers
out
.
Volumes
=
in
.
Spec
.
Volumes
out
.
RestartPolicy
=
in
.
Spec
.
RestartPolicy
...
...
@@ -70,7 +66,7 @@ func init() {
},
// ContainerManifestList
func
(
in
*
ContainerManifestList
,
out
*
BoundPods
,
s
conversion
.
Scope
)
error
{
func
(
in
*
ContainerManifestList
,
out
*
PodList
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
Items
,
&
out
.
Items
,
0
);
err
!=
nil
{
return
err
}
...
...
@@ -80,7 +76,7 @@ func init() {
}
return
nil
},
func
(
in
*
BoundPods
,
out
*
ContainerManifestList
,
s
conversion
.
Scope
)
error
{
func
(
in
*
PodList
,
out
*
ContainerManifestList
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
Items
,
&
out
.
Items
,
0
);
err
!=
nil
{
return
err
}
...
...
pkg/api/register.go
View file @
bdc1981e
...
...
@@ -44,7 +44,6 @@ func init() {
&
ContainerManifest
{},
&
ContainerManifestList
{},
&
BoundPod
{},
&
BoundPods
{},
&
List
{},
&
LimitRange
{},
&
LimitRangeList
{},
...
...
@@ -79,7 +78,6 @@ func (*EventList) IsAnAPIObject() {}
func
(
*
ContainerManifest
)
IsAnAPIObject
()
{}
func
(
*
ContainerManifestList
)
IsAnAPIObject
()
{}
func
(
*
BoundPod
)
IsAnAPIObject
()
{}
func
(
*
BoundPods
)
IsAnAPIObject
()
{}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
...
...
pkg/api/types.go
View file @
bdc1981e
...
...
@@ -1243,7 +1243,7 @@ type EventList struct {
// ContainerManifest corresponds to the Container Manifest format, documented at:
// https://developers.google.com/compute/docs/containers/container_vms#container_manifest
// This is used as the representation of Kubernetes workloads.
// DEPRECATED: Replaced with
Bound
Pod
// DEPRECATED: Replaced with Pod
type
ContainerManifest
struct
{
// Required: This must be a supported version string, such as "v1beta1".
Version
string
`json:"version"`
...
...
@@ -1262,7 +1262,7 @@ type ContainerManifest struct {
}
// ContainerManifestList is used to communicate container manifests to kubelet.
// DEPRECATED: Replaced with
Bound
Pods
// DEPRECATED: Replaced with Pods
type
ContainerManifestList
struct
{
TypeMeta
`json:",inline"`
ListMeta
`json:"metadata,omitempty"`
...
...
@@ -1273,6 +1273,8 @@ type ContainerManifestList struct {
// BoundPod is a collection of containers that should be run on a host. A BoundPod
// defines how a Pod may change after a Binding is created. A Pod is a request to
// execute a pod, whereas a BoundPod is the specification that would be run on a server.
//
// TODO(wojtek-t): Get rid of this type.
type
BoundPod
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
...
...
@@ -1281,19 +1283,6 @@ type BoundPod struct {
Spec
PodSpec
`json:"spec,omitempty"`
}
// BoundPods is a list of Pods bound to a common server. The resource version of
// the pod list is guaranteed to only change when the list of bound pods changes.
type
BoundPods
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
// Host is the name of a node that these pods were bound to.
Host
string
`json:"host"`
// Items is the list of all pods bound to a given host.
Items
[]
BoundPod
`json:"items"`
}
// List holds a list of objects, which may not be known by the server.
type
List
struct
{
TypeMeta
`json:",inline"`
...
...
pkg/api/v1beta1/types.go
View file @
bdc1981e
...
...
@@ -1079,7 +1079,7 @@ type BoundPods struct {
Host
string
`json:"host" description:"name of a node that these pods were bound to"`
// Items is the list of all pods bound to a given host.
Items
[]
Bound
Pod
`json:"items" description:"list of all pods bound to a given host"`
Items
[]
Pod
`json:"items" description:"list of all pods bound to a given host"`
}
// List holds a list of objects, which may not be known by the server.
...
...
pkg/api/v1beta2/types.go
View file @
bdc1981e
...
...
@@ -1141,7 +1141,7 @@ type BoundPods struct {
Host
string
`json:"host" description:"name of a node that these pods were bound to"`
// Items is the list of all pods bound to a given host.
Items
[]
Bound
Pod
`json:"items" description:"list of all pods bound to a given host"`
Items
[]
Pod
`json:"items" description:"list of all pods bound to a given host"`
}
// List holds a list of objects, which may not be known by the server.
...
...
pkg/api/v1beta3/types.go
View file @
bdc1981e
...
...
@@ -666,7 +666,7 @@ type BoundPods struct {
Host
string
`json:"host" description:"name of a node that these pods were bound to"`
// Items is the list of all pods bound to a given host.
Items
[]
Bound
Pod
`json:"items" description:"list of all pods bound to a given host"`
Items
[]
Pod
`json:"items" description:"list of all pods bound to a given host"`
}
// ReplicationControllerSpec is the specification of a replication controller.
...
...
pkg/kubelet/config/apiserver.go
View file @
bdc1981e
...
...
@@ -23,7 +23,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/golang/glog"
)
// NewSourceApiserver creates a config source that watches and pulls from the apiserver.
...
...
@@ -35,19 +34,14 @@ func NewSourceApiserver(client *client.Client, hostname string, updates chan<- i
// newSourceApiserverFromLW holds creates a config source that watches an pulls from the apiserver.
func
newSourceApiserverFromLW
(
lw
cache
.
ListerWatcher
,
updates
chan
<-
interface
{})
{
send
:=
func
(
objs
[]
interface
{})
{
var
bpods
[]
api
.
Bound
Pod
var
pods
[]
api
.
Pod
for
_
,
o
:=
range
objs
{
pod
:=
o
.
(
*
api
.
Pod
)
bpod
:=
api
.
BoundPod
{}
if
err
:=
api
.
Scheme
.
Convert
(
pod
,
&
bpod
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to interpret Pod from apiserver as a BoundPod: %v: %+v"
,
err
,
pod
)
continue
}
// Make a dummy self link so that references to this bound pod will work.
bpod
.
SelfLink
=
"/api/v1beta1/boundPods/"
+
bpod
.
Name
bpods
=
append
(
bpods
,
bpod
)
// Make a dummy self link so that references to this pod will work.
pod
.
SelfLink
=
"/api/v1beta1/pods/"
+
pod
.
Name
pods
=
append
(
pods
,
*
pod
)
}
updates
<-
kubelet
.
PodUpdate
{
b
pods
,
kubelet
.
SET
,
kubelet
.
ApiserverSource
}
updates
<-
kubelet
.
PodUpdate
{
pods
,
kubelet
.
SET
,
kubelet
.
ApiserverSource
}
}
cache
.
NewReflector
(
lw
,
&
api
.
Pod
{},
cache
.
NewUndeltaStore
(
send
,
cache
.
MetaNamespaceKeyFunc
),
0
)
.
Run
()
}
...
...
pkg/kubelet/config/apiserver_test.go
View file @
bdc1981e
...
...
@@ -54,14 +54,14 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"q"
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Image
:
"image/blah"
}}}}
expected
BoundPod1v1
:=
api
.
Bound
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"p"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/p"
},
expected
Pod1v1
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"p"
,
SelfLink
:
"/api/v1beta1/
p
ods/p"
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Image
:
"image/one"
}}}}
expected
BoundPod1v2
:=
api
.
Bound
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"p"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/p"
},
expected
Pod1v2
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"p"
,
SelfLink
:
"/api/v1beta1/
p
ods/p"
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Image
:
"image/two"
}}}}
expected
BoundPod2
:=
api
.
Bound
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"q"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/q"
},
expected
Pod2
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"q"
,
SelfLink
:
"/api/v1beta1/
p
ods/q"
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Image
:
"image/blah"
}}}}
// Setup fake api client.
...
...
@@ -80,7 +80,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) {
t
.
Errorf
(
"Unable to read from channel when expected"
)
}
update
:=
got
.
(
kubelet
.
PodUpdate
)
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
Bound
Pod1v1
)
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expectedPod1v1
)
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
update
)
{
t
.
Errorf
(
"Expected %#v; Got %#v"
,
expected
,
update
)
}
...
...
@@ -93,8 +93,8 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) {
}
update
=
got
.
(
kubelet
.
PodUpdate
)
// Could be sorted either of these two ways:
expectedA
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
BoundPod1v1
,
expectedBoun
dPod2
)
expectedB
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
BoundPod2
,
expectedBoun
dPod1v1
)
expectedA
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
Pod1v1
,
expecte
dPod2
)
expectedB
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
Pod2
,
expecte
dPod1v1
)
if
!
api
.
Semantic
.
DeepEqual
(
expectedA
,
update
)
&&
!
api
.
Semantic
.
DeepEqual
(
expectedB
,
update
)
{
t
.
Errorf
(
"Expected %#v or %#v, Got %#v"
,
expectedA
,
expectedB
,
update
)
...
...
@@ -107,8 +107,8 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) {
t
.
Errorf
(
"Unable to read from channel when expected"
)
}
update
=
got
.
(
kubelet
.
PodUpdate
)
expectedA
=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
BoundPod1v2
,
expectedBoun
dPod2
)
expectedB
=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
BoundPod2
,
expectedBoun
dPod1v2
)
expectedA
=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
Pod1v2
,
expecte
dPod2
)
expectedB
=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
Pod2
,
expecte
dPod1v2
)
if
!
api
.
Semantic
.
DeepEqual
(
expectedA
,
update
)
&&
!
api
.
Semantic
.
DeepEqual
(
expectedB
,
update
)
{
t
.
Errorf
(
"Expected %#v or %#v, Got %#v"
,
expectedA
,
expectedB
,
update
)
...
...
@@ -121,7 +121,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) {
t
.
Errorf
(
"Unable to read from channel when expected"
)
}
update
=
got
.
(
kubelet
.
PodUpdate
)
expected
=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expected
Bound
Pod2
)
expected
=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
ApiserverSource
,
expectedPod2
)
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
update
)
{
t
.
Errorf
(
"Expected %#v, Got %#v"
,
expected
,
update
)
}
...
...
pkg/kubelet/config/config.go
View file @
bdc1981e
...
...
@@ -113,7 +113,7 @@ func (c *PodConfig) Sync() {
type
podStorage
struct
{
podLock
sync
.
RWMutex
// map of source name to pod name to pod reference
pods
map
[
string
]
map
[
string
]
*
api
.
Bound
Pod
pods
map
[
string
]
map
[
string
]
*
api
.
Pod
mode
PodConfigNotificationMode
// ensures that updates are delivered in strict order
...
...
@@ -134,7 +134,7 @@ type podStorage struct {
// TODO: allow initialization of the current state of the store with snapshotted version.
func
newPodStorage
(
updates
chan
<-
kubelet
.
PodUpdate
,
mode
PodConfigNotificationMode
,
recorder
record
.
EventRecorder
)
*
podStorage
{
return
&
podStorage
{
pods
:
make
(
map
[
string
]
map
[
string
]
*
api
.
Bound
Pod
),
pods
:
make
(
map
[
string
]
map
[
string
]
*
api
.
Pod
),
mode
:
mode
,
updates
:
updates
,
sourcesSeen
:
util
.
StringSet
{},
...
...
@@ -169,12 +169,12 @@ func (s *podStorage) Merge(source string, change interface{}) error {
s
.
updates
<-
*
updates
}
if
len
(
deletes
.
Pods
)
>
0
||
len
(
adds
.
Pods
)
>
0
{
s
.
updates
<-
kubelet
.
PodUpdate
{
s
.
MergedState
()
.
([]
api
.
Bound
Pod
),
kubelet
.
SET
,
source
}
s
.
updates
<-
kubelet
.
PodUpdate
{
s
.
MergedState
()
.
([]
api
.
Pod
),
kubelet
.
SET
,
source
}
}
case
PodConfigNotificationSnapshot
:
if
len
(
updates
.
Pods
)
>
0
||
len
(
deletes
.
Pods
)
>
0
||
len
(
adds
.
Pods
)
>
0
{
s
.
updates
<-
kubelet
.
PodUpdate
{
s
.
MergedState
()
.
([]
api
.
Bound
Pod
),
kubelet
.
SET
,
source
}
s
.
updates
<-
kubelet
.
PodUpdate
{
s
.
MergedState
()
.
([]
api
.
Pod
),
kubelet
.
SET
,
source
}
}
default
:
...
...
@@ -194,7 +194,7 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
pods
:=
s
.
pods
[
source
]
if
pods
==
nil
{
pods
=
make
(
map
[
string
]
*
api
.
Bound
Pod
)
pods
=
make
(
map
[
string
]
*
api
.
Pod
)
}
update
:=
change
.
(
kubelet
.
PodUpdate
)
...
...
@@ -246,7 +246,7 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
s
.
markSourceSet
(
source
)
// Clear the old map entries by just creating a new map
oldPods
:=
pods
pods
=
make
(
map
[
string
]
*
api
.
Bound
Pod
)
pods
=
make
(
map
[
string
]
*
api
.
Pod
)
filtered
:=
filterInvalidPods
(
update
.
Pods
,
source
,
s
.
recorder
)
for
_
,
ref
:=
range
filtered
{
...
...
@@ -298,12 +298,12 @@ func (s *podStorage) seenSources(sources ...string) bool {
return
s
.
sourcesSeen
.
HasAll
(
sources
...
)
}
func
filterInvalidPods
(
pods
[]
api
.
BoundPod
,
source
string
,
recorder
record
.
EventRecorder
)
(
filtered
[]
*
api
.
Bound
Pod
)
{
func
filterInvalidPods
(
pods
[]
api
.
Pod
,
source
string
,
recorder
record
.
EventRecorder
)
(
filtered
[]
*
api
.
Pod
)
{
names
:=
util
.
StringSet
{}
for
i
:=
range
pods
{
pod
:=
&
pods
[
i
]
var
errlist
[]
error
if
errs
:=
validation
.
Validate
Bound
Pod
(
pod
);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
ValidatePod
(
pod
);
len
(
errs
)
!=
0
{
errlist
=
append
(
errlist
,
errs
...
)
// If validation fails, don't trust it any further -
// even Name could be bad.
...
...
@@ -331,27 +331,27 @@ func filterInvalidPods(pods []api.BoundPod, source string, recorder record.Event
func
(
s
*
podStorage
)
Sync
()
{
s
.
updateLock
.
Lock
()
defer
s
.
updateLock
.
Unlock
()
s
.
updates
<-
kubelet
.
PodUpdate
{
s
.
MergedState
()
.
([]
api
.
Bound
Pod
),
kubelet
.
SET
,
kubelet
.
AllSource
}
s
.
updates
<-
kubelet
.
PodUpdate
{
s
.
MergedState
()
.
([]
api
.
Pod
),
kubelet
.
SET
,
kubelet
.
AllSource
}
}
// Object implements config.Accessor
func
(
s
*
podStorage
)
MergedState
()
interface
{}
{
s
.
podLock
.
RLock
()
defer
s
.
podLock
.
RUnlock
()
pods
:=
make
([]
api
.
Bound
Pod
,
0
)
pods
:=
make
([]
api
.
Pod
,
0
)
for
_
,
sourcePods
:=
range
s
.
pods
{
for
_
,
podRef
:=
range
sourcePods
{
pod
,
err
:=
api
.
Scheme
.
Copy
(
podRef
)
if
err
!=
nil
{
glog
.
Errorf
(
"unable to copy pod: %v"
,
err
)
}
pods
=
append
(
pods
,
*
pod
.
(
*
api
.
Bound
Pod
))
pods
=
append
(
pods
,
*
pod
.
(
*
api
.
Pod
))
}
}
return
pods
}
func
bestPodIdentString
(
pod
*
api
.
Bound
Pod
)
string
{
func
bestPodIdentString
(
pod
*
api
.
Pod
)
string
{
namespace
:=
pod
.
Namespace
if
namespace
==
""
{
namespace
=
"<empty-namespace>"
...
...
pkg/kubelet/config/config_test.go
View file @
bdc1981e
...
...
@@ -39,7 +39,7 @@ func expectEmptyChannel(t *testing.T, ch <-chan interface{}) {
}
}
type
sortedPods
[]
api
.
Bound
Pod
type
sortedPods
[]
api
.
Pod
func
(
s
sortedPods
)
Len
()
int
{
return
len
(
s
)
...
...
@@ -51,8 +51,8 @@ func (s sortedPods) Less(i, j int) bool {
return
s
[
i
]
.
Namespace
<
s
[
j
]
.
Namespace
}
func
CreateValidPod
(
name
,
namespace
,
source
string
)
api
.
Bound
Pod
{
return
api
.
Bound
Pod
{
func
CreateValidPod
(
name
,
namespace
,
source
string
)
api
.
Pod
{
return
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
name
),
// for the purpose of testing, this is unique enough
Name
:
name
,
...
...
@@ -66,8 +66,8 @@ func CreateValidPod(name, namespace, source string) api.BoundPod {
}
}
func
CreatePodUpdate
(
op
kubelet
.
PodOperation
,
source
string
,
pods
...
api
.
Bound
Pod
)
kubelet
.
PodUpdate
{
newPods
:=
make
([]
api
.
Bound
Pod
,
len
(
pods
))
func
CreatePodUpdate
(
op
kubelet
.
PodOperation
,
source
string
,
pods
...
api
.
Pod
)
kubelet
.
PodUpdate
{
newPods
:=
make
([]
api
.
Pod
,
len
(
pods
))
for
i
:=
range
pods
{
newPods
[
i
]
=
pods
[
i
]
}
...
...
@@ -160,7 +160,7 @@ func TestInvalidPodFiltered(t *testing.T) {
expectPodUpdate
(
t
,
ch
,
CreatePodUpdate
(
kubelet
.
ADD
,
NoneSource
,
CreateValidPod
(
"foo"
,
"new"
,
"test"
)))
// add an invalid update
podUpdate
=
CreatePodUpdate
(
kubelet
.
UPDATE
,
NoneSource
,
api
.
Bound
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
podUpdate
=
CreatePodUpdate
(
kubelet
.
UPDATE
,
NoneSource
,
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
channel
<-
podUpdate
expectNoPodUpdate
(
t
,
ch
)
}
...
...
@@ -219,7 +219,7 @@ func TestNewPodAddedUpdatedRemoved(t *testing.T) {
channel
<-
podUpdate
expectPodUpdate
(
t
,
ch
,
CreatePodUpdate
(
kubelet
.
UPDATE
,
NoneSource
,
pod
))
podUpdate
=
CreatePodUpdate
(
kubelet
.
REMOVE
,
NoneSource
,
api
.
Bound
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"new"
}})
podUpdate
=
CreatePodUpdate
(
kubelet
.
REMOVE
,
NoneSource
,
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"new"
}})
channel
<-
podUpdate
expectPodUpdate
(
t
,
ch
,
CreatePodUpdate
(
kubelet
.
REMOVE
,
NoneSource
,
pod
))
}
...
...
pkg/kubelet/config/file.go
View file @
bdc1981e
...
...
@@ -66,7 +66,7 @@ func (s *sourceFile) extractFromPath() error {
return
err
}
// Emit an update with an empty PodList to allow FileSource to be marked as seen
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Bound
Pod
{},
kubelet
.
SET
,
kubelet
.
FileSource
}
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Pod
{},
kubelet
.
SET
,
kubelet
.
FileSource
}
return
fmt
.
Errorf
(
"path does not exist, ignoring"
)
}
...
...
@@ -83,7 +83,7 @@ func (s *sourceFile) extractFromPath() error {
if
err
!=
nil
{
return
err
}
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Bound
Pod
{
pod
},
kubelet
.
SET
,
kubelet
.
FileSource
}
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Pod
{
pod
},
kubelet
.
SET
,
kubelet
.
FileSource
}
default
:
return
fmt
.
Errorf
(
"path is not a directory or file"
)
...
...
@@ -95,13 +95,13 @@ func (s *sourceFile) extractFromPath() error {
// Get as many pod configs as we can from a directory. Return an error iff something
// prevented us from reading anything at all. Do not return an error if only some files
// were problematic.
func
extractFromDir
(
name
string
)
([]
api
.
Bound
Pod
,
error
)
{
func
extractFromDir
(
name
string
)
([]
api
.
Pod
,
error
)
{
dirents
,
err
:=
filepath
.
Glob
(
filepath
.
Join
(
name
,
"[^.]*"
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"glob failed: %v"
,
err
)
}
pods
:=
make
([]
api
.
Bound
Pod
,
0
)
pods
:=
make
([]
api
.
Pod
,
0
)
if
len
(
dirents
)
==
0
{
return
pods
,
nil
}
...
...
@@ -131,8 +131,8 @@ func extractFromDir(name string) ([]api.BoundPod, error) {
return
pods
,
nil
}
func
extractFromFile
(
filename
string
)
(
api
.
Bound
Pod
,
error
)
{
var
pod
api
.
Bound
Pod
func
extractFromFile
(
filename
string
)
(
api
.
Pod
,
error
)
{
var
pod
api
.
Pod
glog
.
V
(
3
)
.
Infof
(
"Reading config file %q"
,
filename
)
file
,
err
:=
os
.
Open
(
filename
)
...
...
@@ -153,10 +153,10 @@ func extractFromFile(filename string) (api.BoundPod, error) {
// becomes nicer). Until then, we assert that the ContainerManifest
// structure on disk is always v1beta1. Read that, convert it to a
// "current" ContainerManifest (should be ~identical), then convert
// that to a
Bound
Pod (which is a well-understood conversion). This
// avoids writing a v1beta1.ContainerManifest -> api.
Bound
Pod
// that to a Pod (which is a well-understood conversion). This
// avoids writing a v1beta1.ContainerManifest -> api.Pod
// conversion which would be identical to the api.ContainerManifest ->
// api.
Bound
Pod conversion.
// api.Pod conversion.
oldManifest
:=
&
v1beta1
.
ContainerManifest
{}
if
err
:=
yaml
.
Unmarshal
(
data
,
oldManifest
);
err
!=
nil
{
return
pod
,
fmt
.
Errorf
(
"can't unmarshal file %q: %v"
,
filename
,
err
)
...
...
pkg/kubelet/config/file_test.go
View file @
bdc1981e
...
...
@@ -32,7 +32,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
)
func
ExampleManifestAndPod
(
id
string
)
(
v1beta1
.
ContainerManifest
,
api
.
Bound
Pod
)
{
func
ExampleManifestAndPod
(
id
string
)
(
v1beta1
.
ContainerManifest
,
api
.
Pod
)
{
manifest
:=
v1beta1
.
ContainerManifest
{
ID
:
id
,
UUID
:
types
.
UID
(
id
),
...
...
@@ -52,7 +52,7 @@ func ExampleManifestAndPod(id string) (v1beta1.ContainerManifest, api.BoundPod)
},
},
}
expectedPod
:=
api
.
Bound
Pod
{
expectedPod
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
id
,
UID
:
types
.
UID
(
id
),
...
...
@@ -130,7 +130,7 @@ func TestReadFromFile(t *testing.T) {
select
{
case
got
:=
<-
ch
:
update
:=
got
.
(
kubelet
.
PodUpdate
)
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
api
.
Bound
Pod
{
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
UID
:
"12345"
,
...
...
@@ -179,7 +179,7 @@ func TestReadFromFileWithoutID(t *testing.T) {
select
{
case
got
:=
<-
ch
:
update
:=
got
.
(
kubelet
.
PodUpdate
)
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
api
.
Bound
Pod
{
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
UID
:
"12345"
,
...
...
@@ -219,7 +219,7 @@ func TestReadV1Beta2FromFile(t *testing.T) {
select
{
case
got
:=
<-
ch
:
update
:=
got
.
(
kubelet
.
PodUpdate
)
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
api
.
Bound
Pod
{
expected
:=
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
UID
:
"12345"
,
...
...
@@ -303,7 +303,7 @@ func TestExtractFromDir(t *testing.T) {
manifest2
,
expectedPod2
:=
ExampleManifestAndPod
(
"2"
)
manifests
:=
[]
v1beta1
.
ContainerManifest
{
manifest
,
manifest2
}
pods
:=
[]
api
.
Bound
Pod
{
expectedPod
,
expectedPod2
}
pods
:=
[]
api
.
Pod
{
expectedPod
,
expectedPod2
}
files
:=
make
([]
*
os
.
File
,
len
(
manifests
))
dirName
,
err
:=
ioutil
.
TempDir
(
""
,
"foo"
)
...
...
@@ -357,7 +357,7 @@ func TestExtractFromDir(t *testing.T) {
t
.
Fatalf
(
"Expected %#v, Got %#v"
,
expected
,
update
)
}
for
i
:=
range
update
.
Pods
{
if
errs
:=
validation
.
Validate
Bound
Pod
(
&
update
.
Pods
[
i
]);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
ValidatePod
(
&
update
.
Pods
[
i
]);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"Expected no validation errors on %#v, Got %q"
,
update
.
Pods
[
i
],
errs
)
}
}
...
...
pkg/kubelet/config/http.go
View file @
bdc1981e
...
...
@@ -74,7 +74,7 @@ func (s *sourceURL) extractFromURL() error {
}
if
len
(
data
)
==
0
{
// Emit an update with an empty PodList to allow HTTPSource to be marked as seen
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Bound
Pod
{},
kubelet
.
SET
,
kubelet
.
HTTPSource
}
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Pod
{},
kubelet
.
SET
,
kubelet
.
HTTPSource
}
return
fmt
.
Errorf
(
"zero-length data received from %v"
,
s
.
url
)
}
// Short circuit if the manifest has not changed since the last time it was read.
...
...
@@ -94,7 +94,7 @@ func (s *sourceURL) extractFromURL() error {
if
err
=
applyDefaults
(
&
pod
,
s
.
url
);
err
!=
nil
{
return
err
}
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Bound
Pod
{
pod
},
kubelet
.
SET
,
kubelet
.
HTTPSource
}
s
.
updates
<-
kubelet
.
PodUpdate
{[]
api
.
Pod
{
pod
},
kubelet
.
SET
,
kubelet
.
HTTPSource
}
return
nil
}
...
...
@@ -128,7 +128,7 @@ func (s *sourceURL) extractFromURL() error {
s
.
url
,
string
(
data
),
singleErr
,
manifest
,
multiErr
,
manifests
)
}
func
tryDecodeSingle
(
data
[]
byte
)
(
parsed
bool
,
manifest
v1beta1
.
ContainerManifest
,
pod
api
.
Bound
Pod
,
err
error
)
{
func
tryDecodeSingle
(
data
[]
byte
)
(
parsed
bool
,
manifest
v1beta1
.
ContainerManifest
,
pod
api
.
Pod
,
err
error
)
{
// TODO: should be api.Scheme.Decode
// This is awful. DecodeInto() expects to find an APIObject, which
// Manifest is not. We keep reading manifest for now for compat, but
...
...
@@ -136,10 +136,10 @@ func tryDecodeSingle(data []byte) (parsed bool, manifest v1beta1.ContainerManife
// becomes nicer). Until then, we assert that the ContainerManifest
// structure on disk is always v1beta1. Read that, convert it to a
// "current" ContainerManifest (should be ~identical), then convert
// that to a
Bound
Pod (which is a well-understood conversion). This
// avoids writing a v1beta1.ContainerManifest -> api.
Bound
Pod
// that to a Pod (which is a well-understood conversion). This
// avoids writing a v1beta1.ContainerManifest -> api.Pod
// conversion which would be identical to the api.ContainerManifest ->
// api.
Bound
Pod conversion.
// api.Pod conversion.
if
err
=
yaml
.
Unmarshal
(
data
,
&
manifest
);
err
!=
nil
{
return
false
,
manifest
,
pod
,
err
}
...
...
@@ -158,7 +158,7 @@ func tryDecodeSingle(data []byte) (parsed bool, manifest v1beta1.ContainerManife
return
true
,
manifest
,
pod
,
nil
}
func
tryDecodeList
(
data
[]
byte
)
(
parsed
bool
,
manifests
[]
v1beta1
.
ContainerManifest
,
pods
api
.
BoundPods
,
err
error
)
{
func
tryDecodeList
(
data
[]
byte
)
(
parsed
bool
,
manifests
[]
v1beta1
.
ContainerManifest
,
pods
api
.
PodList
,
err
error
)
{
// TODO: should be api.Scheme.Decode
// See the comment in tryDecodeSingle().
if
err
=
yaml
.
Unmarshal
(
data
,
&
manifests
);
err
!=
nil
{
...
...
@@ -183,7 +183,7 @@ func tryDecodeList(data []byte) (parsed bool, manifests []v1beta1.ContainerManif
return
true
,
manifests
,
pods
,
nil
}
func
applyDefaults
(
pod
*
api
.
Bound
Pod
,
url
string
)
error
{
func
applyDefaults
(
pod
*
api
.
Pod
,
url
string
)
error
{
if
len
(
pod
.
UID
)
==
0
{
hasher
:=
md5
.
New
()
fmt
.
Fprintf
(
hasher
,
"url:%s"
,
url
)
...
...
pkg/kubelet/config/http_test.go
View file @
bdc1981e
...
...
@@ -132,12 +132,12 @@ func TestExtractFromHTTP(t *testing.T) {
Containers
:
[]
v1beta1
.
Container
{{
Name
:
"1"
,
Image
:
"foo"
,
ImagePullPolicy
:
v1beta1
.
PullAlways
}}},
expected
:
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
HTTPSource
,
api
.
Bound
Pod
{
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"111"
,
Name
:
"foo"
+
"-"
+
hostname
,
Namespace
:
"foobar"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/foo"
,
SelfLink
:
"/api/v1beta1/
p
ods/foo"
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyAlways
,
...
...
@@ -155,7 +155,7 @@ func TestExtractFromHTTP(t *testing.T) {
manifests
:
api
.
ContainerManifest
{
Version
:
"v1beta1"
,
UUID
:
"111"
},
expected
:
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
HTTPSource
,
api
.
Bound
Pod
{
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"111"
,
Name
:
"111"
+
"-"
+
hostname
,
...
...
@@ -173,12 +173,12 @@ func TestExtractFromHTTP(t *testing.T) {
Containers
:
[]
v1beta1
.
Container
{{
Name
:
"1"
,
Image
:
"foo"
,
ImagePullPolicy
:
v1beta1
.
PullAlways
}}},
expected
:
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
HTTPSource
,
api
.
Bound
Pod
{
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"111"
,
Name
:
"foo"
+
"-"
+
hostname
,
Namespace
:
"foobar"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/foo"
,
SelfLink
:
"/api/v1beta1/
p
ods/foo"
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyAlways
,
...
...
@@ -201,12 +201,12 @@ func TestExtractFromHTTP(t *testing.T) {
},
expected
:
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
HTTPSource
,
api
.
Bound
Pod
{
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"111"
,
Name
:
"foo"
+
"-"
+
hostname
,
Namespace
:
"foobar"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/foo"
,
SelfLink
:
"/api/v1beta1/
p
ods/foo"
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyAlways
,
...
...
@@ -218,12 +218,12 @@ func TestExtractFromHTTP(t *testing.T) {
ImagePullPolicy
:
"Always"
}},
},
},
api
.
Bound
Pod
{
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"222"
,
Name
:
"bar"
+
"-"
+
hostname
,
Namespace
:
"foobar"
,
SelfLink
:
"/api/v1beta1/
boundP
ods/bar"
,
SelfLink
:
"/api/v1beta1/
p
ods/bar"
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyAlways
,
...
...
@@ -274,7 +274,7 @@ func TestExtractFromHTTP(t *testing.T) {
t
.
Errorf
(
"%s: Expected: %#v, Got: %#v"
,
testCase
.
desc
,
testCase
.
expected
,
update
)
}
for
i
:=
range
update
.
Pods
{
if
errs
:=
validation
.
Validate
Bound
Pod
(
&
update
.
Pods
[
i
]);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
ValidatePod
(
&
update
.
Pods
[
i
]);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"%s: Expected no validation errors on %#v, Got %v"
,
testCase
.
desc
,
update
.
Pods
[
i
],
errors
.
NewAggregate
(
errs
))
}
}
...
...
pkg/kubelet/kubelet.go
View file @
bdc1981e
This diff is collapsed.
Click to expand it.
pkg/kubelet/kubelet_test.go
View file @
bdc1981e
This diff is collapsed.
Click to expand it.
pkg/kubelet/pod_workers.go
View file @
bdc1981e
...
...
@@ -28,7 +28,7 @@ import (
"github.com/golang/glog"
)
type
syncPodFnType
func
(
*
api
.
Bound
Pod
,
dockertools
.
DockerContainers
)
error
type
syncPodFnType
func
(
*
api
.
Pod
,
dockertools
.
DockerContainers
)
error
type
podWorkers
struct
{
// Protects podUpdates field.
...
...
@@ -58,7 +58,7 @@ type podWorkers struct {
type
workUpdate
struct
{
// The pod state to reflect.
pod
*
api
.
Bound
Pod
pod
*
api
.
Pod
// Function to call when the update is complete.
updateCompleteFn
func
()
...
...
@@ -106,7 +106,7 @@ func (p *podWorkers) managePodLoop(podUpdates <-chan workUpdate) {
}
// Apply the new setting to the specified pod. updateComplete is called when the update is completed.
func
(
p
*
podWorkers
)
UpdatePod
(
pod
*
api
.
Bound
Pod
,
updateComplete
func
())
{
func
(
p
*
podWorkers
)
UpdatePod
(
pod
*
api
.
Pod
,
updateComplete
func
())
{
uid
:=
pod
.
UID
var
podUpdates
chan
workUpdate
var
exists
bool
...
...
pkg/kubelet/pod_workers_test.go
View file @
bdc1981e
...
...
@@ -27,8 +27,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
)
func
newPod
(
uid
,
name
string
)
*
api
.
Bound
Pod
{
return
&
api
.
Bound
Pod
{
func
newPod
(
uid
,
name
string
)
*
api
.
Pod
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
uid
),
Name
:
name
,
...
...
@@ -46,7 +46,7 @@ func createPodWorkers() (*podWorkers, map[types.UID][]string) {
podWorkers
:=
newPodWorkers
(
fakeDockerCache
,
func
(
pod
*
api
.
Bound
Pod
,
containers
dockertools
.
DockerContainers
)
error
{
func
(
pod
*
api
.
Pod
,
containers
dockertools
.
DockerContainers
)
error
{
func
()
{
lock
.
Lock
()
defer
lock
.
Unlock
()
...
...
pkg/kubelet/probe.go
View file @
bdc1981e
...
...
@@ -41,7 +41,7 @@ const maxProbeRetries = 3
// probeContainer probes the liveness/readiness of the given container.
// If the container's liveness probe is unsuccessful, set readiness to false.
// If liveness is successful, do a readiness check and set readiness accordingly.
func
(
kl
*
Kubelet
)
probeContainer
(
pod
*
api
.
Bound
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
dockerContainer
*
docker
.
APIContainers
)
(
probe
.
Result
,
error
)
{
func
(
kl
*
Kubelet
)
probeContainer
(
pod
*
api
.
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
dockerContainer
*
docker
.
APIContainers
)
(
probe
.
Result
,
error
)
{
// Probe liveness.
live
,
err
:=
kl
.
probeContainerLiveness
(
pod
,
status
,
container
,
dockerContainer
)
if
err
!=
nil
{
...
...
@@ -78,7 +78,7 @@ func (kl *Kubelet) probeContainer(pod *api.BoundPod, status api.PodStatus, conta
// probeContainerLiveness probes the liveness of a container.
// If the initalDelay since container creation on liveness probe has not passed the probe will return probe.Success.
func
(
kl
*
Kubelet
)
probeContainerLiveness
(
pod
*
api
.
Bound
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
dockerContainer
*
docker
.
APIContainers
)
(
probe
.
Result
,
error
)
{
func
(
kl
*
Kubelet
)
probeContainerLiveness
(
pod
*
api
.
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
dockerContainer
*
docker
.
APIContainers
)
(
probe
.
Result
,
error
)
{
p
:=
container
.
LivenessProbe
if
p
==
nil
{
return
probe
.
Success
,
nil
...
...
@@ -91,7 +91,7 @@ func (kl *Kubelet) probeContainerLiveness(pod *api.BoundPod, status api.PodStatu
// probeContainerLiveness probes the readiness of a container.
// If the initial delay on the readiness probe has not passed the probe will return probe.Failure.
func
(
kl
*
Kubelet
)
probeContainerReadiness
(
pod
*
api
.
Bound
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
dockerContainer
*
docker
.
APIContainers
)
(
probe
.
Result
,
error
)
{
func
(
kl
*
Kubelet
)
probeContainerReadiness
(
pod
*
api
.
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
dockerContainer
*
docker
.
APIContainers
)
(
probe
.
Result
,
error
)
{
p
:=
container
.
ReadinessProbe
if
p
==
nil
{
return
probe
.
Success
,
nil
...
...
@@ -104,7 +104,7 @@ func (kl *Kubelet) probeContainerReadiness(pod *api.BoundPod, status api.PodStat
// runProbeWithRetries tries to probe the container in a finite loop, it returns the last result
// if it never succeeds.
func
(
kl
*
Kubelet
)
runProbeWithRetries
(
p
*
api
.
Probe
,
pod
*
api
.
Bound
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
retires
int
)
(
probe
.
Result
,
error
)
{
func
(
kl
*
Kubelet
)
runProbeWithRetries
(
p
*
api
.
Probe
,
pod
*
api
.
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
,
retires
int
)
(
probe
.
Result
,
error
)
{
var
err
error
var
result
probe
.
Result
for
i
:=
0
;
i
<
retires
;
i
++
{
...
...
@@ -116,7 +116,7 @@ func (kl *Kubelet) runProbeWithRetries(p *api.Probe, pod *api.BoundPod, status a
return
result
,
err
}
func
(
kl
*
Kubelet
)
runProbe
(
p
*
api
.
Probe
,
pod
*
api
.
Bound
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
)
(
probe
.
Result
,
error
)
{
func
(
kl
*
Kubelet
)
runProbe
(
p
*
api
.
Probe
,
pod
*
api
.
Pod
,
status
api
.
PodStatus
,
container
api
.
Container
)
(
probe
.
Result
,
error
)
{
timeout
:=
time
.
Duration
(
p
.
TimeoutSeconds
)
*
time
.
Second
if
p
.
Exec
!=
nil
{
return
kl
.
prober
.
exec
.
Probe
(
kl
.
newExecInContainer
(
pod
,
container
))
...
...
@@ -190,7 +190,7 @@ type execInContainer struct {
run
func
()
([]
byte
,
error
)
}
func
(
kl
*
Kubelet
)
newExecInContainer
(
pod
*
api
.
Bound
Pod
,
container
api
.
Container
)
exec
.
Cmd
{
func
(
kl
*
Kubelet
)
newExecInContainer
(
pod
*
api
.
Pod
,
container
api
.
Container
)
exec
.
Cmd
{
uid
:=
pod
.
UID
podFullName
:=
GetPodFullName
(
pod
)
return
execInContainer
{
func
()
([]
byte
,
error
)
{
...
...
pkg/kubelet/probe_test.go
View file @
bdc1981e
...
...
@@ -400,7 +400,7 @@ func TestProbeContainer(t *testing.T) {
}
else
{
kl
=
makeTestKubelet
(
test
.
expectedResult
,
nil
)
}
result
,
err
:=
kl
.
probeContainer
(
&
api
.
Bound
Pod
{},
api
.
PodStatus
{},
test
.
testContainer
,
dc
)
result
,
err
:=
kl
.
probeContainer
(
&
api
.
Pod
{},
api
.
PodStatus
{},
test
.
testContainer
,
dc
)
if
test
.
expectError
&&
err
==
nil
{
t
.
Error
(
"Expected error but did no error was returned."
)
}
...
...
pkg/kubelet/runonce.go
View file @
bdc1981e
...
...
@@ -33,7 +33,7 @@ const (
)
type
RunPodResult
struct
{
Pod
*
api
.
Bound
Pod
Pod
*
api
.
Pod
Err
error
}
...
...
@@ -51,7 +51,7 @@ func (kl *Kubelet) RunOnce(updates <-chan PodUpdate) ([]RunPodResult, error) {
}
// runOnce runs a given set of pods and returns their status.
func
(
kl
*
Kubelet
)
runOnce
(
pods
[]
api
.
Bound
Pod
,
retryDelay
time
.
Duration
)
(
results
[]
RunPodResult
,
err
error
)
{
func
(
kl
*
Kubelet
)
runOnce
(
pods
[]
api
.
Pod
,
retryDelay
time
.
Duration
)
(
results
[]
RunPodResult
,
err
error
)
{
if
kl
.
dockerPuller
==
nil
{
kl
.
dockerPuller
=
dockertools
.
NewDockerPuller
(
kl
.
dockerClient
,
kl
.
pullQPS
,
kl
.
pullBurst
)
}
...
...
@@ -87,7 +87,7 @@ func (kl *Kubelet) runOnce(pods []api.BoundPod, retryDelay time.Duration) (resul
}
// runPod runs a single pod and wait until all containers are running.
func
(
kl
*
Kubelet
)
runPod
(
pod
api
.
Bound
Pod
,
retryDelay
time
.
Duration
)
error
{
func
(
kl
*
Kubelet
)
runPod
(
pod
api
.
Pod
,
retryDelay
time
.
Duration
)
error
{
delay
:=
retryDelay
retry
:=
0
for
{
...
...
@@ -119,7 +119,7 @@ func (kl *Kubelet) runPod(pod api.BoundPod, retryDelay time.Duration) error {
}
// isPodRunning returns true if all containers of a manifest are running.
func
(
kl
*
Kubelet
)
isPodRunning
(
pod
api
.
Bound
Pod
,
dockerContainers
dockertools
.
DockerContainers
)
(
bool
,
error
)
{
func
(
kl
*
Kubelet
)
isPodRunning
(
pod
api
.
Pod
,
dockerContainers
dockertools
.
DockerContainers
)
(
bool
,
error
)
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
dockerContainer
,
found
,
_
:=
dockerContainers
.
FindPodContainer
(
GetPodFullName
(
&
pod
),
pod
.
UID
,
container
.
Name
)
if
!
found
{
...
...
pkg/kubelet/runonce_test.go
View file @
bdc1981e
...
...
@@ -128,7 +128,7 @@ func TestRunOnce(t *testing.T) {
t
:
t
,
}
kb
.
dockerPuller
=
&
dockertools
.
FakeDockerPuller
{}
results
,
err
:=
kb
.
runOnce
([]
api
.
Bound
Pod
{
results
,
err
:=
kb
.
runOnce
([]
api
.
Pod
{
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345678"
,
...
...
pkg/kubelet/server.go
View file @
bdc1981e
...
...
@@ -84,8 +84,8 @@ type HostInterface interface {
GetRootInfo
(
req
*
cadvisorApi
.
ContainerInfoRequest
)
(
*
cadvisorApi
.
ContainerInfo
,
error
)
GetDockerVersion
()
([]
uint
,
error
)
GetMachineInfo
()
(
*
cadvisorApi
.
MachineInfo
,
error
)
Get
BoundPods
()
([]
api
.
Bound
Pod
,
error
)
GetPodByName
(
namespace
,
name
string
)
(
*
api
.
Bound
Pod
,
bool
)
Get
Pods
()
([]
api
.
Pod
,
error
)
GetPodByName
(
namespace
,
name
string
)
(
*
api
.
Pod
,
bool
)
GetPodStatus
(
name
string
,
uid
types
.
UID
)
(
api
.
PodStatus
,
error
)
RunInContainer
(
name
string
,
uid
types
.
UID
,
container
string
,
cmd
[]
string
)
([]
byte
,
error
)
ExecInContainer
(
name
string
,
uid
types
.
UID
,
container
string
,
cmd
[]
string
,
in
io
.
Reader
,
out
,
err
io
.
WriteCloser
,
tty
bool
)
error
...
...
@@ -117,7 +117,7 @@ func (s *Server) InstallDefaultHandlers() {
s
.
mux
.
HandleFunc
(
"/podInfo"
,
s
.
handlePodInfoOld
)
s
.
mux
.
HandleFunc
(
"/api/v1beta1/podInfo"
,
s
.
handlePodInfoVersioned
)
s
.
mux
.
HandleFunc
(
"/api/v1beta1/nodeInfo"
,
s
.
handleNodeInfoVersioned
)
s
.
mux
.
HandleFunc
(
"/
boundPods"
,
s
.
handleBound
Pods
)
s
.
mux
.
HandleFunc
(
"/
pods"
,
s
.
handle
Pods
)
s
.
mux
.
HandleFunc
(
"/stats/"
,
s
.
handleStats
)
s
.
mux
.
HandleFunc
(
"/spec/"
,
s
.
handleSpec
)
}
...
...
@@ -258,17 +258,17 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
}
}
// handle
BoundPods returns a list of pod bound
to the Kubelet and their spec
func
(
s
*
Server
)
handle
Bound
Pods
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
pods
,
err
:=
s
.
host
.
Get
Bound
Pods
()
// handle
Pods returns a list of pod bounds
to the Kubelet and their spec
func
(
s
*
Server
)
handlePods
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
pods
,
err
:=
s
.
host
.
GetPods
()
if
err
!=
nil
{
s
.
error
(
w
,
err
)
return
}
boundPods
:=
&
api
.
BoundPods
{
podList
:=
&
api
.
PodList
{
Items
:
pods
,
}
data
,
err
:=
latest
.
Codec
.
Encode
(
boundPods
)
data
,
err
:=
latest
.
Codec
.
Encode
(
podList
)
if
err
!=
nil
{
s
.
error
(
w
,
err
)
return
...
...
pkg/kubelet/server_test.go
View file @
bdc1981e
...
...
@@ -39,12 +39,12 @@ import (
)
type
fakeKubelet
struct
{
podByNameFunc
func
(
namespace
,
name
string
)
(
*
api
.
Bound
Pod
,
bool
)
podByNameFunc
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
bool
)
statusFunc
func
(
name
string
)
(
api
.
PodStatus
,
error
)
containerInfoFunc
func
(
podFullName
string
,
uid
types
.
UID
,
containerName
string
,
req
*
cadvisorApi
.
ContainerInfoRequest
)
(
*
cadvisorApi
.
ContainerInfo
,
error
)
rootInfoFunc
func
(
query
*
cadvisorApi
.
ContainerInfoRequest
)
(
*
cadvisorApi
.
ContainerInfo
,
error
)
machineInfoFunc
func
()
(
*
cadvisorApi
.
MachineInfo
,
error
)
boundPodsFunc
func
()
([]
api
.
Bound
Pod
,
error
)
podsFunc
func
()
([]
api
.
Pod
,
error
)
logFunc
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
runFunc
func
(
podFullName
string
,
uid
types
.
UID
,
containerName
string
,
cmd
[]
string
)
([]
byte
,
error
)
dockerVersionFunc
func
()
([]
uint
,
error
)
...
...
@@ -55,7 +55,7 @@ type fakeKubelet struct {
hostnameFunc
func
()
string
}
func
(
fk
*
fakeKubelet
)
GetPodByName
(
namespace
,
name
string
)
(
*
api
.
Bound
Pod
,
bool
)
{
func
(
fk
*
fakeKubelet
)
GetPodByName
(
namespace
,
name
string
)
(
*
api
.
Pod
,
bool
)
{
return
fk
.
podByNameFunc
(
namespace
,
name
)
}
...
...
@@ -79,8 +79,8 @@ func (fk *fakeKubelet) GetMachineInfo() (*cadvisorApi.MachineInfo, error) {
return
fk
.
machineInfoFunc
()
}
func
(
fk
*
fakeKubelet
)
Get
BoundPods
()
([]
api
.
Bound
Pod
,
error
)
{
return
fk
.
boundP
odsFunc
()
func
(
fk
*
fakeKubelet
)
Get
Pods
()
([]
api
.
Pod
,
error
)
{
return
fk
.
p
odsFunc
()
}
func
(
fk
*
fakeKubelet
)
ServeLogs
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
...
...
@@ -125,8 +125,8 @@ func newServerTest() *serverTestFramework {
}
fw
.
updateReader
=
startReading
(
fw
.
updateChan
)
fw
.
fakeKubelet
=
&
fakeKubelet
{
podByNameFunc
:
func
(
namespace
,
name
string
)
(
*
api
.
Bound
Pod
,
bool
)
{
return
&
api
.
Bound
Pod
{
podByNameFunc
:
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
bool
)
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
namespace
,
Name
:
name
,
...
...
@@ -510,8 +510,8 @@ func TestHealthCheck(t *testing.T) {
}
func
setPodByNameFunc
(
fw
*
serverTestFramework
,
namespace
,
pod
,
container
string
)
{
fw
.
fakeKubelet
.
podByNameFunc
=
func
(
namespace
,
name
string
)
(
*
api
.
Bound
Pod
,
bool
)
{
return
&
api
.
Bound
Pod
{
fw
.
fakeKubelet
.
podByNameFunc
=
func
(
namespace
,
name
string
)
(
*
api
.
Pod
,
bool
)
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
namespace
,
Name
:
pod
,
...
...
pkg/kubelet/types.go
View file @
bdc1981e
...
...
@@ -62,13 +62,13 @@ const (
// functionally similar, this helps our unit tests properly check that the correct PodUpdates
// are generated.
type
PodUpdate
struct
{
Pods
[]
api
.
Bound
Pod
Pods
[]
api
.
Pod
Op
PodOperation
Source
string
}
// GetPodFullName returns a name that uniquely identifies a pod across all config sources.
func
GetPodFullName
(
pod
*
api
.
Bound
Pod
)
string
{
func
GetPodFullName
(
pod
*
api
.
Pod
)
string
{
// Use underscore as the delimiter because it is not allowed in pod name
// (DNS subdomain format), while allowed in the container name format.
return
fmt
.
Sprintf
(
"%s_%s"
,
pod
.
Name
,
pod
.
Namespace
)
...
...
pkg/kubelet/volumes.go
View file @
bdc1981e
...
...
@@ -72,7 +72,7 @@ func (kl *Kubelet) newVolumeBuilderFromPlugins(spec *api.Volume, podRef *api.Obj
return
builder
}
func
(
kl
*
Kubelet
)
mountExternalVolumes
(
pod
*
api
.
Bound
Pod
)
(
volumeMap
,
error
)
{
func
(
kl
*
Kubelet
)
mountExternalVolumes
(
pod
*
api
.
Pod
)
(
volumeMap
,
error
)
{
podVolumes
:=
make
(
volumeMap
)
for
i
:=
range
pod
.
Spec
.
Volumes
{
volSpec
:=
&
pod
.
Spec
.
Volumes
[
i
]
...
...
test/e2e/events.go
View file @
bdc1981e
...
...
@@ -115,7 +115,7 @@ var _ = Describe("Events", func() {
labels
.
Everything
(),
labels
.
Set
{
"involvedObject.uid"
:
string
(
podWithUid
.
UID
),
"involvedObject.kind"
:
"
Bound
Pod"
,
"involvedObject.kind"
:
"Pod"
,
"involvedObject.namespace"
:
api
.
NamespaceDefault
,
"source"
:
"kubelet"
,
}
.
AsSelector
(),
...
...
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