@@ -22,6 +22,7 @@ import (
22
22
"testing"
23
23
"time"
24
24
25
+ "github.com/stretchr/testify/assert"
25
26
corev1 "k8s.io/api/core/v1"
26
27
"k8s.io/apimachinery/pkg/api/resource"
27
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -36,7 +37,6 @@ import (
36
37
api "k8s.io/kubernetes/pkg/apis/core"
37
38
"k8s.io/kubernetes/pkg/features"
38
39
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
39
- "k8s.io/kubernetes/pkg/util/tolerations"
40
40
pluginapi "k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/apis/podtolerationrestriction"
41
41
)
42
42
@@ -139,10 +139,11 @@ func TestPodAdmission(t *testing.T) {
139
139
{
140
140
pod : bestEffortPod ,
141
141
defaultClusterTolerations : []api.Toleration {},
142
- namespaceTolerations : []api.Toleration {{Key : "testKey" , Operator : "Equal" , Value : "testValue" , Effect : "NoSchedule" , TolerationSeconds : nil }},
143
- podTolerations : []api.Toleration {{Key : "testKey" , Operator : "Equal" , Value : "testValue1" , Effect : "NoSchedule" , TolerationSeconds : nil }},
144
- admit : false ,
145
- testName : "conflicting pod and namespace tolerations" ,
142
+ namespaceTolerations : []api.Toleration {{Key : "testKey" , Operator : "Equal" , Value : "testValue" , Effect : "NoSchedule" }},
143
+ podTolerations : []api.Toleration {{Key : "testKey" , Operator : "Equal" , Value : "testValue1" , Effect : "NoSchedule" }},
144
+ mergedTolerations : []api.Toleration {{Key : "testKey" , Operator : "Equal" , Value : "testValue" , Effect : "NoSchedule" }, {Key : "testKey" , Operator : "Equal" , Value : "testValue1" , Effect : "NoSchedule" }},
145
+ admit : true ,
146
+ testName : "duplicate key pod and namespace tolerations" ,
146
147
},
147
148
{
148
149
pod : bestEffortPod ,
@@ -210,10 +211,11 @@ func TestPodAdmission(t *testing.T) {
210
211
whitelist : []api.Toleration {},
211
212
podTolerations : []api.Toleration {{Key : "testKey" , Operator : "Equal" , Value : "testValue" , Effect : "NoSchedule" , TolerationSeconds : nil }, {Key : "testKey" , Operator : "Equal" , Value : "testValue1" , Effect : "NoSchedule" , TolerationSeconds : nil }},
212
213
mergedTolerations : []api.Toleration {
214
+ {Key : "testKey" , Operator : "Equal" , Value : "testValue" , Effect : "NoSchedule" , TolerationSeconds : nil },
213
215
{Key : "testKey" , Operator : "Equal" , Value : "testValue1" , Effect : "NoSchedule" , TolerationSeconds : nil },
214
216
},
215
217
admit : true ,
216
- testName : "Besteffort pod should overwrite for conflicting tolerations " ,
218
+ testName : "Pod with duplicate key tolerations should not be modified " ,
217
219
},
218
220
{
219
221
pod : guaranteedPod ,
@@ -275,8 +277,8 @@ func TestPodAdmission(t *testing.T) {
275
277
}
276
278
277
279
updatedPodTolerations := pod .Spec .Tolerations
278
- if test .admit && ! tolerations . EqualTolerations ( updatedPodTolerations , test . mergedTolerations ) {
279
- t . Errorf ( "Test: %s, expected: %#v but got: %#v" , test .testName , test . mergedTolerations , updatedPodTolerations )
280
+ if test .admit {
281
+ assert . ElementsMatch ( t , updatedPodTolerations , test .mergedTolerations )
280
282
}
281
283
})
282
284
}
0 commit comments