Skip to content

Commit f8a6707

Browse files
authored
Merge pull request kubernetes#131085 from kayrus/exclude-nodes
[cloud-provider] respect the "exclude-from-external-load-balancers=false" label
2 parents 0b81338 + 310b395 commit f8a6707

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

staging/src/k8s.io/cloud-provider/controllers/service/controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"reflect"
24+
"strconv"
2425
"sync"
2526
"time"
2627

@@ -1011,7 +1012,14 @@ var (
10111012

10121013
// We consider the node for load balancing only when the node is not labelled for exclusion.
10131014
func nodeIncludedPredicate(node *v1.Node) bool {
1014-
_, hasExcludeBalancerLabel := node.Labels[v1.LabelNodeExcludeBalancers]
1015+
v, hasExcludeBalancerLabel := node.Labels[v1.LabelNodeExcludeBalancers]
1016+
if hasExcludeBalancerLabel {
1017+
v, err := strconv.ParseBool(v)
1018+
if err != nil {
1019+
return false
1020+
}
1021+
return !v
1022+
}
10151023
return !hasExcludeBalancerLabel
10161024
}
10171025

staging/src/k8s.io/cloud-provider/controllers/service/controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,9 @@ func Test_respectsPredicates(t *testing.T) {
18291829
{want: false, input: &v1.Node{Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionFalse}}}}},
18301830
{want: true, input: &v1.Node{Spec: v1.NodeSpec{ProviderID: providerID}, Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionTrue}}}, ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{}}}},
18311831
{want: false, input: &v1.Node{Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionTrue}}}, ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{v1.LabelNodeExcludeBalancers: ""}}}},
1832+
{want: true, input: &v1.Node{Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionTrue}}}, ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{v1.LabelNodeExcludeBalancers: "false"}}}},
1833+
{want: false, input: &v1.Node{Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionTrue}}}, ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{v1.LabelNodeExcludeBalancers: "true"}}}},
1834+
{want: false, input: &v1.Node{Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionTrue}}}, ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{v1.LabelNodeExcludeBalancers: "foo"}}}},
18321835

18331836
{want: false, input: &v1.Node{Status: v1.NodeStatus{Conditions: []v1.NodeCondition{{Type: v1.NodeReady, Status: v1.ConditionTrue}}},
18341837
Spec: v1.NodeSpec{Taints: []v1.Taint{{Key: ToBeDeletedTaint, Value: fmt.Sprint(time.Now().Unix()), Effect: v1.TaintEffectNoSchedule}}}}},

0 commit comments

Comments
 (0)