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
6469c8e3
Commit
6469c8e3
authored
May 08, 2018
by
Ryan Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubelet: fix checkpoint manager logic bug on restore
parent
5686fcfc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
9 deletions
+56
-9
BUILD
pkg/kubelet/config/BUILD
+2
-0
config.go
pkg/kubelet/config/config.go
+15
-9
config_test.go
pkg/kubelet/config/config_test.go
+39
-0
No files found.
pkg/kubelet/config/BUILD
View file @
6469c8e3
...
@@ -108,6 +108,8 @@ go_test(
...
@@ -108,6 +108,8 @@ go_test(
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/validation:go_default_library",
"//pkg/apis/core/validation:go_default_library",
"//pkg/kubelet/checkpoint:go_default_library",
"//pkg/kubelet/checkpointmanager:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//pkg/securitycontext:go_default_library",
"//pkg/securitycontext:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
...
...
pkg/kubelet/config/config.go
View file @
6469c8e3
...
@@ -113,17 +113,20 @@ func (c *PodConfig) Sync() {
...
@@ -113,17 +113,20 @@ func (c *PodConfig) Sync() {
// Restore restores pods from the checkpoint path, *once*
// Restore restores pods from the checkpoint path, *once*
func
(
c
*
PodConfig
)
Restore
(
path
string
,
updates
chan
<-
interface
{})
error
{
func
(
c
*
PodConfig
)
Restore
(
path
string
,
updates
chan
<-
interface
{})
error
{
if
c
.
checkpointManager
!=
nil
{
return
nil
}
var
err
error
var
err
error
if
c
.
checkpointManager
==
nil
{
c
.
checkpointManager
,
err
=
checkpointmanager
.
NewCheckpointManager
(
path
)
c
.
checkpointManager
,
err
=
checkpointmanager
.
NewCheckpointManager
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
pods
,
err
:=
checkpoint
.
LoadPods
(
c
.
checkpointManager
)
}
if
err
==
nil
{
pods
,
err
:=
checkpoint
.
LoadPods
(
c
.
checkpointManager
)
updates
<-
kubetypes
.
PodUpdate
{
Pods
:
pods
,
Op
:
kubetypes
.
RESTORE
,
Source
:
kubetypes
.
ApiserverSource
}
if
err
!=
nil
{
}
return
err
}
}
}
return
err
updates
<-
kubetypes
.
PodUpdate
{
Pods
:
pods
,
Op
:
kubetypes
.
RESTORE
,
Source
:
kubetypes
.
ApiserverSource
}
return
nil
}
}
// podStorage manages the current pod state at any point in time and ensures updates
// podStorage manages the current pod state at any point in time and ensures updates
...
@@ -311,6 +314,9 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
...
@@ -311,6 +314,9 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
}
}
case
kubetypes
.
RESTORE
:
case
kubetypes
.
RESTORE
:
glog
.
V
(
4
)
.
Infof
(
"Restoring pods for source %s"
,
source
)
glog
.
V
(
4
)
.
Infof
(
"Restoring pods for source %s"
,
source
)
for
_
,
value
:=
range
update
.
Pods
{
restorePods
=
append
(
restorePods
,
value
)
}
default
:
default
:
glog
.
Warningf
(
"Received invalid update type: %v"
,
update
)
glog
.
Warningf
(
"Received invalid update type: %v"
,
update
)
...
...
pkg/kubelet/config/config_test.go
View file @
6469c8e3
...
@@ -17,7 +17,9 @@ limitations under the License.
...
@@ -17,7 +17,9 @@ limitations under the License.
package
config
package
config
import
(
import
(
"io/ioutil"
"math/rand"
"math/rand"
"os"
"reflect"
"reflect"
"sort"
"sort"
"strconv"
"strconv"
...
@@ -30,6 +32,9 @@ import (
...
@@ -30,6 +32,9 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubelet/checkpoint"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
kubetypes
"k8s.io/kubernetes/pkg/kubelet/types"
kubetypes
"k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/securitycontext"
"k8s.io/kubernetes/pkg/securitycontext"
)
)
...
@@ -85,6 +90,14 @@ func CreatePodUpdate(op kubetypes.PodOperation, source string, pods ...*v1.Pod)
...
@@ -85,6 +90,14 @@ func CreatePodUpdate(op kubetypes.PodOperation, source string, pods ...*v1.Pod)
return
kubetypes
.
PodUpdate
{
Pods
:
pods
,
Op
:
op
,
Source
:
source
}
return
kubetypes
.
PodUpdate
{
Pods
:
pods
,
Op
:
op
,
Source
:
source
}
}
}
func
createPodConfigTesterByChannel
(
mode
PodConfigNotificationMode
,
channelName
string
)
(
chan
<-
interface
{},
<-
chan
kubetypes
.
PodUpdate
,
*
PodConfig
)
{
eventBroadcaster
:=
record
.
NewBroadcaster
()
config
:=
NewPodConfig
(
mode
,
eventBroadcaster
.
NewRecorder
(
scheme
.
Scheme
,
v1
.
EventSource
{
Component
:
"kubelet"
}))
channel
:=
config
.
Channel
(
channelName
)
ch
:=
config
.
Updates
()
return
channel
,
ch
,
config
}
func
createPodConfigTester
(
mode
PodConfigNotificationMode
)
(
chan
<-
interface
{},
<-
chan
kubetypes
.
PodUpdate
,
*
PodConfig
)
{
func
createPodConfigTester
(
mode
PodConfigNotificationMode
)
(
chan
<-
interface
{},
<-
chan
kubetypes
.
PodUpdate
,
*
PodConfig
)
{
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
:=
record
.
NewBroadcaster
()
config
:=
NewPodConfig
(
mode
,
eventBroadcaster
.
NewRecorder
(
scheme
.
Scheme
,
v1
.
EventSource
{
Component
:
"kubelet"
}))
config
:=
NewPodConfig
(
mode
,
eventBroadcaster
.
NewRecorder
(
scheme
.
Scheme
,
v1
.
EventSource
{
Component
:
"kubelet"
}))
...
@@ -413,3 +426,29 @@ func TestPodUpdateLabels(t *testing.T) {
...
@@ -413,3 +426,29 @@ func TestPodUpdateLabels(t *testing.T) {
expectPodUpdate
(
t
,
ch
,
CreatePodUpdate
(
kubetypes
.
UPDATE
,
TestSource
,
pod
))
expectPodUpdate
(
t
,
ch
,
CreatePodUpdate
(
kubetypes
.
UPDATE
,
TestSource
,
pod
))
}
}
func
TestPodRestore
(
t
*
testing
.
T
)
{
tmpDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
defer
os
.
RemoveAll
(
tmpDir
)
pod
:=
CreateValidPod
(
"api-server"
,
"kube-default"
)
pod
.
Annotations
=
make
(
map
[
string
]
string
,
0
)
pod
.
Annotations
[
"kubernetes.io/config.source"
]
=
kubetypes
.
ApiserverSource
pod
.
Annotations
[
core
.
BootstrapCheckpointAnnotationKey
]
=
"true"
// Create Checkpointer
checkpointManager
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
tmpDir
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to initialize checkpoint manager: %v"
,
err
)
}
if
err
:=
checkpoint
.
WritePod
(
checkpointManager
,
pod
);
err
!=
nil
{
t
.
Fatalf
(
"Error writing checkpoint for pod: %v"
,
pod
.
GetName
())
}
// Restore checkpoint
channel
,
ch
,
config
:=
createPodConfigTesterByChannel
(
PodConfigNotificationIncremental
,
kubetypes
.
ApiserverSource
)
if
err
:=
config
.
Restore
(
tmpDir
,
channel
);
err
!=
nil
{
t
.
Fatalf
(
"Restore returned error: %v"
,
err
)
}
expectPodUpdate
(
t
,
ch
,
CreatePodUpdate
(
kubetypes
.
RESTORE
,
kubetypes
.
ApiserverSource
,
pod
))
}
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