mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge tolerations in a consistent order
This commit is contained in:
parent
9b504c474c
commit
a6e1db97f0
@ -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 {
|
|||||||
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 {
|
|||||||
// 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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user