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
7bb047ec
Commit
7bb047ec
authored
May 15, 2018
by
Klaudiusz Dembler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rebase and backward compatibility
parent
ba8d82c9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
41 deletions
+31
-41
BUILD
pkg/kubelet/cm/cpumanager/state/BUILD
+1
-2
checkpoint.go
pkg/kubelet/cm/cpumanager/state/checkpoint.go
+22
-27
state_checkpoint.go
pkg/kubelet/cm/cpumanager/state/state_checkpoint.go
+0
-1
state_checkpoint_test.go
pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go
+5
-5
util.go
pkg/kubelet/cm/cpumanager/state/testing/util.go
+3
-6
No files found.
pkg/kubelet/cm/cpumanager/state/BUILD
View file @
7bb047ec
...
...
@@ -13,10 +13,9 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/kubelet/checkpointmanager:go_default_library",
"//pkg/kubelet/checkpointmanager/checksum:go_default_library",
"//pkg/kubelet/checkpointmanager/errors:go_default_library",
"//pkg/kubelet/cm/cpuset:go_default_library",
"//pkg/kubelet/util/store:go_default_library",
"//pkg/util/hash:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
],
)
...
...
pkg/kubelet/cm/cpumanager/state/checkpoint.go
View file @
7bb047ec
...
...
@@ -18,55 +18,50 @@ package state
import
(
"encoding/json"
"hash/fnv"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
hashutil
"k8s.io/kubernetes/pkg/util/hash"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
)
var
_
checkpointmanager
.
Checkpoint
=
&
CPUManagerCheckpoint
{}
// CPUManagerCheckpoint struct is used to store cpu/pod assignments in a checkpoint
type
CPUManagerCheckpoint
struct
{
PolicyName
string
DefaultCPUSet
string
Entries
map
[
string
]
string
Checksum
uint64
PolicyName
string
`json:"policyName"`
DefaultCPUSet
string
`json:"defaultCpuSet"`
Entries
map
[
string
]
string
`json:"entries,omitempty"`
Checksum
checksum
.
Checksum
`json:"checksum"`
}
// NewCPUManagerCheckpoint returns an instance of Checkpoint
func
NewCPUManagerCheckpoint
()
*
CPUManagerCheckpoint
{
return
&
CPUManagerCheckpoint
{
Entries
:
make
(
map
[
string
]
string
)}
return
&
CPUManagerCheckpoint
{
Entries
:
make
(
map
[
string
]
string
),
}
}
// MarshalCheckpoint returns marshalled checkpoint
func
(
cp
*
CPUManagerCheckpoint
)
MarshalCheckpoint
()
([]
byte
,
error
)
{
// make sure checksum wasn't set before so it doesn't affect output checksum
cp
.
Checksum
=
0
cp
.
Checksum
=
checksum
.
New
(
cp
)
return
json
.
Marshal
(
*
cp
)
}
// UnmarshalCheckpoint tries to unmarshal passed bytes to checkpoint
func
(
cp
*
CPUManagerCheckpoint
)
UnmarshalCheckpoint
(
blob
[]
byte
)
error
{
if
err
:=
json
.
Unmarshal
(
blob
,
cp
);
err
!=
nil
{
return
err
}
if
cp
.
Checksum
!=
cp
.
GetChecksum
()
{
return
errors
.
ErrCorruptCheckpoint
}
return
nil
return
json
.
Unmarshal
(
blob
,
cp
)
}
// GetChecksum returns calculated checksum of checkpoint
func
(
cp
*
CPUManagerCheckpoint
)
GetChecksum
()
uint64
{
orig
:=
cp
.
Checksum
// VerifyChecksum verifies that current checksum of checkpoint is valid
func
(
cp
*
CPUManagerCheckpoint
)
VerifyChecksum
()
error
{
if
cp
.
Checksum
==
0
{
// accept empty checksum for compatibility with old file backend
return
nil
}
ck
:=
cp
.
Checksum
cp
.
Checksum
=
0
hash
:=
fnv
.
New32a
()
hashutil
.
DeepHashObject
(
hash
,
*
cp
)
cp
.
Checksum
=
orig
return
uint64
(
hash
.
Sum32
())
}
// UpdateChecksum calculates and updates checksum of the checkpoint
func
(
cp
*
CPUManagerCheckpoint
)
UpdateChecksum
()
{
cp
.
Checksum
=
cp
.
GetChecksum
()
err
:=
ck
.
Verify
(
cp
)
cp
.
Checksum
=
ck
return
err
}
pkg/kubelet/cm/cpumanager/state/state_checkpoint.go
View file @
7bb047ec
...
...
@@ -25,7 +25,6 @@ import (
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
utilstore
"k8s.io/kubernetes/pkg/kubelet/util/store"
)
// cpuManagerCheckpointName is the name of checkpoint file
...
...
pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go
View file @
7bb047ec
...
...
@@ -48,7 +48,7 @@ func TestCheckpointStateRestore(t *testing.T) {
"PolicyName": "none",
"DefaultCPUSet": "4-6",
"Entries": {},
"Checksum":
861251554
"Checksum":
2912033808
}`
,
"none"
,
""
,
...
...
@@ -65,7 +65,7 @@ func TestCheckpointStateRestore(t *testing.T) {
"container1": "4-6",
"container2": "1-3"
},
"Checksum":
2604807655
"Checksum":
1535905563
}`
,
"none"
,
""
,
...
...
@@ -102,7 +102,7 @@ func TestCheckpointStateRestore(t *testing.T) {
"PolicyName": "other",
"DefaultCPUSet": "1-3",
"Entries": {},
"Checksum": 4
266067046
"Checksum": 4
195836012
}`
,
"none"
,
`configured policy "none" differs from state checkpoint policy "other"`
,
...
...
@@ -114,7 +114,7 @@ func TestCheckpointStateRestore(t *testing.T) {
"PolicyName": "none",
"DefaultCPUSet": "1.3",
"Entries": {},
"Checksum":
4073769779
"Checksum":
1025273327
}`
,
"none"
,
`could not parse default cpu set "1.3": strconv.Atoi: parsing "1.3": invalid syntax`
,
...
...
@@ -129,7 +129,7 @@ func TestCheckpointStateRestore(t *testing.T) {
"container1": "4-6",
"container2": "asd"
},
"Checksum":
383548697
4
"Checksum":
276421392
4
}`
,
"none"
,
`could not parse cpuset "asd" for container id "container2": strconv.Atoi: parsing "asd": invalid syntax`
,
...
...
pkg/kubelet/cm/cpumanager/state/testing/util.go
View file @
7bb047ec
...
...
@@ -35,10 +35,7 @@ func (mc *MockCheckpoint) UnmarshalCheckpoint(blob []byte) error {
return
nil
}
//
GetChecksum fakes gett
ing checksum
func
(
mc
*
MockCheckpoint
)
GetChecksum
()
uint64
{
return
0
//
VerifyChecksum fakes verify
ing checksum
func
(
mc
*
MockCheckpoint
)
VerifyChecksum
()
error
{
return
nil
}
// UpdateChecksum fakes updating cheksum
func
(
mc
*
MockCheckpoint
)
UpdateChecksum
()
{}
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