Skip to content

Commit 67d5ffd

Browse files
authored
Merge pull request #792 from vinicyusmacedo/autoscaler-react
Added NoSchedule effect to GetNodeConditionPredicate
2 parents f93941a + b166480 commit 67d5ffd

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

pkg/utils/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const (
6767
// This label is feature-gated in kubernetes/kubernetes but we do not have feature gates
6868
// This will need to be updated after the end of the alpha
6969
LabelNodeRoleExcludeBalancer = "alpha.service-controller.kubernetes.io/exclude-balancer"
70+
// ToBeDeletedTaint is the taint that the autoscaler adds when a node is scheduled to be deleted
71+
// https://github.com/kubernetes/autoscaler/blob/cluster-autoscaler-0.5.2/cluster-autoscaler/utils/deletetaint/delete.go#L33
72+
ToBeDeletedTaint = "ToBeDeletedByClusterAutoscaler"
7073
)
7174

7275
// FakeGoogleAPIForbiddenErr creates a Forbidden error with type googleapi.Error
@@ -319,6 +322,13 @@ func GetNodeConditionPredicate() listers.NodeConditionPredicate {
319322
return false
320323
}
321324

325+
// Get all nodes that have a taint with NoSchedule effect
326+
for _, taint := range node.Spec.Taints {
327+
if taint.Key == ToBeDeletedTaint {
328+
return false
329+
}
330+
}
331+
322332
// As of 1.6, we will taint the master, but not necessarily mark it unschedulable.
323333
// Recognize nodes labeled as master, and filter them also, as we were doing previously.
324334
if _, hasMasterRoleLabel := node.Labels[LabelNodeRoleMaster]; hasMasterRoleLabel {

pkg/utils/utils_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package utils
1818

1919
import (
20+
"fmt"
2021
"testing"
22+
"time"
2123

24+
api_v1 "k8s.io/api/core/v1"
2225
extensions "k8s.io/api/extensions/v1beta1"
2326
"k8s.io/apimachinery/pkg/types"
2427
"k8s.io/apimachinery/pkg/util/intstr"
@@ -452,6 +455,69 @@ func TestTraverseIngressBackends(t *testing.T) {
452455
}
453456
}
454457

458+
func TestGetNodeConditionPredicate(t *testing.T) {
459+
tests := []struct {
460+
node api_v1.Node
461+
expectAccept bool
462+
name string
463+
}{
464+
{
465+
node: api_v1.Node{},
466+
expectAccept: false,
467+
name: "empty",
468+
},
469+
{
470+
node: api_v1.Node{
471+
Status: api_v1.NodeStatus{
472+
Conditions: []api_v1.NodeCondition{
473+
{Type: api_v1.NodeReady, Status: api_v1.ConditionTrue},
474+
},
475+
},
476+
},
477+
expectAccept: true,
478+
name: "basic",
479+
},
480+
{
481+
node: api_v1.Node{
482+
Spec: api_v1.NodeSpec{Unschedulable: true},
483+
Status: api_v1.NodeStatus{
484+
Conditions: []api_v1.NodeCondition{
485+
{Type: api_v1.NodeReady, Status: api_v1.ConditionTrue},
486+
},
487+
},
488+
},
489+
expectAccept: false,
490+
name: "unschedulable",
491+
}, {
492+
node: api_v1.Node{
493+
Spec: api_v1.NodeSpec{
494+
Taints: []api_v1.Taint{
495+
api_v1.Taint{
496+
Key: ToBeDeletedTaint,
497+
Value: fmt.Sprint(time.Now().Unix()),
498+
Effect: api_v1.TaintEffectNoSchedule,
499+
},
500+
},
501+
},
502+
Status: api_v1.NodeStatus{
503+
Conditions: []api_v1.NodeCondition{
504+
{Type: api_v1.NodeReady, Status: api_v1.ConditionTrue},
505+
},
506+
},
507+
},
508+
expectAccept: false,
509+
name: "ToBeDeletedByClusterAutoscaler-taint",
510+
},
511+
}
512+
pred := GetNodeConditionPredicate()
513+
for _, test := range tests {
514+
accept := pred(&test.node)
515+
if accept != test.expectAccept {
516+
t.Errorf("Test failed for %s, expected %v, saw %v", test.name, test.expectAccept, accept)
517+
}
518+
}
519+
}
520+
455521
func getTestIngress() {
456522
return
457523
}

0 commit comments

Comments
 (0)