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
de3f0978
Commit
de3f0978
authored
Jul 30, 2017
by
Mayank Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify disruption controller
parent
58c85e27
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
34 deletions
+22
-34
disruption.go
pkg/controller/disruption/disruption.go
+22
-34
No files found.
pkg/controller/disruption/disruption.go
View file @
de3f0978
...
...
@@ -107,7 +107,7 @@ type controllerAndScale struct {
// podControllerFinder is a function type that maps a pod to a list of
// controllers and their scale.
type
podControllerFinder
func
(
*
v1
.
Pod
)
(
[]
controllerAndScale
,
error
)
type
podControllerFinder
func
(
*
v1
.
Pod
)
(
*
controllerAndScale
,
error
)
func
NewDisruptionController
(
podInformer
coreinformers
.
PodInformer
,
...
...
@@ -170,8 +170,8 @@ func NewDisruptionController(
// and we may well need further tweaks just to be able to access scale
// subresources.
func
(
dc
*
DisruptionController
)
finders
()
[]
podControllerFinder
{
return
[]
podControllerFinder
{
dc
.
getPodReplicationController
s
,
dc
.
getPodDeployments
,
dc
.
getPodReplicaSets
,
dc
.
getPodStatefulSet
s
}
return
[]
podControllerFinder
{
dc
.
getPodReplicationController
,
dc
.
getPodDeployment
,
dc
.
getPodReplicaSet
,
dc
.
getPodStatefulSet
}
}
var
(
...
...
@@ -181,9 +181,8 @@ var (
controllerKindDep
=
v1beta1
.
SchemeGroupVersion
.
WithKind
(
"Deployment"
)
)
// getPodReplicaSets finds replicasets which have no matching deployments.
func
(
dc
*
DisruptionController
)
getPodReplicaSets
(
pod
*
v1
.
Pod
)
([]
controllerAndScale
,
error
)
{
var
casSlice
[]
controllerAndScale
// getPodReplicaSet finds a replicaset which has no matching deployments.
func
(
dc
*
DisruptionController
)
getPodReplicaSet
(
pod
*
v1
.
Pod
)
(
*
controllerAndScale
,
error
)
{
controllerRef
:=
metav1
.
GetControllerOf
(
pod
)
if
controllerRef
==
nil
{
return
nil
,
nil
...
...
@@ -204,13 +203,11 @@ func (dc *DisruptionController) getPodReplicaSets(pod *v1.Pod) ([]controllerAndS
// Skip RS if it's controlled by a Deployment.
return
nil
,
nil
}
casSlice
=
append
(
casSlice
,
controllerAndScale
{
rs
.
UID
,
*
(
rs
.
Spec
.
Replicas
)})
return
casSlice
,
nil
return
&
controllerAndScale
{
rs
.
UID
,
*
(
rs
.
Spec
.
Replicas
)},
nil
}
// getPodStatefulSet returns the statefulset managing the given pod.
func
(
dc
*
DisruptionController
)
getPodStatefulSets
(
pod
*
v1
.
Pod
)
([]
controllerAndScale
,
error
)
{
var
casSlice
[]
controllerAndScale
func
(
dc
*
DisruptionController
)
getPodStatefulSet
(
pod
*
v1
.
Pod
)
(
*
controllerAndScale
,
error
)
{
controllerRef
:=
metav1
.
GetControllerOf
(
pod
)
if
controllerRef
==
nil
{
return
nil
,
nil
...
...
@@ -227,13 +224,11 @@ func (dc *DisruptionController) getPodStatefulSets(pod *v1.Pod) ([]controllerAnd
return
nil
,
nil
}
casSlice
=
append
(
casSlice
,
controllerAndScale
{
ss
.
UID
,
*
(
ss
.
Spec
.
Replicas
)})
return
casSlice
,
nil
return
&
controllerAndScale
{
ss
.
UID
,
*
(
ss
.
Spec
.
Replicas
)},
nil
}
// getPodDeployments finds deployments for any replicasets which are being managed by deployments.
func
(
dc
*
DisruptionController
)
getPodDeployments
(
pod
*
v1
.
Pod
)
([]
controllerAndScale
,
error
)
{
var
casSlice
[]
controllerAndScale
func
(
dc
*
DisruptionController
)
getPodDeployment
(
pod
*
v1
.
Pod
)
(
*
controllerAndScale
,
error
)
{
controllerRef
:=
metav1
.
GetControllerOf
(
pod
)
if
controllerRef
==
nil
{
return
nil
,
nil
...
...
@@ -264,12 +259,10 @@ func (dc *DisruptionController) getPodDeployments(pod *v1.Pod) ([]controllerAndS
if
deployment
.
UID
!=
controllerRef
.
UID
{
return
nil
,
nil
}
casSlice
=
append
(
casSlice
,
controllerAndScale
{
deployment
.
UID
,
*
(
deployment
.
Spec
.
Replicas
)})
return
casSlice
,
nil
return
&
controllerAndScale
{
deployment
.
UID
,
*
(
deployment
.
Spec
.
Replicas
)},
nil
}
func
(
dc
*
DisruptionController
)
getPodReplicationControllers
(
pod
*
v1
.
Pod
)
([]
controllerAndScale
,
error
)
{
var
casSlice
[]
controllerAndScale
func
(
dc
*
DisruptionController
)
getPodReplicationController
(
pod
*
v1
.
Pod
)
(
*
controllerAndScale
,
error
)
{
controllerRef
:=
metav1
.
GetControllerOf
(
pod
)
if
controllerRef
==
nil
{
return
nil
,
nil
...
...
@@ -285,8 +278,7 @@ func (dc *DisruptionController) getPodReplicationControllers(pod *v1.Pod) ([]con
if
rc
.
UID
!=
controllerRef
.
UID
{
return
nil
,
nil
}
casSlice
=
append
(
casSlice
,
controllerAndScale
{
rc
.
UID
,
*
(
rc
.
Spec
.
Replicas
)})
return
casSlice
,
nil
return
&
controllerAndScale
{
rc
.
UID
,
*
(
rc
.
Spec
.
Replicas
)},
nil
}
func
(
dc
*
DisruptionController
)
Run
(
stopCh
<-
chan
struct
{})
{
...
...
@@ -590,30 +582,26 @@ func (dc *DisruptionController) getExpectedScale(pdb *policy.PodDisruptionBudget
// A mapping from controllers to their scale.
controllerScale
:=
map
[
types
.
UID
]
int32
{}
// 1. Find the controller(s) for each pod. If any pod has 0 controllers,
// that's an error. If any pod has more than 1 controller, that's also an
// error.
// 1. Find the controller for each pod. If any pod has 0 controllers,
// that's an error. With ControllerRef, a pod can only have 1 controller.
for
_
,
pod
:=
range
pods
{
controllerCount
:=
0
foundController
:=
false
for
_
,
finder
:=
range
dc
.
finders
()
{
var
controller
s
[]
controllerAndScale
controller
s
,
err
=
finder
(
pod
)
var
controller
NScale
*
controllerAndScale
controller
NScale
,
err
=
finder
(
pod
)
if
err
!=
nil
{
return
}
for
_
,
controller
:=
range
controllers
{
controllerScale
[
controller
.
UID
]
=
controller
.
scale
controllerCount
++
if
controllerNScale
!=
nil
{
controllerScale
[
controllerNScale
.
UID
]
=
controllerNScale
.
scale
foundController
=
true
break
}
}
if
controllerCount
==
0
{
if
!
foundController
{
err
=
fmt
.
Errorf
(
"found no controllers for pod %q"
,
pod
.
Name
)
dc
.
recorder
.
Event
(
pdb
,
v1
.
EventTypeWarning
,
"NoControllers"
,
err
.
Error
())
return
}
else
if
controllerCount
>
1
{
err
=
fmt
.
Errorf
(
"pod %q has %v>1 controllers"
,
pod
.
Name
,
controllerCount
)
dc
.
recorder
.
Event
(
pdb
,
v1
.
EventTypeWarning
,
"TooManyControllers"
,
err
.
Error
())
return
}
}
...
...
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