@@ -18,67 +18,3 @@ func AddPodSchedulingToSpec(podSpec *corev1.PodSpec, nodeSelector map[string]str
1818 podSpec .Tolerations = MergeTolerations (podSpec .Tolerations , tolerations )
1919 }
2020}
21-
22- // MergeTolerations returns base and extra tolerations without duplicating identical tolerations.
23- // The returned slice is a deep copy: pointer fields such as Toleration.TolerationSeconds are
24- // cloned so that mutating the result never corrupts the input slices.
25- func MergeTolerations (base , extra []corev1.Toleration ) []corev1.Toleration {
26- if len (base ) == 0 {
27- return cloneTolerations (extra )
28- }
29- if len (extra ) == 0 {
30- return cloneTolerations (base )
31- }
32-
33- tolerations := cloneTolerations (base )
34- seen := make (map [tolerationKey ]struct {}, len (base )+ len (extra ))
35- for _ , toleration := range base {
36- seen [newTolerationKey (toleration )] = struct {}{}
37- }
38-
39- for _ , toleration := range extra {
40- key := newTolerationKey (toleration )
41- if _ , ok := seen [key ]; ok {
42- continue
43- }
44- tolerations = append (tolerations , * toleration .DeepCopy ())
45- seen [key ] = struct {}{}
46- }
47-
48- return tolerations
49- }
50-
51- // cloneTolerations returns a deep copy of the given tolerations, including pointer fields.
52- func cloneTolerations (tolerations []corev1.Toleration ) []corev1.Toleration {
53- if tolerations == nil {
54- return nil
55- }
56- cloned := make ([]corev1.Toleration , len (tolerations ))
57- for i := range tolerations {
58- tolerations [i ].DeepCopyInto (& cloned [i ])
59- }
60- return cloned
61- }
62-
63- type tolerationKey struct {
64- Key string
65- Operator corev1.TolerationOperator
66- Value string
67- Effect corev1.TaintEffect
68- HasTolerationSeconds bool
69- TolerationSeconds int64
70- }
71-
72- func newTolerationKey (toleration corev1.Toleration ) tolerationKey {
73- key := tolerationKey {
74- Key : toleration .Key ,
75- Operator : toleration .Operator ,
76- Value : toleration .Value ,
77- Effect : toleration .Effect ,
78- }
79- if toleration .TolerationSeconds != nil {
80- key .HasTolerationSeconds = true
81- key .TolerationSeconds = * toleration .TolerationSeconds
82- }
83- return key
84- }
0 commit comments