@@ -20,15 +20,11 @@ import (
2020 "testing"
2121
2222 . "github.com/onsi/gomega"
23- corev1 "k8s.io/api/core/v1"
2423 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25- utilfeature "k8s.io/component-base/featuregate/testing"
2624 "k8s.io/utils/ptr"
2725
2826 clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
29- "sigs.k8s.io/cluster-api/feature"
3027 "sigs.k8s.io/cluster-api/internal/webhooks/util"
31- "sigs.k8s.io/cluster-api/util/test/builder"
3228)
3329
3430func TestMachineDefault (t * testing.T ) {
@@ -229,119 +225,3 @@ func TestMachineVersionValidation(t *testing.T) {
229225 })
230226 }
231227}
232-
233- func TestMachineTaintValidation (t * testing.T ) {
234- m := builder .Machine ("default" , "machine1" ).
235- WithBootstrapTemplate (builder .BootstrapTemplate ("default" , "bootstrap-template" ).Build ())
236- webhook := & Machine {}
237-
238- tests := []struct {
239- name string
240- machine * clusterv1.Machine
241- featureEnabled bool
242- expectErr bool
243- }{
244- {
245- name : "should allow empty taints with feature gate disabled" ,
246- featureEnabled : false ,
247- machine : m .DeepCopy ().Build (),
248- expectErr : false ,
249- },
250- {
251- name : "should allow empty taints with feature gate enabled" ,
252- featureEnabled : true ,
253- machine : m .DeepCopy ().Build (),
254- expectErr : false ,
255- },
256- {
257- name : "should block taint key node.cluster.x-k8s.io/uninitialized" ,
258- featureEnabled : true ,
259- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
260- Key : "node.cluster.x-k8s.io/uninitialized" , Effect : corev1 .TaintEffectNoSchedule ,
261- }).Build (),
262- expectErr : true ,
263- },
264- {
265- name : "should block taint key node.cluster.x-k8s.io/outdated-revision" ,
266- featureEnabled : true ,
267- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
268- Key : "node.cluster.x-k8s.io/outdated-revision" , Effect : corev1 .TaintEffectNoSchedule ,
269- }).Build (),
270- expectErr : true ,
271- },
272- {
273- name : "should block taint with key prefix node.kubernetes.io/, which is not `out-of-service`" ,
274- featureEnabled : true ,
275- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
276- Key : "node.kubernetes.io/some-taint" , Effect : corev1 .TaintEffectNoSchedule ,
277- }).Build (),
278- expectErr : true ,
279- },
280- {
281- name : "should allow taint node.kubernetes.io/out-of-service" ,
282- featureEnabled : true ,
283- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
284- Key : "node.kubernetes.io/out-of-service" , Effect : corev1 .TaintEffectNoSchedule ,
285- }).Build (),
286- expectErr : false ,
287- },
288- {
289- name : "should block taint with key prefix node.cloudprovider.kubernetes.io/" ,
290- featureEnabled : true ,
291- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
292- Key : "node.cloudprovider.kubernetes.io/some-taint" , Effect : corev1 .TaintEffectNoSchedule ,
293- }).Build (),
294- expectErr : true ,
295- },
296- {
297- name : "should block taint key node-role.kubernetes.io/master" ,
298- featureEnabled : true ,
299- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
300- Key : "node-role.kubernetes.io/master" , Effect : corev1 .TaintEffectNoSchedule ,
301- }).Build (),
302- expectErr : true ,
303- },
304- {
305- name : "should allow taint key node-role.kubernetes.io/control-plane for control-plane nodes" ,
306- featureEnabled : true ,
307- machine : m .DeepCopy ().
308- WithLabels (map [string ]string {clusterv1 .MachineControlPlaneLabel : "true" }).
309- WithTaints (clusterv1.MachineTaint {
310- Key : "node-role.kubernetes.io/control-plane" , Effect : corev1 .TaintEffectNoSchedule ,
311- }).Build (),
312- expectErr : false ,
313- },
314- {
315- name : "should block taint key node-role.kubernetes.io/control-plane for worker nodes" ,
316- featureEnabled : true ,
317- machine : m .DeepCopy ().WithTaints (clusterv1.MachineTaint {
318- Key : "node-role.kubernetes.io/control-plane" , Effect : corev1 .TaintEffectNoSchedule ,
319- }).Build (),
320- expectErr : true ,
321- },
322- }
323- for i := range tests {
324- tt := tests [i ]
325- t .Run (tt .name , func (t * testing.T ) {
326- g := NewWithT (t )
327-
328- utilfeature .SetFeatureGateDuringTest (t , feature .Gates , feature .MachineTaintPropagation , tt .featureEnabled )
329-
330- warnings , err := webhook .ValidateCreate (ctx , tt .machine )
331- if tt .expectErr {
332- g .Expect (err ).To (HaveOccurred ())
333- } else {
334- g .Expect (err ).ToNot (HaveOccurred ())
335- }
336- g .Expect (warnings ).To (BeEmpty ())
337-
338- warnings , err = webhook .ValidateUpdate (ctx , tt .machine , tt .machine )
339- if tt .expectErr {
340- g .Expect (err ).To (HaveOccurred ())
341- } else {
342- g .Expect (err ).ToNot (HaveOccurred ())
343- }
344- g .Expect (warnings ).To (BeEmpty ())
345- })
346- }
347- }
0 commit comments