From c8db3ec2449673ec476a1d3d51ead2e3a6b77f57 Mon Sep 17 00:00:00 2001 From: takahiro-tsuruda Date: Thu, 11 Oct 2018 11:38:47 +0900 Subject: [PATCH 1/4] Replace `Dead` to `Unreachable` --- cmd/sabactl/machines.go | 2 +- docs/api.md | 4 ++-- docs/lifecycle.md | 14 +++++++------- docs/sabactl.md | 4 ++-- machines.go | 4 ++-- query_test.go | 2 +- web/machines_test.go | 2 +- web/state.go | 2 +- web/state_test.go | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/sabactl/machines.go b/cmd/sabactl/machines.go index 94b58dcb..b2f27ee1 100644 --- a/cmd/sabactl/machines.go +++ b/cmd/sabactl/machines.go @@ -174,7 +174,7 @@ STATE can be one of: uninitialized The machine is not yet initialized. healthy The machine has no problems. unhealthy The machine has some problems. - dead The machine does not communicate with others. + unreachable The machine does not communicate with others. updating The machine is updating. retiring The machine should soon be retired/repaired. `, diff --git a/docs/api.md b/docs/api.md index d1f97de8..4c3ec7bc 100644 --- a/docs/api.md +++ b/docs/api.md @@ -277,7 +277,7 @@ The new state is given by contents of request body and should be one of: * `uninitialized` * `healthy` * `unhealthy` -* `dead` +* `unreachable` * `updating` * `retiring` @@ -313,7 +313,7 @@ The state will be returned by response body and should be one of: * uninitialized * healthy * unhealthy -* dead +* unreachable * updating * retiring * retired diff --git a/docs/lifecycle.md b/docs/lifecycle.md index 9e47eb16..8fd02fae 100644 --- a/docs/lifecycle.md +++ b/docs/lifecycle.md @@ -28,7 +28,7 @@ Sabakan defines following machine states: * **Uninitialized**: Machines to not be initialized. * **Healthy**: Machines that can run applications * **Unhealthy**: Machines having problems to be repaired -* **Dead**: Machines that cannot be accessed +* **Unreachable**: Machines that cannot be accessed * **Updating**: Machines to be updating * **Retiring**: Machines to be retired/repaired * **Retired**: Machines whose disk encryption keys were deleted @@ -40,16 +40,16 @@ External controllers are expected to: * Prepare **Uninitialized** machines to (re)join to application clusters. * Allocate **Healthy** machines to applications like Kubernetes or Ceph. * Reboot the **Updating** machines, Machines will be **Uninitialized** after reboot. -* Drain **Unhealthy**, **Dead** and **Retiring** machines from applications. +* Drain **Unhealthy**, **Unreachable** and **Retiring** machines from applications. * Remove disk encryption keys of **Retiring** machines after drain. ### Transition constraints -* **Uninitialized**, ***Healthy**, **Unhealthy**, or **Dead** machine can transition to **Retiring**. +* **Uninitialized**, ***Healthy**, **Unhealthy**, or **Unreachable** machine can transition to **Retiring**. * A **Retiring** machine can transition only to **Retired**. -* A **Healthy** machine can transition to **Unhealthy**, **Dead**, **Retiring**, and **Updating**. -* A **Unhealthy** machine can transition to **Dead**. -* **Uneahlthy** and **Dead** machine can not return to **Healthy** directly. +* A **Healthy** machine can transition to **Unhealthy**, **Unreachable**, **Retiring**, and **Updating**. +* A **Unreachable** machine can transition to **Healthy**. +* **Uneahlthy** machine cannot return to **Healthy** directly. * Disk encryption keys of a machine can be deleted if the machine is in **Retiring** state. * A machine transitions to **Retired** when its disk encryption keys are deleted. * Only **Retired** machines can be removed from sabakan. @@ -64,4 +64,4 @@ sabakan. ### Transition diagram -![state transition diagram](http://www.plantuml.com/plantuml/png/ZP91JuH038NlyojwDY7UEPWrxa4lncoo9-EXC5sPCDCXfRZ1No-3B3h4nBsGbdxlFMYwwnL5X-3DwyqR53QUkRY38pjswj2xJx8cww2Ove-4NflnZyc1r8dZznBsL7jqGY3BAsCMsGmUkVdk4gbKQm_8G29HCcvFQ4ju9Zr7QM5W8QmRh3nbr2RsT-gA3LsAxIng0jVgza1LZAa2RGZ2PE-OZBdCeTWkf8JxavA0pCA9vEQwJyd0hUVJsa107j3xSID8gp0cFVyBMfbDnejGby3iHyt5wCSriGSAyOFwcRMkRu6ubh5J5nbQ6XSPNPspuEkDJVTMmWCoI0hAM3X93D1ZXIsosH7R8VWl) +![state transition diagram](http://www.plantuml.com/plantuml/png/ZPB1JiCm38RlUGgVaIhkFQ0XTe0BGfKu8GvUuz6eYLEvBbDvUfgnXQL2QBVO_dv_RPJDg2Ww1M_URjwXil70rHsyicEd3htx8ckA2gfb_aZejPl_c3IaJXn_rB2brgCJ0ZcrZ3d55Z0fkfygaKgjZe0C91AbuBQ4jePdqaEK7YOMmhR3dQU2McalhHcRXgGTB6e2y-cseLsCwGJQ4OHblMCovZo7QdqXDTplbGJa65n8xgxxb19SxNpA1GJa2RsVZTaIbZUU6_zeChCol0WD2RpupGkLEM_yNPz23ONuIUCnPDtO0t4hyw0kClGqds9qhJ3ZvwUsFBiQ7f11agXWOIynm8Wxx97DXjXEmNy3) \ No newline at end of file diff --git a/docs/sabactl.md b/docs/sabactl.md index c5641949..65deaded 100644 --- a/docs/sabactl.md +++ b/docs/sabactl.md @@ -90,7 +90,7 @@ Detailed specification of the query parameters and the output JSON content is sa ---------------------------- Set the state of a machine. -State is one of `uninitialized`, `healthy`, `unhealthy`, `dead`, `updating` or `retiring`. +State is one of `uninitialized`, `healthy`, `unhealthy`, `unreachbale`, `updating` or `retiring`. ```console $ sabactl machines set-state @@ -100,7 +100,7 @@ $ sabactl machines set-state ---------------------------- Get the state of a machine. -State is one of `uninitialized`, `healthy`, `unhealthy`, `dead`, `updating`, `retiring` or `retired`. +State is one of `uninitialized`, `healthy`, `unhealthy`, `unreachable`, `updating`, `retiring` or `retired`. ```console $ sabactl machines get-state diff --git a/machines.go b/machines.go index 525c3240..35796b35 100644 --- a/machines.go +++ b/machines.go @@ -19,7 +19,7 @@ const ( StateUninitialized = MachineState("uninitialized") StateHealthy = MachineState("healthy") StateUnhealthy = MachineState("unhealthy") - StateDead = MachineState("dead") + StateUnreachable = MachineState("unreachable") StateUpdating = MachineState("updating") StateRetiring = MachineState("retiring") StateRetired = MachineState("retired") @@ -114,7 +114,7 @@ func (m *Machine) SetState(ms MachineState) error { if ms == StateHealthy || ms == StateUpdating || ms == StateRetired { return errors.New("transition to " + ms.String() + " is forbidden") } - case StateDead: + case StateUnreachable: if ms == StateHealthy || ms == StateUpdating || ms == StateRetired || ms == StateUnhealthy { return errors.New("transition to " + ms.String() + " is forbidden") } diff --git a/query_test.go b/query_test.go index 1ea9f737..7007dc11 100644 --- a/query_test.go +++ b/query_test.go @@ -27,7 +27,7 @@ func TestMatch(t *testing.T) { {Query{"ipv6": "aa::ff"}, NewMachine(MachineSpec{IPv6: []string{"bb::ff", "cc::ff"}}), false}, {Query{"ipv4": "10.20.30.40"}, NewMachine(MachineSpec{}), false}, {Query{"ipv6": "aa::ff"}, NewMachine(MachineSpec{}), false}, - {Query{"state": "dead"}, NewMachine(MachineSpec{}), false}, + {Query{"state": "unreachable"}, NewMachine(MachineSpec{}), false}, } for _, c := range cases { diff --git a/web/machines_test.go b/web/machines_test.go index 3a886ee4..e13c05af 100644 --- a/web/machines_test.go +++ b/web/machines_test.go @@ -256,7 +256,7 @@ func testMachinesGet(t *testing.T) { expected: nil, }, { - query: map[string][]string{"state": {"dead"}}, + query: map[string][]string{"state": {"unreachable"}}, status: http.StatusNotFound, expected: nil, }, diff --git a/web/state.go b/web/state.go index 496d73ad..7d99a2ad 100644 --- a/web/state.go +++ b/web/state.go @@ -52,7 +52,7 @@ func (s Server) handleStatePut(w http.ResponseWriter, r *http.Request, serial st ms := sabakan.MachineState(state) switch ms { - case sabakan.StateUninitialized, sabakan.StateHealthy, sabakan.StateUnhealthy, sabakan.StateDead, sabakan.StateUpdating, sabakan.StateRetiring: + case sabakan.StateUninitialized, sabakan.StateHealthy, sabakan.StateUnhealthy, sabakan.StateUnreachable, sabakan.StateUpdating, sabakan.StateRetiring: default: renderError(r.Context(), w, BadRequest("invalid state: "+string(state))) return diff --git a/web/state_test.go b/web/state_test.go index 96a3e327..f8a94c9d 100644 --- a/web/state_test.go +++ b/web/state_test.go @@ -81,7 +81,7 @@ func testStatePut(t *testing.T) { {"healthy", 200}, {"unhealthy", 200}, {"healthy", 500}, - {"dead", 200}, + {"unreachable", 200}, {"uninitialized", 200}, {"healthy", 200}, {"retired", 400}, From d9b429eccc5a956f8ed97447e0dec95156e9db2f Mon Sep 17 00:00:00 2001 From: takahiro-tsuruda Date: Thu, 11 Oct 2018 11:47:11 +0900 Subject: [PATCH 2/4] Modify state rules --- machines.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/machines.go b/machines.go index 35796b35..93d6bf69 100644 --- a/machines.go +++ b/machines.go @@ -107,7 +107,7 @@ func (m *Machine) SetState(ms MachineState) error { return errors.New("transition to state other than healthy or retiring is forbidden") } case StateHealthy: - if ms == StateUninitialized || ms == StateRetired { + if ms == StateUnreachable || ms == StateUninitialized || ms == StateRetired { return errors.New("transition to " + ms.String() + " is forbidden") } case StateUnhealthy: @@ -115,7 +115,7 @@ func (m *Machine) SetState(ms MachineState) error { return errors.New("transition to " + ms.String() + " is forbidden") } case StateUnreachable: - if ms == StateHealthy || ms == StateUpdating || ms == StateRetired || ms == StateUnhealthy { + if ms == StateUpdating || ms == StateRetired || ms == StateUnhealthy { return errors.New("transition to " + ms.String() + " is forbidden") } case StateUpdating: From 39a6bf865b4127eb26fca6dd12e054d924d82072 Mon Sep 17 00:00:00 2001 From: takahiro-tsuruda Date: Thu, 11 Oct 2018 11:57:06 +0900 Subject: [PATCH 3/4] Update lifecycle rule --- machines.go | 4 ++-- web/state_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/machines.go b/machines.go index 93d6bf69..9240e7a6 100644 --- a/machines.go +++ b/machines.go @@ -107,11 +107,11 @@ func (m *Machine) SetState(ms MachineState) error { return errors.New("transition to state other than healthy or retiring is forbidden") } case StateHealthy: - if ms == StateUnreachable || ms == StateUninitialized || ms == StateRetired { + if ms == StateUninitialized || ms == StateRetired { return errors.New("transition to " + ms.String() + " is forbidden") } case StateUnhealthy: - if ms == StateHealthy || ms == StateUpdating || ms == StateRetired { + if ms != StateUninitialized && ms != StateRetiring { return errors.New("transition to " + ms.String() + " is forbidden") } case StateUnreachable: diff --git a/web/state_test.go b/web/state_test.go index f8a94c9d..ab28a15e 100644 --- a/web/state_test.go +++ b/web/state_test.go @@ -79,9 +79,14 @@ func testStatePut(t *testing.T) { {"unhealthy", 500}, {"uninitialized", 200}, {"healthy", 200}, + {"unreachable", 200}, + {"healthy", 200}, + {"unreachable", 200}, + {"unhealthy", 500}, + {"healthy", 200}, {"unhealthy", 200}, {"healthy", 500}, - {"unreachable", 200}, + {"unreachable", 500}, {"uninitialized", 200}, {"healthy", 200}, {"retired", 400}, From 544fdb0f86c8fa887d562c69bc7a4a45bc2dba0b Mon Sep 17 00:00:00 2001 From: ZOETROPE Date: Thu, 11 Oct 2018 13:42:00 +0900 Subject: [PATCH 4/4] fix typo --- docs/sabactl.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sabactl.md b/docs/sabactl.md index 65deaded..a1e81b13 100644 --- a/docs/sabactl.md +++ b/docs/sabactl.md @@ -90,7 +90,7 @@ Detailed specification of the query parameters and the output JSON content is sa ---------------------------- Set the state of a machine. -State is one of `uninitialized`, `healthy`, `unhealthy`, `unreachbale`, `updating` or `retiring`. +State is one of `uninitialized`, `healthy`, `unhealthy`, `unreachable`, `updating` or `retiring`. ```console $ sabactl machines set-state