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
ae2aece9
Commit
ae2aece9
authored
Feb 02, 2016
by
Jeff Lowdermilk
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20202 from caesarxuchao/skip-update
skip update when deleting with grace-period=0
parents
136c1f9d
a6d96a04
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
23 deletions
+42
-23
resttest.go
pkg/api/rest/resttest/resttest.go
+2
-1
runtime.go
pkg/kubelet/container/runtime.go
+8
-0
kubelet.go
pkg/kubelet/kubelet.go
+24
-18
kubelet_test.go
pkg/kubelet/kubelet_test.go
+1
-1
etcd.go
pkg/registry/generic/etcd/etcd.go
+1
-1
pods.go
test/e2e/pods.go
+6
-2
No files found.
pkg/api/rest/resttest/resttest.go
View file @
ae2aece9
...
...
@@ -673,7 +673,8 @@ func (t *Tester) testDeleteGracefulImmediate(obj runtime.Object, setFn SetFunc,
t
.
Errorf
(
"unexpected error, object should be deleted immediately: %v"
,
err
)
}
objectMeta
=
t
.
getObjectMetaOrFail
(
out
)
if
objectMeta
.
DeletionTimestamp
==
nil
||
objectMeta
.
DeletionGracePeriodSeconds
==
nil
||
*
objectMeta
.
DeletionGracePeriodSeconds
!=
0
{
// the second delete shouldn't update the object, so the objectMeta.DeletionGracePeriodSeconds should eqaul to the value set in the first delete.
if
objectMeta
.
DeletionTimestamp
==
nil
||
objectMeta
.
DeletionGracePeriodSeconds
==
nil
||
*
objectMeta
.
DeletionGracePeriodSeconds
!=
expectedGrace
{
t
.
Errorf
(
"unexpected deleted meta: %#v"
,
objectMeta
)
}
}
...
...
pkg/kubelet/container/runtime.go
View file @
ae2aece9
...
...
@@ -141,6 +141,14 @@ type Pod struct {
Containers
[]
*
Container
}
// PodPair contains both runtime#Pod and api#Pod
type
PodPair
struct
{
// APIPod is the api.Pod
APIPod
*
api
.
Pod
// RunningPod is the pod defined defined in pkg/kubelet/container/runtime#Pod
RunningPod
*
Pod
}
// ContainerID is a type that identifies a container.
type
ContainerID
struct
{
// The type of the container runtime. e.g. 'docker', 'rkt'.
...
...
pkg/kubelet/kubelet.go
View file @
ae2aece9
...
...
@@ -450,7 +450,7 @@ func NewMainKubelet(
klet
.
podWorkers
=
newPodWorkers
(
klet
.
syncPod
,
recorder
,
klet
.
workQueue
,
klet
.
resyncInterval
,
backOffPeriod
,
klet
.
podCache
)
klet
.
backOff
=
util
.
NewBackOff
(
backOffPeriod
,
MaxContainerBackOff
)
klet
.
podKillingCh
=
make
(
chan
*
kubecontainer
.
Pod
,
podKillingChannelCapacity
)
klet
.
podKillingCh
=
make
(
chan
*
kubecontainer
.
Pod
Pair
,
podKillingChannelCapacity
)
klet
.
sourcesSeen
=
sets
.
NewString
()
return
klet
,
nil
}
...
...
@@ -632,7 +632,7 @@ type Kubelet struct {
backOff
*
util
.
Backoff
// Channel for sending pods to kill.
podKillingCh
chan
*
kubecontainer
.
Pod
podKillingCh
chan
*
kubecontainer
.
Pod
Pair
// The configuration file used as the base to generate the container's
// DNS resolver configuration file. This can be used in conjunction with
...
...
@@ -1961,13 +1961,16 @@ func (kl *Kubelet) removeOrphanedPodStatuses(pods []*api.Pod, mirrorPods []*api.
kl
.
statusManager
.
RemoveOrphanedStatuses
(
podUIDs
)
}
func
(
kl
*
Kubelet
)
deletePod
(
uid
types
.
UID
)
error
{
func
(
kl
*
Kubelet
)
deletePod
(
pod
*
api
.
Pod
)
error
{
if
pod
==
nil
{
return
fmt
.
Errorf
(
"deletePod does not allow nil pod"
)
}
if
!
kl
.
allSourcesReady
()
{
// If the sources aren't ready, skip deletion, as we may accidentally delete pods
// for sources that haven't reported yet.
return
fmt
.
Errorf
(
"skipping delete because sources aren't ready yet"
)
}
kl
.
podWorkers
.
ForgetWorker
(
uid
)
kl
.
podWorkers
.
ForgetWorker
(
pod
.
UID
)
// Runtime cache may not have been updated to with the pod, but it's okay
// because the periodic cleanup routine will attempt to delete again later.
...
...
@@ -1975,12 +1978,13 @@ func (kl *Kubelet) deletePod(uid types.UID) error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error listing containers: %v"
,
err
)
}
pod
:=
kubecontainer
.
Pods
(
runningPods
)
.
FindPod
(
""
,
uid
)
if
p
od
.
IsEmpty
()
{
runningPod
:=
kubecontainer
.
Pods
(
runningPods
)
.
FindPod
(
""
,
pod
.
UID
)
if
runningP
od
.
IsEmpty
()
{
return
fmt
.
Errorf
(
"pod not found"
)
}
podPair
:=
kubecontainer
.
PodPair
{
pod
,
&
runningPod
}
kl
.
podKillingCh
<-
&
pod
kl
.
podKillingCh
<-
&
pod
Pair
// TODO: delete the mirror pod here?
// We leave the volume/directory cleanup to the periodic cleanup routine.
...
...
@@ -2023,7 +2027,7 @@ func (kl *Kubelet) HandlePodCleanups() error {
}
for
_
,
pod
:=
range
runningPods
{
if
_
,
found
:=
desiredPods
[
pod
.
ID
];
!
found
{
kl
.
podKillingCh
<-
pod
kl
.
podKillingCh
<-
&
kubecontainer
.
PodPair
{
nil
,
pod
}
}
}
...
...
@@ -2082,25 +2086,27 @@ func (kl *Kubelet) podKiller() {
defer
close
(
resultCh
)
for
{
select
{
case
pod
,
ok
:=
<-
kl
.
podKillingCh
:
case
podPair
,
ok
:=
<-
kl
.
podKillingCh
:
runningPod
:=
podPair
.
RunningPod
apiPod
:=
podPair
.
APIPod
if
!
ok
{
return
}
if
killing
.
Has
(
string
(
p
od
.
ID
))
{
if
killing
.
Has
(
string
(
runningP
od
.
ID
))
{
// The pod is already being killed.
break
}
killing
.
Insert
(
string
(
p
od
.
ID
))
go
func
(
p
od
*
kubecontainer
.
Pod
,
ch
chan
types
.
UID
)
{
killing
.
Insert
(
string
(
runningP
od
.
ID
))
go
func
(
apiPod
*
api
.
Pod
,
runningP
od
*
kubecontainer
.
Pod
,
ch
chan
types
.
UID
)
{
defer
func
()
{
ch
<-
p
od
.
ID
ch
<-
runningP
od
.
ID
}()
glog
.
V
(
2
)
.
Infof
(
"Killing unwanted pod %q"
,
p
od
.
Name
)
err
:=
kl
.
killPod
(
nil
,
p
od
,
nil
)
glog
.
V
(
2
)
.
Infof
(
"Killing unwanted pod %q"
,
runningP
od
.
Name
)
err
:=
kl
.
killPod
(
apiPod
,
runningP
od
,
nil
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed killing the pod %q: %v"
,
p
od
.
Name
,
err
)
glog
.
Errorf
(
"Failed killing the pod %q: %v"
,
runningP
od
.
Name
,
err
)
}
}(
p
od
,
resultCh
)
}(
apiPod
,
runningP
od
,
resultCh
)
case
podID
:=
<-
resultCh
:
killing
.
Delete
(
string
(
podID
))
...
...
@@ -2388,7 +2394,7 @@ func (kl *Kubelet) HandlePodDeletions(pods []*api.Pod) {
}
// Deletion is allowed to fail because the periodic cleanup routine
// will trigger deletion again.
if
err
:=
kl
.
deletePod
(
pod
.
UID
);
err
!=
nil
{
if
err
:=
kl
.
deletePod
(
pod
);
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"Failed to delete pod %q, err: %v"
,
format
.
Pod
(
pod
),
err
)
}
kl
.
probeManager
.
RemovePod
(
pod
)
...
...
pkg/kubelet/kubelet_test.go
View file @
ae2aece9
...
...
@@ -176,7 +176,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
fakeClock
:=
util
.
NewFakeClock
(
time
.
Now
())
kubelet
.
backOff
=
util
.
NewBackOff
(
time
.
Second
,
time
.
Minute
)
kubelet
.
backOff
.
Clock
=
fakeClock
kubelet
.
podKillingCh
=
make
(
chan
*
kubecontainer
.
Pod
,
20
)
kubelet
.
podKillingCh
=
make
(
chan
*
kubecontainer
.
Pod
Pair
,
20
)
kubelet
.
resyncInterval
=
10
*
time
.
Second
kubelet
.
reservation
=
kubetypes
.
Reservation
{
Kubernetes
:
api
.
ResourceList
{
...
...
pkg/registry/generic/etcd/etcd.go
View file @
ae2aece9
...
...
@@ -387,7 +387,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
if
pendingGraceful
{
return
e
.
finalizeDelete
(
obj
,
false
)
}
if
graceful
{
if
graceful
&&
*
options
.
GracePeriodSeconds
>
0
{
out
:=
e
.
NewFunc
()
lastGraceful
:=
int64
(
0
)
err
:=
e
.
Storage
.
GuaranteedUpdate
(
...
...
test/e2e/pods.go
View file @
ae2aece9
...
...
@@ -343,8 +343,12 @@ var _ = Describe("Pods", func() {
Fail
(
"Timeout while waiting for pod creation"
)
}
// We need to wait for the pod to be scheduled, otherwise the deletion
// will be carried out immediately rather than gracefully.
expectNoError
(
framework
.
WaitForPodRunning
(
pod
.
Name
))
By
(
"deleting the pod gracefully"
)
if
err
:=
podClient
.
Delete
(
pod
.
Name
,
nil
);
err
!=
nil
{
if
err
:=
podClient
.
Delete
(
pod
.
Name
,
api
.
NewDeleteOptions
(
30
)
);
err
!=
nil
{
Failf
(
"Failed to delete pod: %v"
,
err
)
}
...
...
@@ -352,7 +356,7 @@ var _ = Describe("Pods", func() {
deleted
:=
false
timeout
:=
false
var
lastPod
*
api
.
Pod
timer
:=
time
.
After
(
podStartTimeout
)
timer
:=
time
.
After
(
30
*
time
.
Second
)
for
!
deleted
&&
!
timeout
{
select
{
case
event
,
_
:=
<-
w
.
ResultChan
()
:
...
...
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