Skip to content

Commit

Permalink
Merge pull request #792 from vinicyusmacedo/autoscaler-react
Browse files Browse the repository at this point in the history
Added NoSchedule effect to GetNodeConditionPredicate
  • Loading branch information
k8s-ci-robot authored Jul 12, 2019
2 parents f93941a + b166480 commit 67d5ffd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const (
// This label is feature-gated in kubernetes/kubernetes but we do not have feature gates
// This will need to be updated after the end of the alpha
LabelNodeRoleExcludeBalancer = "alpha.service-controller.kubernetes.io/exclude-balancer"
// ToBeDeletedTaint is the taint that the autoscaler adds when a node is scheduled to be deleted
// https://github.com/kubernetes/autoscaler/blob/cluster-autoscaler-0.5.2/cluster-autoscaler/utils/deletetaint/delete.go#L33
ToBeDeletedTaint = "ToBeDeletedByClusterAutoscaler"
)

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

// Get all nodes that have a taint with NoSchedule effect
for _, taint := range node.Spec.Taints {
if taint.Key == ToBeDeletedTaint {
return false
}
}

// As of 1.6, we will taint the master, but not necessarily mark it unschedulable.
// Recognize nodes labeled as master, and filter them also, as we were doing previously.
if _, hasMasterRoleLabel := node.Labels[LabelNodeRoleMaster]; hasMasterRoleLabel {
Expand Down
66 changes: 66 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ limitations under the License.
package utils

import (
"fmt"
"testing"
"time"

api_v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -452,6 +455,69 @@ func TestTraverseIngressBackends(t *testing.T) {
}
}

func TestGetNodeConditionPredicate(t *testing.T) {
tests := []struct {
node api_v1.Node
expectAccept bool
name string
}{
{
node: api_v1.Node{},
expectAccept: false,
name: "empty",
},
{
node: api_v1.Node{
Status: api_v1.NodeStatus{
Conditions: []api_v1.NodeCondition{
{Type: api_v1.NodeReady, Status: api_v1.ConditionTrue},
},
},
},
expectAccept: true,
name: "basic",
},
{
node: api_v1.Node{
Spec: api_v1.NodeSpec{Unschedulable: true},
Status: api_v1.NodeStatus{
Conditions: []api_v1.NodeCondition{
{Type: api_v1.NodeReady, Status: api_v1.ConditionTrue},
},
},
},
expectAccept: false,
name: "unschedulable",
}, {
node: api_v1.Node{
Spec: api_v1.NodeSpec{
Taints: []api_v1.Taint{
api_v1.Taint{
Key: ToBeDeletedTaint,
Value: fmt.Sprint(time.Now().Unix()),
Effect: api_v1.TaintEffectNoSchedule,
},
},
},
Status: api_v1.NodeStatus{
Conditions: []api_v1.NodeCondition{
{Type: api_v1.NodeReady, Status: api_v1.ConditionTrue},
},
},
},
expectAccept: false,
name: "ToBeDeletedByClusterAutoscaler-taint",
},
}
pred := GetNodeConditionPredicate()
for _, test := range tests {
accept := pred(&test.node)
if accept != test.expectAccept {
t.Errorf("Test failed for %s, expected %v, saw %v", test.name, test.expectAccept, accept)
}
}
}

func getTestIngress() {
return
}

0 comments on commit 67d5ffd

Please sign in to comment.