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
cf56f7a8
Commit
cf56f7a8
authored
Sep 24, 2015
by
Vishnu kannan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring kubelet to separate object creation from object logical initialization.
parent
8761ad3e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
141 additions
and
103 deletions
+141
-103
kubelet.go
pkg/kubelet/kubelet.go
+58
-97
kubelet_test.go
pkg/kubelet/kubelet_test.go
+9
-6
runtime.go
pkg/kubelet/runtime.go
+74
-0
No files found.
pkg/kubelet/kubelet.go
View file @
cf56f7a8
This diff is collapsed.
Click to expand it.
pkg/kubelet/kubelet_test.go
View file @
cf56f7a8
...
@@ -96,7 +96,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
...
@@ -96,7 +96,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet
.
hostname
=
testKubeletHostname
kubelet
.
hostname
=
testKubeletHostname
kubelet
.
nodeName
=
testKubeletHostname
kubelet
.
nodeName
=
testKubeletHostname
kubelet
.
runtime
UpThreshold
=
maxWaitForContainerRuntime
kubelet
.
runtime
State
=
newRuntimeState
(
maxWaitForContainerRuntime
)
kubelet
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
network
.
NewFakeHost
(
nil
))
kubelet
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
network
.
NewFakeHost
(
nil
))
if
tempDir
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"kubelet_test."
);
err
!=
nil
{
if
tempDir
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"kubelet_test."
);
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
...
@@ -140,7 +140,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
...
@@ -140,7 +140,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet
.
volumeManager
=
newVolumeManager
()
kubelet
.
volumeManager
=
newVolumeManager
()
kubelet
.
containerManager
,
_
=
newContainerManager
(
fakeContainerMgrMountInt
(),
mockCadvisor
,
""
,
""
,
""
)
kubelet
.
containerManager
,
_
=
newContainerManager
(
fakeContainerMgrMountInt
(),
mockCadvisor
,
""
,
""
,
""
)
kubelet
.
networkConfigured
=
true
kubelet
.
runtimeState
.
setNetworkError
(
nil
)
fakeClock
:=
&
util
.
FakeClock
{
Time
:
time
.
Now
()}
fakeClock
:=
&
util
.
FakeClock
{
Time
:
time
.
Now
()}
kubelet
.
backOff
=
util
.
NewBackOff
(
time
.
Second
,
time
.
Minute
)
kubelet
.
backOff
=
util
.
NewBackOff
(
time
.
Second
,
time
.
Minute
)
kubelet
.
backOff
.
Clock
=
fakeClock
kubelet
.
backOff
.
Clock
=
fakeClock
...
@@ -357,8 +357,10 @@ func TestSyncLoopAbort(t *testing.T) {
...
@@ -357,8 +357,10 @@ func TestSyncLoopAbort(t *testing.T) {
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
kubelet
:=
testKubelet
.
kubelet
kubelet
:=
testKubelet
.
kubelet
kubelet
.
lastTimestampRuntimeUp
=
time
.
Now
()
kubelet
.
runtimeState
.
setRuntimeSync
(
time
.
Now
())
kubelet
.
networkConfigured
=
true
// The syncLoop waits on time.After(resyncInterval), set it really big so that we don't race for
// the channel close
kubelet
.
resyncInterval
=
time
.
Second
*
30
ch
:=
make
(
chan
kubetypes
.
PodUpdate
)
ch
:=
make
(
chan
kubetypes
.
PodUpdate
)
close
(
ch
)
close
(
ch
)
...
@@ -2626,7 +2628,8 @@ func TestUpdateNewNodeStatus(t *testing.T) {
...
@@ -2626,7 +2628,8 @@ func TestUpdateNewNodeStatus(t *testing.T) {
}
}
}
}
func
TestDockerRuntimeVersion
(
t
*
testing
.
T
)
{
// FIXME: Enable me..
func
testDockerRuntimeVersion
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
kubelet
:=
testKubelet
.
kubelet
fakeRuntime
:=
testKubelet
.
fakeRuntime
fakeRuntime
:=
testKubelet
.
fakeRuntime
...
@@ -2994,7 +2997,7 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
...
@@ -2994,7 +2997,7 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
},
},
}
}
kubelet
.
runtime
UpThreshold
=
time
.
Duration
(
0
)
kubelet
.
runtime
State
=
newRuntimeState
(
time
.
Duration
(
0
)
)
kubelet
.
updateRuntimeUp
()
kubelet
.
updateRuntimeUp
()
if
err
:=
kubelet
.
updateNodeStatus
();
err
!=
nil
{
if
err
:=
kubelet
.
updateNodeStatus
();
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
...
pkg/kubelet/runtime.go
0 → 100644
View file @
cf56f7a8
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
kubelet
import
(
"sync"
"time"
)
type
runtimeState
struct
{
sync
.
Mutex
lastBaseRuntimeSync
time
.
Time
baseRuntimeSyncThreshold
time
.
Duration
networkError
error
initError
error
}
func
(
s
*
runtimeState
)
setRuntimeSync
(
t
time
.
Time
)
{
s
.
Lock
()
defer
s
.
Unlock
()
s
.
lastBaseRuntimeSync
=
t
}
func
(
s
*
runtimeState
)
setNetworkError
(
err
error
)
{
if
err
==
nil
{
return
}
s
.
Lock
()
defer
s
.
Unlock
()
s
.
networkError
=
err
}
func
(
s
*
runtimeState
)
setInitError
(
err
error
)
{
s
.
Lock
()
defer
s
.
Unlock
()
s
.
initError
=
err
}
func
(
s
*
runtimeState
)
errors
()
[]
string
{
s
.
Lock
()
defer
s
.
Unlock
()
var
ret
[]
string
if
s
.
initError
!=
nil
{
ret
=
append
(
ret
,
s
.
initError
.
Error
())
}
if
s
.
networkError
!=
nil
{
ret
=
append
(
ret
,
s
.
networkError
.
Error
())
}
if
!
s
.
lastBaseRuntimeSync
.
Add
(
s
.
baseRuntimeSyncThreshold
)
.
After
(
time
.
Now
())
{
ret
=
append
(
ret
,
"container runtime is down"
)
}
return
ret
}
func
newRuntimeState
(
runtimeSyncThreshold
time
.
Duration
)
*
runtimeState
{
return
&
runtimeState
{
lastBaseRuntimeSync
:
time
.
Time
{},
baseRuntimeSyncThreshold
:
runtimeSyncThreshold
,
}
}
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