@@ -1589,9 +1589,18 @@ func Test_propagateMachineTaintsToNode(t *testing.T) {
15891589 Effect : corev1 .TaintEffectNoSchedule ,
15901590 Propagation : clusterv1 .MachineTaintPropagationAlways ,
15911591 }
1592+
15921593 transitionOnInitialization := transitionAlways
15931594 transitionOnInitialization .Propagation = clusterv1 .MachineTaintPropagationOnInitialization
15941595
1596+ transitionExistingAlwaysNewValue := existingAlwaysTaint
1597+ transitionExistingAlwaysNewValue .Value = "transition-value-new"
1598+
1599+ transitionExistingAlwaysNewEffect := existingAlwaysTaint
1600+ transitionExistingAlwaysNewEffect .Effect = corev1 .TaintEffectNoSchedule
1601+
1602+ externalNodeTaint := corev1.Taint {Key : "external-taint" , Value : "external-value" , Effect : corev1 .TaintEffectNoExecute }
1603+
15951604 tests := []struct {
15961605 name string
15971606 node * corev1.Node
@@ -1642,6 +1651,15 @@ func Test_propagateMachineTaintsToNode(t *testing.T) {
16421651 expectedAnnotation : "added-always:NoSchedule" ,
16431652 expectChanged : true ,
16441653 },
1654+ {
1655+ name : "Add missing but tracked Always taint, tracking annotation, no other taints" ,
1656+ node : builder .Node ("" ).
1657+ WithAnnotations (map [string ]string {clusterv1 .TaintsFromMachineAnnotation : "existing-always:NoExecute" }).Build (),
1658+ machineTaints : []clusterv1.MachineTaint {existingAlwaysTaint },
1659+ expectedTaints : []corev1.Taint {convertMachineTaintToCoreV1Taint (existingAlwaysTaint )},
1660+ expectedAnnotation : "existing-always:NoExecute" ,
1661+ expectChanged : true ,
1662+ },
16451663 {
16461664 name : "Delete Always taint, tracking annotation, no other taints" ,
16471665 node : builder .Node ("" ).
@@ -1701,6 +1719,54 @@ func Test_propagateMachineTaintsToNode(t *testing.T) {
17011719 expectedAnnotation : "transition-taint:NoSchedule" ,
17021720 expectChanged : true ,
17031721 },
1722+ {
1723+ name : "Transition Always taint to have a new value should change the value also on the node" ,
1724+ node : builder .Node ("" ).
1725+ WithAnnotations (map [string ]string {clusterv1 .TaintsFromMachineAnnotation : "existing-always:NoExecute" }).
1726+ WithTaints (convertMachineTaintToCoreV1Taint (existingAlwaysTaint )).Build (),
1727+ machineTaints : []clusterv1.MachineTaint {transitionExistingAlwaysNewValue },
1728+ expectedTaints : []corev1.Taint {convertMachineTaintToCoreV1Taint (transitionExistingAlwaysNewValue )},
1729+ expectedAnnotation : "existing-always:NoExecute" ,
1730+ expectChanged : true ,
1731+ },
1732+ {
1733+ name : "Transition Always taint to have a new effect should change the effect also on the node" ,
1734+ node : builder .Node ("" ).
1735+ WithAnnotations (map [string ]string {clusterv1 .TaintsFromMachineAnnotation : "existing-always:NoExecute" }).
1736+ WithTaints (convertMachineTaintToCoreV1Taint (existingAlwaysTaint )).Build (),
1737+ machineTaints : []clusterv1.MachineTaint {transitionExistingAlwaysNewEffect },
1738+ expectedTaints : []corev1.Taint {convertMachineTaintToCoreV1Taint (transitionExistingAlwaysNewEffect )},
1739+ expectedAnnotation : "existing-always:NoSchedule" ,
1740+ expectChanged : true ,
1741+ },
1742+ {
1743+ name : "Add missing taints, no tracking annotation, preserve other taints" ,
1744+ node : builder .Node ("" ).
1745+ WithTaints (externalNodeTaint ).Build (),
1746+ machineTaints : []clusterv1.MachineTaint {alwaysTaint , onInitializationTaint },
1747+ expectedTaints : []corev1.Taint {externalNodeTaint , convertMachineTaintToCoreV1Taint (alwaysTaint ), convertMachineTaintToCoreV1Taint (onInitializationTaint )},
1748+ expectedAnnotation : "added-always:NoSchedule" ,
1749+ expectChanged : true ,
1750+ },
1751+ {
1752+ name : "Adopt existing taint, no tracking annotation" ,
1753+ node : builder .Node ("" ).
1754+ WithTaints (convertMachineTaintToCoreV1Taint (existingAlwaysTaint )).Build (),
1755+ machineTaints : []clusterv1.MachineTaint {existingAlwaysTaint },
1756+ expectedTaints : []corev1.Taint {convertMachineTaintToCoreV1Taint (existingAlwaysTaint )},
1757+ expectedAnnotation : "existing-always:NoExecute" ,
1758+ expectChanged : true ,
1759+ },
1760+ {
1761+ name : "Recover from broken tracking annotation" ,
1762+ node : builder .Node ("" ).
1763+ WithAnnotations (map [string ]string {clusterv1 .TaintsFromMachineAnnotation : "existing-always:NoExecute," }).
1764+ WithTaints (convertMachineTaintToCoreV1Taint (existingAlwaysTaint )).Build (),
1765+ machineTaints : []clusterv1.MachineTaint {existingAlwaysTaint },
1766+ expectedTaints : []corev1.Taint {convertMachineTaintToCoreV1Taint (existingAlwaysTaint )},
1767+ expectedAnnotation : "existing-always:NoExecute" ,
1768+ expectChanged : true ,
1769+ },
17041770 }
17051771 for _ , tt := range tests {
17061772 t .Run (tt .name , func (t * testing.T ) {
0 commit comments