Skip to content

Commit

Permalink
Merge pull request #4022 from kahirokunn/adding-issue-taint
Browse files Browse the repository at this point in the history
Checking for taint `karpenter.sh/disrupted:NoSchedule` while checking if node is suitable to handle traffic.
  • Loading branch information
k8s-ci-robot authored Jan 25, 2025
2 parents 388f1df + 6b50067 commit 7118c22
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/backend/endpoint_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const (
labelAlphaNodeRoleExcludeBalancer = "alpha.service-controller.kubernetes.io/exclude-balancer"
labelEKSComputeType = "eks.amazonaws.com/compute-type"

toBeDeletedByCATaint = "ToBeDeletedByClusterAutoscaler"
toBeDeletedByCATaint = "ToBeDeletedByClusterAutoscaler"
toBeDeletedByKarpenterTaint = "karpenter.sh/disrupted"
)

var (
Expand Down Expand Up @@ -61,12 +62,17 @@ func GetTrafficProxyNodeSelector(tgb *elbv2api.TargetGroupBinding) (labels.Selec
// IsNodeSuitableAsTrafficProxy check whether node is suitable as a traffic proxy.
// This should be checked in additional to the nodeSelector defined in TargetGroupBinding.
func IsNodeSuitableAsTrafficProxy(node *corev1.Node) bool {
// ToBeDeletedByClusterAutoscaler taint is added by cluster autoscaler before removing node from cluster
// Marking the node as unsuitable for traffic once the taint is observed on the node
for _, taint := range node.Spec.Taints {
// ToBeDeletedByClusterAutoscaler taint is added by cluster autoscaler before removing node from cluster
// Marking the node as unsuitable for traffic once the taint is observed on the node
if taint.Key == toBeDeletedByCATaint {
return false
}
// karpenter.sh/disrupted:NoSchedule taint is added by karpenter before removing node from cluster
// Marking the node as unsuitable for traffic once the taint is observed on the node
if taint.Key == toBeDeletedByKarpenterTaint && taint.Effect == corev1.TaintEffectNoSchedule {
return false
}
}

return true
Expand Down
25 changes: 25 additions & 0 deletions pkg/backend/endpoint_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ func TestIsNodeSuitableAsTrafficProxy(t *testing.T) {
},
want: false,
},
{
name: "node is ready but tainted with karpenter.sh/disrupted",
args: args{
node: &corev1.Node{
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
Spec: corev1.NodeSpec{
Unschedulable: false,
Taints: []corev1.Taint{
{
Key: toBeDeletedByKarpenterTaint,
Effect: corev1.TaintEffectNoSchedule,
},
},
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 7118c22

Please sign in to comment.