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
4d6d9817
Commit
4d6d9817
authored
Nov 22, 2017
by
pospispa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PVC Being Deleted Checks in kubelet
Kubelet must not start pods that use PVCs that are being deleted.
parent
a258269c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
1 deletion
+109
-1
BUILD
pkg/kubelet/volumemanager/populator/BUILD
+1
-0
desired_state_of_world_populator.go
...lumemanager/populator/desired_state_of_world_populator.go
+20
-1
BUILD
pkg/volume/util/BUILD
+2
-0
finalizer.go
pkg/volume/util/finalizer.go
+28
-0
finalizer_test.go
pkg/volume/util/finalizer_test.go
+58
-0
No files found.
pkg/kubelet/volumemanager/populator/BUILD
View file @
4d6d9817
...
...
@@ -19,6 +19,7 @@ go_library(
"//pkg/kubelet/util/format:go_default_library",
"//pkg/kubelet/volumemanager/cache:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util/types:go_default_library",
"//pkg/volume/util/volumehelper:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
...
...
pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go
View file @
4d6d9817
...
...
@@ -41,6 +41,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/util/format"
"k8s.io/kubernetes/pkg/kubelet/volumemanager/cache"
"k8s.io/kubernetes/pkg/volume"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumetypes
"k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
...
...
@@ -419,7 +420,8 @@ func (dswp *desiredStateOfWorldPopulator) createVolumeSpec(
}
// getPVCExtractPV fetches the PVC object with the given namespace and name from
// the API server extracts the name of the PV it is pointing to and returns it.
// the API server, checks whether PVC is being deleted, extracts the name of the PV
// it is pointing to and returns it.
// An error is returned if the PVC object's phase is not "Bound".
func
(
dswp
*
desiredStateOfWorldPopulator
)
getPVCExtractPV
(
namespace
string
,
claimName
string
)
(
string
,
types
.
UID
,
error
)
{
...
...
@@ -433,6 +435,23 @@ func (dswp *desiredStateOfWorldPopulator) getPVCExtractPV(
err
)
}
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
PVCProtection
)
{
// Pods that uses a PVC that is being deleted must not be started.
//
// In case an old kubelet is running without this check or some kubelets
// have this feature disabled, the worst that can happen is that such
// pod is scheduled. This was the default behavior in 1.8 and earlier
// and users should not be that surprised.
// It should happen only in very rare case when scheduler schedules
// a pod and user deletes a PVC that's used by it at the same time.
if
volumeutil
.
IsPVCBeingDeleted
(
pvc
)
{
return
""
,
""
,
fmt
.
Errorf
(
"can't start pod because PVC %s/%s is being deleted"
,
namespace
,
claimName
)
}
}
if
pvc
.
Status
.
Phase
!=
v1
.
ClaimBound
||
pvc
.
Spec
.
VolumeName
==
""
{
return
""
,
""
,
fmt
.
Errorf
(
...
...
pkg/volume/util/BUILD
View file @
4d6d9817
...
...
@@ -14,6 +14,7 @@ go_library(
"device_util_unsupported.go",
"doc.go",
"error.go",
"finalizer.go",
"fs_unsupported.go",
"io_util.go",
"metrics.go",
...
...
@@ -61,6 +62,7 @@ go_library(
go_test(
name = "go_default_test",
srcs = [
"finalizer_test.go",
"util_test.go",
] + select({
"@io_bazel_rules_go//go/platform:linux_amd64": [
...
...
pkg/volume/util/finalizer.go
0 → 100644
View file @
4d6d9817
/*
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
util
import
(
"k8s.io/api/core/v1"
)
// IsPVCBeingDeleted returns:
// true: in case PVC is being deleted, i.e. ObjectMeta.DeletionTimestamp is set
// false: in case PVC is not being deleted, i.e. ObjectMeta.DeletionTimestamp is nil
func
IsPVCBeingDeleted
(
pvc
*
v1
.
PersistentVolumeClaim
)
bool
{
return
pvc
.
ObjectMeta
.
DeletionTimestamp
!=
nil
}
pkg/volume/util/finalizer_test.go
0 → 100644
View file @
4d6d9817
/*
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
util
import
(
"testing"
"time"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
var
(
arbitraryTime
=
metav1
.
Date
(
2017
,
11
,
1
,
14
,
28
,
47
,
0
,
time
.
FixedZone
(
"CET"
,
0
))
)
func
TestIsPVCBeingDeleted
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
pvc
*
v1
.
PersistentVolumeClaim
want
bool
}{
{
pvc
:
&
v1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
DeletionTimestamp
:
nil
,
},
},
want
:
false
,
},
{
pvc
:
&
v1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
DeletionTimestamp
:
&
arbitraryTime
,
},
},
want
:
true
,
},
}
for
_
,
tt
:=
range
tests
{
if
got
:=
IsPVCBeingDeleted
(
tt
.
pvc
);
got
!=
tt
.
want
{
t
.
Errorf
(
"IsPVCBeingDeleted(%v) = %v WANT %v"
,
tt
.
pvc
,
got
,
tt
.
want
)
}
}
}
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