Skip to content

Commit

Permalink
Merge pull request #663 from cybozu-go/register-retire-date-label
Browse files Browse the repository at this point in the history
Add `register-month` and `retire-month` labels
  • Loading branch information
zoetrope authored Sep 12, 2023
2 parents e5a1269 + b9ab8b7 commit 6708bda
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
18 changes: 10 additions & 8 deletions docs/sabakan-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,16 @@ Other Machine fields are also translated to labels as follows.
`topology.kubernetes.io/zone` and `failure-domain.beta.kubernetes.io/zone`(deprecated) are well-known labels.
`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`. |
| `spec.indexInRack` | `cke.cybozu.com/index-in-rack` | `spec.indexInRack` converted to string. |
| `spec.role` | `cke.cybozu.com/role` | The same as `spec.role`. |
| `spec.role` | `node-role.kubernetes.io/<role>` | `"true"` |
| 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`. |
| `spec.indexInRack` | `cke.cybozu.com/index-in-rack` | `spec.indexInRack` converted to string. |
| `spec.role` | `cke.cybozu.com/role` | The same as `spec.role`. |
| `spec.role` | `node-role.kubernetes.io/<role>` | `"true"` |
| `spec.registerDate` | `cke.cybozu.com/register-month` | `spec.registerDate` in `yyyy-MM` format. |
| `spec.retireDate` | `cke.cybozu.com/retire-month` | `spec.retireDate` in `yyyy-MM` format. |

In addition `node-role.kubernetes.io/master` is set to `"true"` in the control plane node.

Expand Down
2 changes: 2 additions & 0 deletions sabakan/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func MachineToNode(m *Machine, tmpl *cke.Node) *cke.Node {
n.Labels["cke.cybozu.com/rack"] = strconv.Itoa(m.Spec.Rack)
n.Labels["cke.cybozu.com/index-in-rack"] = strconv.Itoa(m.Spec.IndexInRack)
n.Labels["cke.cybozu.com/role"] = m.Spec.Role
n.Labels["cke.cybozu.com/retire-month"] = m.Spec.RetireDate.Format("2006-01")
n.Labels["cke.cybozu.com/register-month"] = m.Spec.RegisterDate.Format("2006-01")
n.Labels["node-role.kubernetes.io/"+m.Spec.Role] = "true"
if n.ControlPlane {
n.Labels["node-role.kubernetes.io/master"] = "true"
Expand Down
6 changes: 6 additions & 0 deletions sabakan/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func testMachineToNode(t *testing.T) {
if res1.Labels["node-role.kubernetes.io/control-plane"] != "true" {
t.Error(`res1.Lables["node-role.kubernetes.io/control-plane"] != "true", actual:`, res1.Labels)
}
if res1.Labels[domain+"/register-month"] != testPast250.Format("2006-01") {
t.Error(`res1.Labels["cke.cybozu.com/register-month"] != machine.Spec.RegisterDate.Format("2006-01"), actual:`, res1.Labels)
}
if res1.Labels[domain+"/retire-month"] != testBaseTS.Format("2006-01") {
t.Error(`res1.Labels["cke.cybozu.com/register-month"] != machine.Spec.RetireDate.Format("2006-01"), actual:`, res1.Labels)
}
if !containsTaint(res1.Taints, corev1.Taint{Key: "foo", Effect: corev1.TaintEffectNoSchedule}) {
t.Error(`res1.Taints do not have corev1.Taint{Key"foo", Effect: corev1.TaintEffectNoSchedule}, actual:`, res1.Taints)
}
Expand Down

0 comments on commit 6708bda

Please sign in to comment.