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
667ed4ef
Commit
667ed4ef
authored
Jun 05, 2017
by
Avesh Agarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicate errors from an aggregate error input.
Helps with some scheduler errors that fill the log enormously.
parent
d3146080
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
3 deletions
+59
-3
generic_scheduler.go
plugin/pkg/scheduler/core/generic_scheduler.go
+3
-3
errors.go
staging/src/k8s.io/apimachinery/pkg/util/errors/errors.go
+19
-0
errors_test.go
...ng/src/k8s.io/apimachinery/pkg/util/errors/errors_test.go
+37
-0
No files found.
plugin/pkg/scheduler/core/generic_scheduler.go
View file @
667ed4ef
...
@@ -178,7 +178,7 @@ func findNodesThatFit(
...
@@ -178,7 +178,7 @@ func findNodesThatFit(
// Create filtered list with enough space to avoid growing it
// Create filtered list with enough space to avoid growing it
// and allow assigning.
// and allow assigning.
filtered
=
make
([]
*
v1
.
Node
,
len
(
nodes
))
filtered
=
make
([]
*
v1
.
Node
,
len
(
nodes
))
errs
:=
[]
error
{}
errs
:=
errors
.
MessageCountMap
{}
var
predicateResultLock
sync
.
Mutex
var
predicateResultLock
sync
.
Mutex
var
filteredLen
int32
var
filteredLen
int32
...
@@ -189,7 +189,7 @@ func findNodesThatFit(
...
@@ -189,7 +189,7 @@ func findNodesThatFit(
fits
,
failedPredicates
,
err
:=
podFitsOnNode
(
pod
,
meta
,
nodeNameToInfo
[
nodeName
],
predicateFuncs
,
ecache
)
fits
,
failedPredicates
,
err
:=
podFitsOnNode
(
pod
,
meta
,
nodeNameToInfo
[
nodeName
],
predicateFuncs
,
ecache
)
if
err
!=
nil
{
if
err
!=
nil
{
predicateResultLock
.
Lock
()
predicateResultLock
.
Lock
()
errs
=
append
(
errs
,
err
)
errs
[
err
.
Error
()]
++
predicateResultLock
.
Unlock
()
predicateResultLock
.
Unlock
()
return
return
}
}
...
@@ -204,7 +204,7 @@ func findNodesThatFit(
...
@@ -204,7 +204,7 @@ func findNodesThatFit(
workqueue
.
Parallelize
(
16
,
len
(
nodes
),
checkNode
)
workqueue
.
Parallelize
(
16
,
len
(
nodes
),
checkNode
)
filtered
=
filtered
[
:
filteredLen
]
filtered
=
filtered
[
:
filteredLen
]
if
len
(
errs
)
>
0
{
if
len
(
errs
)
>
0
{
return
[]
*
v1
.
Node
{},
FailedPredicateMap
{},
errors
.
NewAggregate
(
errs
)
return
[]
*
v1
.
Node
{},
FailedPredicateMap
{},
errors
.
CreateAggregateFromMessageCountMap
(
errs
)
}
}
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/util/errors/errors.go
View file @
667ed4ef
...
@@ -21,6 +21,9 @@ import (
...
@@ -21,6 +21,9 @@ import (
"fmt"
"fmt"
)
)
// MessagesgCountMap contains occurance for each error message.
type
MessageCountMap
map
[
string
]
int
// Aggregate represents an object that contains multiple errors, but does not
// Aggregate represents an object that contains multiple errors, but does not
// necessarily have singular semantic meaning.
// necessarily have singular semantic meaning.
type
Aggregate
interface
{
type
Aggregate
interface
{
...
@@ -147,6 +150,22 @@ func Flatten(agg Aggregate) Aggregate {
...
@@ -147,6 +150,22 @@ func Flatten(agg Aggregate) Aggregate {
return
NewAggregate
(
result
)
return
NewAggregate
(
result
)
}
}
// CreateAggregateFromMessageCountMap converts MessageCountMap Aggregate
func
CreateAggregateFromMessageCountMap
(
m
MessageCountMap
)
Aggregate
{
if
m
==
nil
{
return
nil
}
result
:=
make
([]
error
,
0
,
len
(
m
))
for
errStr
,
count
:=
range
m
{
var
countStr
string
if
count
>
1
{
countStr
=
fmt
.
Sprintf
(
" (repeated %v times)"
,
count
)
}
result
=
append
(
result
,
fmt
.
Errorf
(
"%v%v"
,
errStr
,
countStr
))
}
return
NewAggregate
(
result
)
}
// Reduce will return err or, if err is an Aggregate and only has one item,
// Reduce will return err or, if err is an Aggregate and only has one item,
// the first item in the aggregate.
// the first item in the aggregate.
func
Reduce
(
err
error
)
error
{
func
Reduce
(
err
error
)
error
{
...
...
staging/src/k8s.io/apimachinery/pkg/util/errors/errors_test.go
View file @
667ed4ef
...
@@ -19,6 +19,7 @@ package errors
...
@@ -19,6 +19,7 @@ package errors
import
(
import
(
"fmt"
"fmt"
"reflect"
"reflect"
"sort"
"testing"
"testing"
)
)
...
@@ -262,6 +263,42 @@ func TestFlatten(t *testing.T) {
...
@@ -262,6 +263,42 @@ func TestFlatten(t *testing.T) {
}
}
}
}
func
TestCreateAggregateFromMessageCountMap
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
mcp
MessageCountMap
expected
Aggregate
}{
{
"input has single instance of one message"
,
MessageCountMap
{
"abc"
:
1
},
aggregate
{
fmt
.
Errorf
(
"abc"
)},
},
{
"input has multiple messages"
,
MessageCountMap
{
"abc"
:
2
,
"ghi"
:
1
},
aggregate
{
fmt
.
Errorf
(
"abc (repeated 2 times)"
),
fmt
.
Errorf
(
"ghi"
)},
},
}
var
expected
,
agg
[]
error
for
_
,
testCase
:=
range
testCases
{
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
if
testCase
.
expected
!=
nil
{
expected
=
testCase
.
expected
.
Errors
()
sort
.
Slice
(
expected
,
func
(
i
,
j
int
)
bool
{
return
expected
[
i
]
.
Error
()
<
expected
[
j
]
.
Error
()
})
}
if
testCase
.
mcp
!=
nil
{
agg
=
CreateAggregateFromMessageCountMap
(
testCase
.
mcp
)
.
Errors
()
sort
.
Slice
(
agg
,
func
(
i
,
j
int
)
bool
{
return
agg
[
i
]
.
Error
()
<
agg
[
j
]
.
Error
()
})
}
if
!
reflect
.
DeepEqual
(
expected
,
agg
)
{
t
.
Errorf
(
"expected %v, got %v"
,
expected
,
agg
)
}
})
}
}
func
TestAggregateGoroutines
(
t
*
testing
.
T
)
{
func
TestAggregateGoroutines
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
errs
[]
error
errs
[]
error
...
...
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