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
ddf624ef
Commit
ddf624ef
authored
Nov 30, 2016
by
ymqytw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add retry logic for eviction
parent
1e09f64a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
BUILD
pkg/registry/core/pod/etcd/BUILD
+2
-0
eviction.go
pkg/registry/core/pod/etcd/eviction.go
+29
-6
No files found.
pkg/registry/core/pod/etcd/BUILD
View file @
ddf624ef
...
@@ -26,6 +26,7 @@ go_library(
...
@@ -26,6 +26,7 @@ go_library(
"//pkg/api/validation:go_default_library",
"//pkg/api/validation:go_default_library",
"//pkg/apis/policy:go_default_library",
"//pkg/apis/policy:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/policy/internalversion:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/policy/internalversion:go_default_library",
"//pkg/client/retry:go_default_library",
"//pkg/kubelet/client:go_default_library",
"//pkg/kubelet/client:go_default_library",
"//pkg/labels:go_default_library",
"//pkg/labels:go_default_library",
"//pkg/registry/cachesize:go_default_library",
"//pkg/registry/cachesize:go_default_library",
...
@@ -35,6 +36,7 @@ go_library(
...
@@ -35,6 +36,7 @@ go_library(
"//pkg/registry/generic/registry:go_default_library",
"//pkg/registry/generic/registry:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/storage:go_default_library",
"//pkg/storage:go_default_library",
"//pkg/util/wait:go_default_library",
],
],
)
)
...
...
pkg/registry/core/pod/etcd/eviction.go
View file @
ddf624ef
...
@@ -25,9 +25,11 @@ import (
...
@@ -25,9 +25,11 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/policy"
policyclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/policy/internalversion"
policyclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/policy/internalversion"
"k8s.io/kubernetes/pkg/client/retry"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/generic/registry"
"k8s.io/kubernetes/pkg/registry/generic/registry"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/wait"
)
)
const
(
const
(
...
@@ -40,6 +42,15 @@ const (
...
@@ -40,6 +42,15 @@ const (
MaxDisruptedPodSize
=
2000
MaxDisruptedPodSize
=
2000
)
)
// EvictionsRetry is the retry for a conflict where multiple clients
// are making changes to the same resource.
var
EvictionsRetry
=
wait
.
Backoff
{
Steps
:
20
,
Duration
:
500
*
time
.
Millisecond
,
Factor
:
1.0
,
Jitter
:
0.1
,
}
func
newEvictionStorage
(
store
*
registry
.
Store
,
podDisruptionBudgetClient
policyclient
.
PodDisruptionBudgetsGetter
)
*
EvictionREST
{
func
newEvictionStorage
(
store
*
registry
.
Store
,
podDisruptionBudgetClient
policyclient
.
PodDisruptionBudgetsGetter
)
*
EvictionREST
{
return
&
EvictionREST
{
store
:
store
,
podDisruptionBudgetClient
:
podDisruptionBudgetClient
}
return
&
EvictionREST
{
store
:
store
,
podDisruptionBudgetClient
:
podDisruptionBudgetClient
}
}
}
...
@@ -66,17 +77,20 @@ func (r *EvictionREST) Create(ctx api.Context, obj runtime.Object) (runtime.Obje
...
@@ -66,17 +77,20 @@ func (r *EvictionREST) Create(ctx api.Context, obj runtime.Object) (runtime.Obje
return
nil
,
err
return
nil
,
err
}
}
pod
:=
obj
.
(
*
api
.
Pod
)
pod
:=
obj
.
(
*
api
.
Pod
)
var
rtStatus
*
unversioned
.
Status
err
=
retry
.
RetryOnConflict
(
EvictionsRetry
,
func
()
error
{
pdbs
,
err
:=
r
.
getPodDisruptionBudgets
(
ctx
,
pod
)
pdbs
,
err
:=
r
.
getPodDisruptionBudgets
(
ctx
,
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
err
}
}
if
len
(
pdbs
)
>
1
{
if
len
(
pdbs
)
>
1
{
return
&
unversioned
.
Status
{
rtStatus
=
&
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
Message
:
"This pod has more than one PodDisruptionBudget, which the eviction subresource does not support."
,
Message
:
"This pod has more than one PodDisruptionBudget, which the eviction subresource does not support."
,
Code
:
500
,
Code
:
500
,
},
nil
}
return
nil
}
else
if
len
(
pdbs
)
==
1
{
}
else
if
len
(
pdbs
)
==
1
{
pdb
:=
pdbs
[
0
]
pdb
:=
pdbs
[
0
]
// Try to verify-and-decrement
// Try to verify-and-decrement
...
@@ -85,11 +99,11 @@ func (r *EvictionREST) Create(ctx api.Context, obj runtime.Object) (runtime.Obje
...
@@ -85,11 +99,11 @@ func (r *EvictionREST) Create(ctx api.Context, obj runtime.Object) (runtime.Obje
// raise an error marked as a 429.
// raise an error marked as a 429.
ok
,
err
:=
r
.
checkAndDecrement
(
pod
.
Namespace
,
pod
.
Name
,
pdb
)
ok
,
err
:=
r
.
checkAndDecrement
(
pod
.
Namespace
,
pod
.
Name
,
pdb
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
err
}
}
if
!
ok
{
if
!
ok
{
return
&
unversioned
.
Status
{
rtStatus
=
&
unversioned
.
Status
{
Status
:
unversioned
.
StatusFailure
,
Status
:
unversioned
.
StatusFailure
,
// TODO(mml): Include some more details about why the eviction is disallowed.
// TODO(mml): Include some more details about why the eviction is disallowed.
// Ideally any such text is generated by the DisruptionController (offline).
// Ideally any such text is generated by the DisruptionController (offline).
...
@@ -99,9 +113,18 @@ func (r *EvictionREST) Create(ctx api.Context, obj runtime.Object) (runtime.Obje
...
@@ -99,9 +113,18 @@ func (r *EvictionREST) Create(ctx api.Context, obj runtime.Object) (runtime.Obje
// budgets, we can sometimes compute a sensible suggested value. But
// budgets, we can sometimes compute a sensible suggested value. But
// even without that, we can give a suggestion (10 minutes?) that
// even without that, we can give a suggestion (10 minutes?) that
// prevents well-behaved clients from hammering us.
// prevents well-behaved clients from hammering us.
},
nil
}
}
}
}
}
return
nil
})
if
err
!=
nil
{
return
nil
,
err
}
if
rtStatus
!=
nil
{
return
rtStatus
,
nil
}
// At this point there was either no PDB or we succeded in decrementing
// At this point there was either no PDB or we succeded in decrementing
...
...
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