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
a6e1db97
Commit
a6e1db97
authored
May 23, 2019
by
Joe Betz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge tolerations in a consistent order
parent
9b504c47
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
tolerations.go
pkg/util/tolerations/tolerations.go
+12
-7
No files found.
pkg/util/tolerations/tolerations.go
View file @
a6e1db97
...
@@ -25,6 +25,10 @@ type key struct {
...
@@ -25,6 +25,10 @@ type key struct {
effect
api
.
TaintEffect
effect
api
.
TaintEffect
}
}
func
convertTolerationToKey
(
in
api
.
Toleration
)
key
{
return
key
{
in
.
Key
,
in
.
Effect
}
}
// VerifyAgainstWhitelist checks if the provided tolerations
// VerifyAgainstWhitelist checks if the provided tolerations
// satisfy the provided whitelist and returns true, otherwise returns false
// satisfy the provided whitelist and returns true, otherwise returns false
func
VerifyAgainstWhitelist
(
tolerations
[]
api
.
Toleration
,
whitelist
[]
api
.
Toleration
)
bool
{
func
VerifyAgainstWhitelist
(
tolerations
[]
api
.
Toleration
,
whitelist
[]
api
.
Toleration
)
bool
{
...
@@ -62,13 +66,14 @@ func IsConflict(first []api.Toleration, second []api.Toleration) bool {
...
@@ -62,13 +66,14 @@ func IsConflict(first []api.Toleration, second []api.Toleration) bool {
func
MergeTolerations
(
first
[]
api
.
Toleration
,
second
[]
api
.
Toleration
)
[]
api
.
Toleration
{
func
MergeTolerations
(
first
[]
api
.
Toleration
,
second
[]
api
.
Toleration
)
[]
api
.
Toleration
{
var
mergedTolerations
[]
api
.
Toleration
var
mergedTolerations
[]
api
.
Toleration
mergedTolerations
=
append
(
mergedTolerations
,
second
...
)
mergedTolerations
=
append
(
mergedTolerations
,
second
...
)
firstMap
:=
ConvertTolerationToAMap
(
first
)
firstMap
:=
ConvertTolerationToAMap
(
first
)
secondMap
:=
ConvertTolerationToAMap
(
second
)
secondMap
:=
ConvertTolerationToAMap
(
second
)
// preserve order of first when merging
for
k1
,
v1
:=
range
firstMap
{
for
_
,
v
:=
range
first
{
if
_
,
ok
:=
secondMap
[
k1
];
!
ok
{
k
:=
convertTolerationToKey
(
v
)
mergedTolerations
=
append
(
mergedTolerations
,
v1
)
// if first contains key conflicts, the last one takes precedence
if
_
,
ok
:=
secondMap
[
k
];
!
ok
&&
firstMap
[
k
]
==
v
{
mergedTolerations
=
append
(
mergedTolerations
,
v
)
}
}
}
}
return
mergedTolerations
return
mergedTolerations
...
@@ -95,8 +100,8 @@ func EqualTolerations(first []api.Toleration, second []api.Toleration) bool {
...
@@ -95,8 +100,8 @@ func EqualTolerations(first []api.Toleration, second []api.Toleration) bool {
// ConvertTolerationToAMap converts toleration list into a map[string]api.Toleration
// ConvertTolerationToAMap converts toleration list into a map[string]api.Toleration
func
ConvertTolerationToAMap
(
in
[]
api
.
Toleration
)
map
[
key
]
api
.
Toleration
{
func
ConvertTolerationToAMap
(
in
[]
api
.
Toleration
)
map
[
key
]
api
.
Toleration
{
out
:=
map
[
key
]
api
.
Toleration
{}
out
:=
map
[
key
]
api
.
Toleration
{}
for
i
:=
range
in
{
for
_
,
v
:=
range
in
{
out
[
key
{
in
[
i
]
.
Key
,
in
[
i
]
.
Effect
}]
=
in
[
i
]
out
[
convertTolerationToKey
(
v
)]
=
v
}
}
return
out
return
out
}
}
...
...
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