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
89c3cb2f
Commit
89c3cb2f
authored
Sep 25, 2015
by
Vishnu kannan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor podCIDR handling in kubelet to runtime state
parent
5f4570b7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
19 deletions
+27
-19
kubelet.go
pkg/kubelet/kubelet.go
+4
-12
kubelet_test.go
pkg/kubelet/kubelet_test.go
+3
-5
runtime.go
pkg/kubelet/runtime.go
+20
-2
No files found.
pkg/kubelet/kubelet.go
View file @
89c3cb2f
...
...
@@ -32,7 +32,6 @@ import (
"path/filepath"
"sort"
"strings"
"sync"
"time"
"github.com/golang/glog"
...
...
@@ -278,7 +277,7 @@ func NewMainKubelet(
clusterDNS
:
clusterDNS
,
serviceLister
:
serviceLister
,
nodeLister
:
nodeLister
,
runtimeState
:
newRuntimeState
(
maxWaitForContainerRuntime
),
runtimeState
:
newRuntimeState
(
maxWaitForContainerRuntime
,
configureCBR0
,
podCIDR
),
masterServiceNamespace
:
masterServiceNamespace
,
streamingConnectionIdleTimeout
:
streamingConnectionIdleTimeout
,
recorder
:
recorder
,
...
...
@@ -297,7 +296,6 @@ func NewMainKubelet(
chownRunner
:
chownRunner
,
writer
:
writer
,
configureCBR0
:
configureCBR0
,
podCIDR
:
podCIDR
,
reconcileCIDR
:
reconcileCIDR
,
pods
:
pods
,
syncLoopMonitor
:
util
.
AtomicValue
{},
...
...
@@ -499,8 +497,7 @@ type Kubelet struct {
// Last timestamp when runtime responded on ping.
// Mutex is used to protect this value.
runtimeState
*
runtimeState
networkConfigMutex
sync
.
Mutex
runtimeState
*
runtimeState
// Volume plugins.
volumePluginMgr
volume
.
VolumePluginMgr
...
...
@@ -588,7 +585,6 @@ type Kubelet struct {
// Whether or not kubelet should take responsibility for keeping cbr0 in
// the correct state.
configureCBR0
bool
podCIDR
string
reconcileCIDR
bool
// Number of Pods which can be run by this Kubelet
...
...
@@ -2425,9 +2421,7 @@ func (kl *Kubelet) syncNetworkStatus() {
err
=
fmt
.
Errorf
(
"Error on adding ip table rules: %v"
,
err
)
glog
.
Error
(
err
)
}
kl
.
networkConfigMutex
.
Lock
()
podCIDR
:=
kl
.
podCIDR
kl
.
networkConfigMutex
.
Unlock
()
podCIDR
:=
kl
.
runtimeState
.
podCIDR
()
if
len
(
podCIDR
)
==
0
{
err
=
fmt
.
Errorf
(
"ConfigureCBR0 requested, but PodCIDR not set. Will not configure CBR0 right now"
)
glog
.
Warning
(
err
)
...
...
@@ -2694,11 +2688,9 @@ func (kl *Kubelet) tryUpdateNodeStatus() error {
if
node
==
nil
{
return
fmt
.
Errorf
(
"no node instance returned for %q"
,
kl
.
nodeName
)
}
kl
.
networkConfigMutex
.
Lock
()
if
kl
.
reconcileCIDR
{
kl
.
podCIDR
=
node
.
Spec
.
PodCIDR
kl
.
runtimeState
.
setPodCIDR
(
node
.
Spec
.
PodCIDR
)
}
kl
.
networkConfigMutex
.
Unlock
()
if
err
:=
kl
.
setNodeStatus
(
node
);
err
!=
nil
{
return
err
...
...
pkg/kubelet/kubelet_test.go
View file @
89c3cb2f
...
...
@@ -96,7 +96,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet
.
hostname
=
testKubeletHostname
kubelet
.
nodeName
=
testKubeletHostname
kubelet
.
runtimeState
=
newRuntimeState
(
maxWaitForContainerRuntime
)
kubelet
.
runtimeState
=
newRuntimeState
(
maxWaitForContainerRuntime
,
false
,
""
/* Pod CIDR */
)
kubelet
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
network
.
NewFakeHost
(
nil
))
if
tempDir
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"kubelet_test."
);
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
...
...
@@ -139,8 +139,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet
.
livenessManager
=
proberesults
.
NewManager
()
kubelet
.
volumeManager
=
newVolumeManager
()
kubelet
.
containerManager
,
_
=
newContainerManager
(
fakeContainerMgrMountInt
(),
mockCadvisor
,
""
,
""
,
""
)
kubelet
.
runtimeState
.
setNetworkState
(
nil
)
kubelet
.
containerManager
=
cm
.
NewStubContainerManager
()
fakeClock
:=
&
util
.
FakeClock
{
Time
:
time
.
Now
()}
kubelet
.
backOff
=
util
.
NewBackOff
(
time
.
Second
,
time
.
Minute
)
kubelet
.
backOff
.
Clock
=
fakeClock
...
...
@@ -2996,8 +2995,7 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
},
},
}
kubelet
.
runtimeState
=
newRuntimeState
(
time
.
Duration
(
0
))
kubelet
.
runtimeState
.
setNetworkState
(
nil
)
kubelet
.
runtimeState
=
newRuntimeState
(
time
.
Duration
(
0
),
false
,
""
/* Pod CIDR */
)
kubelet
.
updateRuntimeUp
()
if
err
:=
kubelet
.
updateNodeStatus
();
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
...
pkg/kubelet/runtime.go
View file @
89c3cb2f
...
...
@@ -27,6 +27,7 @@ type runtimeState struct {
lastBaseRuntimeSync
time
.
Time
baseRuntimeSyncThreshold
time
.
Duration
networkError
error
cidr
string
initError
error
}
...
...
@@ -42,6 +43,18 @@ func (s *runtimeState) setNetworkState(err error) {
s
.
networkError
=
err
}
func
(
s
*
runtimeState
)
setPodCIDR
(
cidr
string
)
{
s
.
Lock
()
defer
s
.
Unlock
()
s
.
cidr
=
cidr
}
func
(
s
*
runtimeState
)
podCIDR
()
string
{
s
.
Lock
()
defer
s
.
Unlock
()
return
s
.
cidr
}
func
(
s
*
runtimeState
)
setInitError
(
err
error
)
{
s
.
Lock
()
defer
s
.
Unlock
()
...
...
@@ -64,10 +77,15 @@ func (s *runtimeState) errors() []string {
return
ret
}
func
newRuntimeState
(
runtimeSyncThreshold
time
.
Duration
)
*
runtimeState
{
func
newRuntimeState
(
runtimeSyncThreshold
time
.
Duration
,
configureNetwork
bool
,
cidr
string
)
*
runtimeState
{
var
networkError
error
=
nil
if
configureNetwork
{
networkError
=
fmt
.
Errorf
(
"network state unknown"
)
}
return
&
runtimeState
{
lastBaseRuntimeSync
:
time
.
Time
{},
baseRuntimeSyncThreshold
:
runtimeSyncThreshold
,
networkError
:
fmt
.
Errorf
(
"network state unknown"
),
networkError
:
networkError
,
cidr
:
cidr
,
}
}
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