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
012acad3
Commit
012acad3
authored
Feb 14, 2017
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add CheckpointNotFound error
parent
95badd95
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
10 deletions
+48
-10
checkpoint_store.go
pkg/kubelet/dockershim/checkpoint_store.go
+8
-1
checkpoint_store_test.go
pkg/kubelet/dockershim/checkpoint_store_test.go
+2
-1
docker_checkpoint.go
pkg/kubelet/dockershim/docker_checkpoint.go
+3
-4
docker_sandbox.go
pkg/kubelet/dockershim/docker_sandbox.go
+2
-1
docker_service.go
pkg/kubelet/dockershim/docker_service.go
+8
-1
errors.go
pkg/kubelet/dockershim/errors/errors.go
+22
-0
util.go
pkg/kubelet/dockershim/testing/util.go
+3
-2
No files found.
pkg/kubelet/dockershim/checkpoint_store.go
View file @
012acad3
...
...
@@ -23,6 +23,8 @@ import (
"path/filepath"
"regexp"
"strings"
"k8s.io/kubernetes/pkg/kubelet/dockershim/errors"
)
const
(
...
...
@@ -40,6 +42,7 @@ type CheckpointStore interface {
// Write persists a checkpoint with key
Write
(
key
string
,
data
[]
byte
)
error
// Read retrieves a checkpoint with key
// Read must return CheckpointNotFoundError if checkpoint is not found
Read
(
key
string
)
([]
byte
,
error
)
// Delete deletes a checkpoint with key
// Delete must not return error if checkpoint does not exist
...
...
@@ -75,7 +78,11 @@ func (fstore *FileStore) Read(key string) ([]byte, error) {
if
err
:=
validateKey
(
key
);
err
!=
nil
{
return
nil
,
err
}
return
ioutil
.
ReadFile
(
fstore
.
getCheckpointPath
(
key
))
bytes
,
err
:=
ioutil
.
ReadFile
(
fstore
.
getCheckpointPath
(
key
))
if
os
.
IsNotExist
(
err
)
{
return
bytes
,
errors
.
CheckpointNotFoundError
}
return
bytes
,
err
}
func
(
fstore
*
FileStore
)
Delete
(
key
string
)
error
{
...
...
pkg/kubelet/dockershim/checkpoint_store_test.go
View file @
012acad3
...
...
@@ -23,6 +23,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/kubernetes/pkg/kubelet/dockershim/errors"
)
func
TestFileStore
(
t
*
testing
.
T
)
{
...
...
@@ -102,7 +103,7 @@ func TestFileStore(t *testing.T) {
err
=
store
.
Delete
(
c
.
key
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
store
.
Read
(
c
.
key
)
assert
.
E
rror
(
t
,
err
)
assert
.
E
qualValues
(
t
,
errors
.
CheckpointNotFoundError
,
err
)
}
// Test delete non existed checkpoint
...
...
pkg/kubelet/dockershim/docker_checkpoint.go
View file @
012acad3
...
...
@@ -23,6 +23,7 @@ import (
"path/filepath"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/kubelet/dockershim/errors"
hashutil
"k8s.io/kubernetes/pkg/util/hash"
)
...
...
@@ -34,8 +35,6 @@ const (
schemaVersion
=
"v1"
)
var
CorruptCheckpointError
=
fmt
.
Errorf
(
"checkpoint is corrupted."
)
type
Protocol
string
// PortMapping is the port mapping configurations of a sandbox.
...
...
@@ -108,11 +107,11 @@ func (handler *PersistentCheckpointHandler) GetCheckpoint(podSandboxID string) (
err
=
json
.
Unmarshal
(
blob
,
&
checkpoint
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to unmarshal checkpoint %q. Checkpoint content: %q. ErrMsg: %v"
,
podSandboxID
,
string
(
blob
),
err
)
return
&
checkpoint
,
CorruptCheckpointError
return
&
checkpoint
,
errors
.
CorruptCheckpointError
}
if
checkpoint
.
CheckSum
!=
calculateChecksum
(
checkpoint
)
{
glog
.
Errorf
(
"Checksum of checkpoint %q is not valid"
,
podSandboxID
)
return
&
checkpoint
,
CorruptCheckpointError
return
&
checkpoint
,
errors
.
CorruptCheckpointError
}
return
&
checkpoint
,
nil
}
...
...
pkg/kubelet/dockershim/docker_sandbox.go
View file @
012acad3
...
...
@@ -27,6 +27,7 @@ import (
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockershim/errors"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/qos"
"k8s.io/kubernetes/pkg/kubelet/types"
...
...
@@ -355,7 +356,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to retrieve checkpoint for sandbox %q: %v"
,
id
,
err
)
if
err
==
CorruptCheckpointError
{
if
err
==
errors
.
CorruptCheckpointError
{
glog
.
V
(
2
)
.
Info
(
"Removing corrupted checkpoint %q: %+v"
,
id
,
*
checkpoint
)
ds
.
checkpointHandler
.
RemoveCheckpoint
(
id
)
}
...
...
pkg/kubelet/dockershim/docker_service.go
View file @
012acad3
...
...
@@ -32,6 +32,7 @@ import (
kubecm
"k8s.io/kubernetes/pkg/kubelet/cm"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockershim/cm"
"k8s.io/kubernetes/pkg/kubelet/dockershim/errors"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/network"
"k8s.io/kubernetes/pkg/kubelet/network/cni"
...
...
@@ -292,8 +293,14 @@ func (ds *dockerService) GetNetNS(podSandboxID string) (string, error) {
func
(
ds
*
dockerService
)
GetPodPortMappings
(
podSandboxID
string
)
([]
*
hostport
.
PortMapping
,
error
)
{
// TODO: get portmappings from docker labels for backward compatibility
checkpoint
,
err
:=
ds
.
checkpointHandler
.
GetCheckpoint
(
podSandboxID
)
// Return empty portMappings if checkpoint is not found
if
err
!=
nil
{
return
nil
,
err
if
err
==
errors
.
CheckpointNotFoundError
{
glog
.
Warningf
(
"Failed to retrieve checkpoint for sandbox %q: %v"
,
err
)
return
nil
,
nil
}
else
{
return
nil
,
err
}
}
portMappings
:=
[]
*
hostport
.
PortMapping
{}
...
...
pkg/kubelet/dockershim/errors/errors.go
0 → 100644
View file @
012acad3
/*
Copyright 2017 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
errors
import
"fmt"
var
CorruptCheckpointError
=
fmt
.
Errorf
(
"checkpoint is corrupted."
)
var
CheckpointNotFoundError
=
fmt
.
Errorf
(
"checkpoint is not found."
)
pkg/kubelet/dockershim/testing/util.go
View file @
012acad3
...
...
@@ -17,8 +17,9 @@ limitations under the License.
package
testing
import
(
"fmt"
"sync"
"k8s.io/kubernetes/pkg/kubelet/dockershim/errors"
)
// MemStore is an implementation of CheckpointStore interface which stores checkpoint in memory.
...
...
@@ -43,7 +44,7 @@ func (mstore *MemStore) Read(key string) ([]byte, error) {
defer
mstore
.
Unlock
()
data
,
ok
:=
mstore
.
mem
[
key
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"checkpoint %q could not be found"
,
key
)
return
nil
,
errors
.
CheckpointNotFoundError
}
return
data
,
nil
}
...
...
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