Skip to content

Commit

Permalink
Merge pull request #782 from cybozu-go/backport-780
Browse files Browse the repository at this point in the history
Revive unreachable taint (backport of #780)
  • Loading branch information
masa213f authored Dec 13, 2024
2 parents 21d0d03 + d0d50d9 commit a4fd108
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ This project employs a versioning scheme described in [RELEASE.md](RELEASE.md#ve

## [Unreleased]

### Changed

- Revive unreachable taint (backport of [#780](https://github.com/cybozu-go/cke/pull/780)) [#782](https://github.com/cybozu-go/cke/pull/782)

## [1.29.1]

### Changed

- Set /sys mount of kubelet as read-write (backport of [#773](https://github.com/cybozu-go/cke/pull/773)) [#775](https://github.com/cybozu-go/cke/pull/775)

## [1.29.0]
Expand Down
4 changes: 3 additions & 1 deletion docs/sabakan-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ CKE generates cluster configuration with the following conditions.
* The servers which have the same role should be distributed evenly over the racks.
* Newer machines should be preferred than old ones.
* Healthy machines should be preferred than non-healthy ones.
* Unreachable machines in the cluster should be [tainted][taint] with `NoSchedule`.
* Retiring and retired machines should be [tainted][taint] with `NoExecute`.
* Retired machines should be removed if the machines are kept retired for a while.
* Rebooting machines should not be removed from the cluster nor be tainted.
Expand Down Expand Up @@ -304,6 +305,7 @@ The taint key is `cke.cybozu.com/state`.

| Machine state | Taint value | Taint effect |
| ------------- | ------------- | ------------ |
| Unreachable | `unreachable` | `NoSchedule` |
| Retiring | `retiring` | `NoExecute` |
| Retired | `retired` | `NoExecute` |

Expand All @@ -320,7 +322,7 @@ Other Machine fields are also translated to labels as follows.
`node-role.kubernetes.io/<role>` are used by `kubectl` to display the node's role.

| Field | Label key | Value |
|---------------------|------------------------------------------|-----------------------------------------------------|
| ------------------- | ---------------------------------------- | --------------------------------------------------- |
| `spec.rack` | `cke.cybozu.com/rack` | `spec.rack` converted to string. |
| `spec.rack` | `topology.kubernetes.io/zone` | `spec.rack` converted to string with prefix `rack`. |
| `spec.rack` | `failure-domain.beta.kubernetes.io/zone` | `spec.rack` converted to string with prefix `rack`. |
Expand Down
10 changes: 10 additions & 0 deletions sabakan/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func MachineToNode(m *Machine, tmpl *cke.Node) *cke.Node {

n.Taints = append(n.Taints, tmpl.Taints...)
switch m.Status.State {
case StateUnreachable:
n.Taints = append(n.Taints, corev1.Taint{
Key: "cke.cybozu.com/state",
Value: "unreachable",
Effect: corev1.TaintEffectNoSchedule,
})
case StateRetiring:
n.Taints = append(n.Taints, corev1.Taint{
Key: "cke.cybozu.com/state",
Expand Down Expand Up @@ -687,6 +693,10 @@ func hasValidTaint(n *cke.Node, m *Machine) bool {
}

switch m.Status.State {
case StateUnreachable:
if ckeTaint.Value != "unreachable" || ckeTaint.Effect != corev1.TaintEffectNoSchedule {
return false
}
case StateRetiring:
if ckeTaint.Value != "retiring" || ckeTaint.Effect != corev1.TaintEffectNoExecute {
return false
Expand Down
17 changes: 11 additions & 6 deletions sabakan/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,20 @@ func testMachineToNode(t *testing.T) {
t.Error(`res1.Taints do not have corev1.Taint{Key"foo", Effect: corev1.TaintEffectNoSchedule}, actual:`, res1.Taints)
}

machine.Status.State = StateRetiring
machine.Status.State = StateUnreachable
res2 := MachineToNode(machine, node)
if !containsTaint(res2.Taints, corev1.Taint{Key: domain + "/state", Value: "retiring", Effect: corev1.TaintEffectNoExecute}) {
t.Error(`res2.Taints do not have corev1.Taint{Key: "cke.cybozu.com/state", Value: "retiring", Effect: "NoExecute"}, actual:`, res2.Taints)
if !containsTaint(res2.Taints, corev1.Taint{Key: domain + "/state", Value: "unreachable", Effect: corev1.TaintEffectNoSchedule}) {
t.Error(`res2.Taints do not have corev1.Taint{Key: "cke.cybozu.com/state", Value: "unreachable", Effect: "NoSchedule"}, actual:`, res2.Taints)
}
machine.Status.State = StateRetired
machine.Status.State = StateRetiring
res3 := MachineToNode(machine, node)
if !containsTaint(res3.Taints, corev1.Taint{Key: domain + "/state", Value: "retired", Effect: corev1.TaintEffectNoExecute}) {
t.Error(`res3.Taints do not have corev1.Taint{Key: "cke.cybozu.com/state", Value: "retired", Effect: "NoExecute"}, actual:`, res3.Taints)
if !containsTaint(res3.Taints, corev1.Taint{Key: domain + "/state", Value: "retiring", Effect: corev1.TaintEffectNoExecute}) {
t.Error(`res3.Taints do not have corev1.Taint{Key: "cke.cybozu.com/state", Value: "retiring", Effect: "NoExecute"}, actual:`, res3.Taints)
}
machine.Status.State = StateRetired
res4 := MachineToNode(machine, node)
if !containsTaint(res4.Taints, corev1.Taint{Key: domain + "/state", Value: "retired", Effect: corev1.TaintEffectNoExecute}) {
t.Error(`res4.Taints do not have corev1.Taint{Key: "cke.cybozu.com/state", Value: "retired", Effect: "NoExecute"}, actual:`, res4.Taints)
}
}

Expand Down

0 comments on commit a4fd108

Please sign in to comment.