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
de1063bc
Commit
de1063bc
authored
May 21, 2018
by
Klaudiusz Dembler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add compatibility tests
parent
3d09101b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
20 deletions
+100
-20
cpu_manager.go
pkg/kubelet/cm/cpumanager/cpu_manager.go
+3
-3
state_checkpoint.go
pkg/kubelet/cm/cpumanager/state/state_checkpoint.go
+6
-7
state_checkpoint_test.go
pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go
+13
-10
state_compatibility_test.go
pkg/kubelet/cm/cpumanager/state/state_compatibility_test.go
+78
-0
No files found.
pkg/kubelet/cm/cpumanager/cpu_manager.go
View file @
de1063bc
...
@@ -44,8 +44,8 @@ type runtimeService interface {
...
@@ -44,8 +44,8 @@ type runtimeService interface {
type
policyName
string
type
policyName
string
//
CPU
ManagerStateFileName is the name file name where cpu manager stores it's state
//
cpu
ManagerStateFileName is the name file name where cpu manager stores it's state
const
CPU
ManagerStateFileName
=
"cpu_manager_state"
const
cpu
ManagerStateFileName
=
"cpu_manager_state"
// Manager interface provides methods for Kubelet to manage pod cpus.
// Manager interface provides methods for Kubelet to manage pod cpus.
type
Manager
interface
{
type
Manager
interface
{
...
@@ -136,7 +136,7 @@ func NewManager(cpuPolicyName string, reconcilePeriod time.Duration, machineInfo
...
@@ -136,7 +136,7 @@ func NewManager(cpuPolicyName string, reconcilePeriod time.Duration, machineInfo
policy
=
NewNonePolicy
()
policy
=
NewNonePolicy
()
}
}
stateImpl
,
err
:=
state
.
NewCheckpointState
(
stateFileDirecory
,
policy
.
Name
())
stateImpl
,
err
:=
state
.
NewCheckpointState
(
stateFileDirecory
,
cpuManagerStateFileName
,
policy
.
Name
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not initialize checkpoint manager: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"could not initialize checkpoint manager: %v"
,
err
)
}
}
...
...
pkg/kubelet/cm/cpumanager/state/state_checkpoint.go
View file @
de1063bc
...
@@ -27,9 +27,6 @@ import (
...
@@ -27,9 +27,6 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
)
)
// cpuManagerCheckpointName is the name of checkpoint file
const
cpuManagerCheckpointName
=
"cpu_manager_state"
var
_
State
=
&
stateCheckpoint
{}
var
_
State
=
&
stateCheckpoint
{}
type
stateCheckpoint
struct
{
type
stateCheckpoint
struct
{
...
@@ -37,10 +34,11 @@ type stateCheckpoint struct {
...
@@ -37,10 +34,11 @@ type stateCheckpoint struct {
policyName
string
policyName
string
cache
State
cache
State
checkpointManager
checkpointmanager
.
CheckpointManager
checkpointManager
checkpointmanager
.
CheckpointManager
checkpointName
string
}
}
// NewCheckpointState creates new State for keeping track of cpu/pod assignment with checkpoint backend
// NewCheckpointState creates new State for keeping track of cpu/pod assignment with checkpoint backend
func
NewCheckpointState
(
stateDir
string
,
policyName
string
)
(
State
,
error
)
{
func
NewCheckpointState
(
stateDir
,
checkpointName
,
policyName
string
)
(
State
,
error
)
{
checkpointManager
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
stateDir
)
checkpointManager
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
stateDir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to initialize checkpoint manager: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to initialize checkpoint manager: %v"
,
err
)
...
@@ -49,12 +47,13 @@ func NewCheckpointState(stateDir string, policyName string) (State, error) {
...
@@ -49,12 +47,13 @@ func NewCheckpointState(stateDir string, policyName string) (State, error) {
cache
:
NewMemoryState
(),
cache
:
NewMemoryState
(),
policyName
:
policyName
,
policyName
:
policyName
,
checkpointManager
:
checkpointManager
,
checkpointManager
:
checkpointManager
,
checkpointName
:
checkpointName
,
}
}
if
err
:=
stateCheckpoint
.
restoreState
();
err
!=
nil
{
if
err
:=
stateCheckpoint
.
restoreState
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not restore state from checkpoint: %v
\n
"
+
return
nil
,
fmt
.
Errorf
(
"could not restore state from checkpoint: %v
\n
"
+
"Please drain this node and delete the CPU manager checkpoint file %q before restarting Kubelet."
,
"Please drain this node and delete the CPU manager checkpoint file %q before restarting Kubelet."
,
err
,
path
.
Join
(
stateDir
,
c
puManagerC
heckpointName
))
err
,
path
.
Join
(
stateDir
,
checkpointName
))
}
}
return
stateCheckpoint
,
nil
return
stateCheckpoint
,
nil
...
@@ -72,7 +71,7 @@ func (sc *stateCheckpoint) restoreState() error {
...
@@ -72,7 +71,7 @@ func (sc *stateCheckpoint) restoreState() error {
tmpContainerCPUSet
:=
cpuset
.
NewCPUSet
()
tmpContainerCPUSet
:=
cpuset
.
NewCPUSet
()
checkpoint
:=
NewCPUManagerCheckpoint
()
checkpoint
:=
NewCPUManagerCheckpoint
()
if
err
=
sc
.
checkpointManager
.
GetCheckpoint
(
cpuManagerC
heckpointName
,
checkpoint
);
err
!=
nil
{
if
err
=
sc
.
checkpointManager
.
GetCheckpoint
(
sc
.
c
heckpointName
,
checkpoint
);
err
!=
nil
{
if
err
==
errors
.
ErrCheckpointNotFound
{
if
err
==
errors
.
ErrCheckpointNotFound
{
sc
.
storeState
()
sc
.
storeState
()
return
nil
return
nil
...
@@ -114,7 +113,7 @@ func (sc *stateCheckpoint) storeState() {
...
@@ -114,7 +113,7 @@ func (sc *stateCheckpoint) storeState() {
checkpoint
.
Entries
[
containerID
]
=
cset
.
String
()
checkpoint
.
Entries
[
containerID
]
=
cset
.
String
()
}
}
err
:=
sc
.
checkpointManager
.
CreateCheckpoint
(
cpuManagerC
heckpointName
,
checkpoint
)
err
:=
sc
.
checkpointManager
.
CreateCheckpoint
(
sc
.
c
heckpointName
,
checkpoint
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
"[cpumanager] could not save checkpoint: "
+
err
.
Error
())
panic
(
"[cpumanager] could not save checkpoint: "
+
err
.
Error
())
...
...
pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go
View file @
de1063bc
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
state
package
state
import
(
import
(
"os"
"strings"
"strings"
"testing"
"testing"
...
@@ -25,7 +26,9 @@ import (
...
@@ -25,7 +26,9 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
)
)
const
testingDir
=
"/tmp"
const
testingCheckpoint
=
"cpumanager_checkpoint_test"
var
testingDir
=
os
.
TempDir
()
func
TestCheckpointStateRestore
(
t
*
testing
.
T
)
{
func
TestCheckpointStateRestore
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
...
@@ -146,17 +149,17 @@ func TestCheckpointStateRestore(t *testing.T) {
...
@@ -146,17 +149,17 @@ func TestCheckpointStateRestore(t *testing.T) {
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
// ensure there is no previous checkpoint
// ensure there is no previous checkpoint
cpm
.
RemoveCheckpoint
(
cpuManagerCheckpointName
)
cpm
.
RemoveCheckpoint
(
testingCheckpoint
)
// prepare checkpoint for testing
// prepare checkpoint for testing
if
strings
.
TrimSpace
(
tc
.
checkpointContent
)
!=
""
{
if
strings
.
TrimSpace
(
tc
.
checkpointContent
)
!=
""
{
checkpoint
:=
&
testutil
.
MockCheckpoint
{
Content
:
tc
.
checkpointContent
}
checkpoint
:=
&
testutil
.
MockCheckpoint
{
Content
:
tc
.
checkpointContent
}
if
err
:=
cpm
.
CreateCheckpoint
(
cpuManagerCheckpointName
,
checkpoint
);
err
!=
nil
{
if
err
:=
cpm
.
CreateCheckpoint
(
testingCheckpoint
,
checkpoint
);
err
!=
nil
{
t
.
Fatalf
(
"could not create testing checkpoint: %v"
,
err
)
t
.
Fatalf
(
"could not create testing checkpoint: %v"
,
err
)
}
}
}
}
restoredState
,
err
:=
NewCheckpointState
(
testingDir
,
tc
.
policyName
)
restoredState
,
err
:=
NewCheckpointState
(
testingDir
,
t
estingCheckpoint
,
t
c
.
policyName
)
if
err
!=
nil
{
if
err
!=
nil
{
if
strings
.
TrimSpace
(
tc
.
expectedError
)
!=
""
{
if
strings
.
TrimSpace
(
tc
.
expectedError
)
!=
""
{
tc
.
expectedError
=
"could not restore state from checkpoint: "
+
tc
.
expectedError
tc
.
expectedError
=
"could not restore state from checkpoint: "
+
tc
.
expectedError
...
@@ -201,9 +204,9 @@ func TestCheckpointStateStore(t *testing.T) {
...
@@ -201,9 +204,9 @@ func TestCheckpointStateStore(t *testing.T) {
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
// ensure there is no previous checkpoint
// ensure there is no previous checkpoint
cpm
.
RemoveCheckpoint
(
cpuManagerCheckpointName
)
cpm
.
RemoveCheckpoint
(
testingCheckpoint
)
cs1
,
err
:=
NewCheckpointState
(
testingDir
,
"none"
)
cs1
,
err
:=
NewCheckpointState
(
testingDir
,
testingCheckpoint
,
"none"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
}
}
...
@@ -213,7 +216,7 @@ func TestCheckpointStateStore(t *testing.T) {
...
@@ -213,7 +216,7 @@ func TestCheckpointStateStore(t *testing.T) {
cs1
.
SetCPUAssignments
(
tc
.
expectedState
.
assignments
)
cs1
.
SetCPUAssignments
(
tc
.
expectedState
.
assignments
)
// restore checkpoint with previously stored values
// restore checkpoint with previously stored values
cs2
,
err
:=
NewCheckpointState
(
testingDir
,
"none"
)
cs2
,
err
:=
NewCheckpointState
(
testingDir
,
testingCheckpoint
,
"none"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
}
}
...
@@ -261,9 +264,9 @@ func TestCheckpointStateHelpers(t *testing.T) {
...
@@ -261,9 +264,9 @@ func TestCheckpointStateHelpers(t *testing.T) {
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
// ensure there is no previous checkpoint
// ensure there is no previous checkpoint
cpm
.
RemoveCheckpoint
(
cpuManagerCheckpointName
)
cpm
.
RemoveCheckpoint
(
testingCheckpoint
)
state
,
err
:=
NewCheckpointState
(
testingDir
,
"none"
)
state
,
err
:=
NewCheckpointState
(
testingDir
,
testingCheckpoint
,
"none"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
}
}
...
@@ -301,7 +304,7 @@ func TestCheckpointStateClear(t *testing.T) {
...
@@ -301,7 +304,7 @@ func TestCheckpointStateClear(t *testing.T) {
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
state
,
err
:=
NewCheckpointState
(
testingDir
,
"none"
)
state
,
err
:=
NewCheckpointState
(
testingDir
,
testingCheckpoint
,
"none"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
t
.
Fatalf
(
"could not create testing checkpointState instance: %v"
,
err
)
}
}
...
...
pkg/kubelet/cm/cpumanager/state/state_compatibility_test.go
0 → 100644
View file @
de1063bc
/*
Copyright 2018 The Kubernetes Authors.
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
state
import
(
"os"
"path"
"testing"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
)
const
compatibilityTestingCheckpoint
=
"cpumanager_state_compatibility_test"
var
state
=
&
stateMemory
{
assignments
:
ContainerCPUAssignments
{
"container1"
:
cpuset
.
NewCPUSet
(
4
,
5
,
6
),
"container2"
:
cpuset
.
NewCPUSet
(
1
,
2
,
3
),
},
defaultCPUSet
:
cpuset
.
NewCPUSet
(
1
,
2
,
3
),
}
func
TestFileToCheckpointCompatibility
(
t
*
testing
.
T
)
{
statePath
:=
path
.
Join
(
testingDir
,
compatibilityTestingCheckpoint
)
// ensure there is no previous state saved at testing path
os
.
Remove
(
statePath
)
// ensure testing state is removed after testing
defer
os
.
Remove
(
statePath
)
fileState
:=
NewFileState
(
statePath
,
"none"
)
fileState
.
SetDefaultCPUSet
(
state
.
defaultCPUSet
)
fileState
.
SetCPUAssignments
(
state
.
assignments
)
restoredState
,
err
:=
NewCheckpointState
(
testingDir
,
compatibilityTestingCheckpoint
,
"none"
)
if
err
!=
nil
{
t
.
Fatalf
(
"could not restore file state: %v"
,
err
)
}
AssertStateEqual
(
t
,
restoredState
,
state
)
}
func
TestCheckpointToFileCompatibility
(
t
*
testing
.
T
)
{
cpm
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
testingDir
)
if
err
!=
nil
{
t
.
Fatalf
(
"could not create testing checkpoint manager: %v"
,
err
)
}
// ensure there is no previous checkpoint
cpm
.
RemoveCheckpoint
(
compatibilityTestingCheckpoint
)
// ensure testing checkpoint is removed after testing
defer
cpm
.
RemoveCheckpoint
(
compatibilityTestingCheckpoint
)
checkpointState
,
err
:=
NewCheckpointState
(
testingDir
,
compatibilityTestingCheckpoint
,
"none"
)
checkpointState
.
SetDefaultCPUSet
(
state
.
defaultCPUSet
)
checkpointState
.
SetCPUAssignments
(
state
.
assignments
)
restoredState
:=
NewFileState
(
path
.
Join
(
testingDir
,
compatibilityTestingCheckpoint
),
"none"
)
AssertStateEqual
(
t
,
restoredState
,
state
)
}
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