Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NoSchedule effect to GetNodeConditionPredicate #792

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any public documentation regarding this taint?

If not, probably still need to add a link to the autoscaler repo.
https://github.com/kubernetes/autoscaler/blob/cluster-autoscaler-0.5.2/cluster-autoscaler/utils/deletetaint/delete.go#L33

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freehan I didn't find any docs on it :/

I'll try to vendor it and its dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is tons of dependencies, just add the link in the comment then. No need for the hustle.

)

// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it should not be this generic. It should be limited to the autoscaler's ToBeDeletedByClusterAutoscaler taint.
Otherwise, if all nodes mark by no schedule by accident, it would disrupt all existing LB traffic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds better, I'll change it.

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
}