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
e3c8c4c2
Unverified
Commit
e3c8c4c2
authored
May 18, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle resource.Quantity changes in eviction thresholds
parent
5e4308f9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
22 deletions
+23
-22
helpers.go
pkg/kubelet/eviction/helpers.go
+6
-10
helpers_test.go
pkg/kubelet/eviction/helpers_test.go
+14
-9
manager_test.go
pkg/kubelet/eviction/manager_test.go
+1
-1
types.go
pkg/kubelet/eviction/types.go
+2
-2
No files found.
pkg/kubelet/eviction/helpers.go
View file @
e3c8c4c2
...
...
@@ -148,7 +148,7 @@ func parseThresholdStatement(statement string) (Threshold, error) {
return
Threshold
{
Signal
:
signal
,
Operator
:
operator
,
Value
:
quantity
,
Value
:
&
quantity
,
},
nil
}
...
...
@@ -213,14 +213,10 @@ func podUsage(podStats statsapi.PodStats) (api.ResourceList, error) {
// disk usage (if known)
// TODO: need to handle volumes
for
_
,
fsStats
:=
range
[]
*
statsapi
.
FsStats
{
container
.
Rootfs
,
container
.
Logs
}
{
if
err
:=
disk
.
Add
(
*
diskUsage
(
fsStats
));
err
!=
nil
{
return
nil
,
err
}
disk
.
Add
(
*
diskUsage
(
fsStats
))
}
// memory usage (if known)
if
err
:=
memory
.
Add
(
*
memoryUsage
(
container
.
Memory
));
err
!=
nil
{
return
nil
,
err
}
memory
.
Add
(
*
memoryUsage
(
container
.
Memory
))
}
return
api
.
ResourceList
{
api
.
ResourceMemory
:
memory
,
...
...
@@ -430,7 +426,7 @@ func makeSignalObservations(summaryProvider stats.SummaryProvider) (signalObserv
statsFunc
:=
cachedStatsFunc
(
summary
.
Pods
)
// build an evaluation context for current eviction signals
result
:=
signalObservations
{}
result
[
SignalMemoryAvailable
]
=
*
resource
.
NewQuantity
(
int64
(
*
summary
.
Node
.
Memory
.
AvailableBytes
),
resource
.
BinarySI
)
result
[
SignalMemoryAvailable
]
=
resource
.
NewQuantity
(
int64
(
*
summary
.
Node
.
Memory
.
AvailableBytes
),
resource
.
BinarySI
)
return
result
,
statsFunc
,
nil
}
...
...
@@ -446,7 +442,7 @@ func thresholdsMet(thresholds []Threshold, observations signalObservations) []Th
}
// determine if we have met the specified threshold
thresholdMet
:=
false
thresholdResult
:=
threshold
.
Value
.
Cmp
(
observed
)
thresholdResult
:=
threshold
.
Value
.
Cmp
(
*
observed
)
switch
threshold
.
Operator
{
case
OpLessThan
:
thresholdMet
=
thresholdResult
>
0
...
...
@@ -538,7 +534,7 @@ func hasNodeCondition(inputs []api.NodeConditionType, item api.NodeConditionType
// hasThreshold returns true if the node condition is in the input list
func
hasThreshold
(
inputs
[]
Threshold
,
item
Threshold
)
bool
{
for
_
,
input
:=
range
inputs
{
if
input
.
GracePeriod
==
item
.
GracePeriod
&&
input
.
Operator
==
item
.
Operator
&&
input
.
Signal
==
item
.
Signal
&&
input
.
Value
.
Cmp
(
item
.
Value
)
==
0
{
if
input
.
GracePeriod
==
item
.
GracePeriod
&&
input
.
Operator
==
item
.
Operator
&&
input
.
Signal
==
item
.
Signal
&&
input
.
Value
.
Cmp
(
*
item
.
Value
)
==
0
{
return
true
}
}
...
...
pkg/kubelet/eviction/helpers_test.go
View file @
e3c8c4c2
...
...
@@ -30,6 +30,11 @@ import (
"k8s.io/kubernetes/pkg/types"
)
func
quantityMustParse
(
value
string
)
*
resource
.
Quantity
{
q
:=
resource
.
MustParse
(
value
)
return
&
q
}
func
TestParseThresholdConfig
(
t
*
testing
.
T
)
{
gracePeriod
,
_
:=
time
.
ParseDuration
(
"30s"
)
testCases
:=
map
[
string
]
struct
{
...
...
@@ -55,12 +60,12 @@ func TestParseThresholdConfig(t *testing.T) {
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"150Mi"
),
Value
:
quantity
MustParse
(
"150Mi"
),
},
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"300Mi"
),
Value
:
quantity
MustParse
(
"300Mi"
),
GracePeriod
:
gracePeriod
,
},
},
...
...
@@ -145,7 +150,7 @@ func thresholdEqual(a Threshold, b Threshold) bool {
return
a
.
GracePeriod
==
b
.
GracePeriod
&&
a
.
Operator
==
b
.
Operator
&&
a
.
Signal
==
b
.
Signal
&&
a
.
Value
.
Cmp
(
b
.
Value
)
==
0
a
.
Value
.
Cmp
(
*
b
.
Value
)
==
0
}
// TestOrderedByQoS ensures we order BestEffort < Burstable < Guaranteed
...
...
@@ -348,7 +353,7 @@ func TestThresholdsMet(t *testing.T) {
hardThreshold
:=
Threshold
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"1Gi"
),
Value
:
quantity
MustParse
(
"1Gi"
),
}
testCases
:=
map
[
string
]
struct
{
thresholds
[]
Threshold
...
...
@@ -363,14 +368,14 @@ func TestThresholdsMet(t *testing.T) {
"threshold-met"
:
{
thresholds
:
[]
Threshold
{
hardThreshold
},
observations
:
signalObservations
{
SignalMemoryAvailable
:
resource
.
MustParse
(
"500Mi"
),
SignalMemoryAvailable
:
quantity
MustParse
(
"500Mi"
),
},
result
:
[]
Threshold
{
hardThreshold
},
},
"threshold-not-met"
:
{
thresholds
:
[]
Threshold
{
hardThreshold
},
observations
:
signalObservations
{
SignalMemoryAvailable
:
resource
.
MustParse
(
"2Gi"
),
SignalMemoryAvailable
:
quantity
MustParse
(
"2Gi"
),
},
result
:
[]
Threshold
{},
},
...
...
@@ -387,7 +392,7 @@ func TestThresholdsFirstObservedAt(t *testing.T) {
hardThreshold
:=
Threshold
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"1Gi"
),
Value
:
quantity
MustParse
(
"1Gi"
),
}
now
:=
unversioned
.
Now
()
oldTime
:=
unversioned
.
NewTime
(
now
.
Time
.
Add
(
-
1
*
time
.
Minute
))
...
...
@@ -435,12 +440,12 @@ func TestThresholdsMetGracePeriod(t *testing.T) {
hardThreshold
:=
Threshold
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"1Gi"
),
Value
:
quantity
MustParse
(
"1Gi"
),
}
softThreshold
:=
Threshold
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"2Gi"
),
Value
:
quantity
MustParse
(
"2Gi"
),
GracePeriod
:
1
*
time
.
Minute
,
}
oldTime
:=
unversioned
.
NewTime
(
now
.
Time
.
Add
(
-
2
*
time
.
Minute
))
...
...
pkg/kubelet/eviction/manager_test.go
View file @
e3c8c4c2
...
...
@@ -103,7 +103,7 @@ func TestMemoryPressure(t *testing.T) {
{
Signal
:
SignalMemoryAvailable
,
Operator
:
OpLessThan
,
Value
:
resource
.
MustParse
(
"1Gi"
),
Value
:
quantity
MustParse
(
"1Gi"
),
},
},
}
...
...
pkg/kubelet/eviction/types.go
View file @
e3c8c4c2
...
...
@@ -55,7 +55,7 @@ type Threshold struct {
// Operator represents a relationship of a signal to a value.
Operator
ThresholdOperator
// value is a quantity associated with the signal that is evaluated against the specified operator.
Value
resource
.
Quantity
Value
*
resource
.
Quantity
// GracePeriod represents the amount of time that a threshold must be met before eviction is triggered.
GracePeriod
time
.
Duration
}
...
...
@@ -88,7 +88,7 @@ type statsFunc func(pod *api.Pod) (statsapi.PodStats, bool)
type
rankFunc
func
(
pods
[]
*
api
.
Pod
,
stats
statsFunc
)
// signalObservations maps a signal to an observed quantity
type
signalObservations
map
[
Signal
]
resource
.
Quantity
type
signalObservations
map
[
Signal
]
*
resource
.
Quantity
// thresholdsObservedAt maps a threshold to a time that it was observed
type
thresholdsObservedAt
map
[
Threshold
]
time
.
Time
...
...
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