Skip to content

Commit 753a253

Browse files
authored
Merge pull request #5 from gridscale/fix/node-taint-not-respecting-pools
Fix node taint not respecting pools
2 parents 1da19b5 + 25c5e8d commit 753a253

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ jobs:
2727
with:
2828
path: ${{ env.GOPATH }}/src/k8s.io/autoscaler
2929

30-
- name: Test
30+
- name: Test cloudprovider/gridscale
3131
working-directory: ${{ env.GOPATH }}/src/k8s.io/autoscaler/cluster-autoscaler/cloudprovider/gridscale
3232
run: go test ./...
33+
- name: Test utils/taints
34+
working-directory: ${{ env.GOPATH }}/src/k8s.io/autoscaler/cluster-autoscaler/utils/taints
35+
run: go test ./...
3336

3437
test-and-verify:
3538
runs-on: ubuntu-latest

cluster-autoscaler/utils/taints/taints.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
klog "k8s.io/klog/v2"
3636
)
3737

38-
// gridscaleNode0SuffixName is the suffix of the gridscale node 0's name
39-
const gridscaleNode0SuffixName = "-node-pool0-0"
38+
// gridscaleNode0SuffixName is the suffix of the first node of every gridscale node pool.
39+
const gridscaleNode0SuffixName = "-0"
4040

4141
const (
4242
// ToBeDeletedTaint is a taint used to make the node unschedulable.
@@ -182,16 +182,25 @@ func MarkDeletionCandidate(node *apiv1.Node, client kube_client.Interface) error
182182
return AddTaints(node, client, []apiv1.Taint{taint}, false)
183183
}
184184

185+
// skipTaintingGridscaleNode checks if a node should not be tainted. This is gridscale specific.
186+
func skipTaintingGridscaleNode(node *apiv1.Node) (reason string, skip bool) {
187+
// The first node should never be tainted
188+
if strings.HasSuffix(node.Name, gridscaleNode0SuffixName) {
189+
return fmt.Sprintf("Skipping tainting of node %v, because the first pool node should never be tainted", node.Name), true
190+
}
191+
return "", false
192+
}
193+
185194
// AddTaints sets the specified taints on the node.
186195
func AddTaints(node *apiv1.Node, client kube_client.Interface, taints []apiv1.Taint, cordonNode bool) error {
187196
retryDeadline := time.Now().Add(maxRetryDeadline)
188197
freshNode := node.DeepCopy()
189198
var err error
190199
refresh := false
191200
for {
192-
// skip tainting gridscale node 0
193-
if strings.HasSuffix(node.Name, gridscaleNode0SuffixName) {
194-
klog.V(1).Infof("Skipping tainting of node %v, because it is a gridscale node 0", node.Name)
201+
// skip tainting gridscale nodes when we don't want to
202+
if reason, skip := skipTaintingGridscaleNode(node); skip {
203+
klog.V(1).Infof(reason)
195204
return nil
196205
}
197206
if refresh {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package taints
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
apiv1 "k8s.io/api/core/v1"
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
"testing"
8+
)
9+
10+
func Test_skipTaintingGridscaleNode(t *testing.T) {
11+
type Test struct {
12+
Name string
13+
NodeName string
14+
ExpectsSkip bool
15+
}
16+
17+
tests := []Test{
18+
{
19+
Name: "skips node if it is the first node",
20+
NodeName: "prod-my-pool-pool0-0",
21+
ExpectsSkip: true,
22+
},
23+
{
24+
Name: "does not skip second node",
25+
NodeName: "prod-my-pool-pool0-1",
26+
ExpectsSkip: false,
27+
},
28+
{
29+
Name: "skips node with pre-node-pool name if it is the first node",
30+
NodeName: "prod-node-pool0-0",
31+
ExpectsSkip: true,
32+
},
33+
{
34+
Name: "does not skip node with pre-node-pool name if it is the second node",
35+
NodeName: "prod-node-pool0-1",
36+
ExpectsSkip: false,
37+
},
38+
}
39+
40+
for _, test := range tests {
41+
t.Run(test.Name, func(t *testing.T) {
42+
node := &apiv1.Node{
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: test.NodeName,
45+
},
46+
}
47+
48+
reason, skip := skipTaintingGridscaleNode(node)
49+
50+
if test.ExpectsSkip {
51+
assert.True(t, skip, "Node should be skipped")
52+
assert.NotEmpty(t, reason, "Skipping nodes must return a reason")
53+
} else {
54+
assert.False(t, skip, "Node should not be skipped")
55+
assert.Empty(t, reason, "Non-skipped nodes should not return a reason")
56+
}
57+
})
58+
}
59+
}

0 commit comments

Comments
 (0)