Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package cluster |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | |
| 22 | "source.monogon.dev/metropolis/pkg/pki" |
| 23 | ) |
| 24 | |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 25 | // ClusterState is the state of the cluster from the point of view of the |
| 26 | // current node. Clients within the node code can watch this state to change |
| 27 | // their behaviour as needed. |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 28 | type ClusterState int |
| 29 | |
| 30 | const ( |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 31 | // ClusterStateUnknown means the node has not yet determined the existence |
| 32 | // of a cluster it should join or start. This is a transient, initial state |
| 33 | // that should only manifest during boot. |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 34 | ClusterUnknown ClusterState = iota |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 35 | // ClusterForeign means the node is attempting to register into an already |
| 36 | // existing cluster with which it managed to make preliminary contact, but |
| 37 | // which the cluster has not yet fully productionized (eg. the node is |
| 38 | // still being hardware attested, or the operator needs to confirm the |
| 39 | // registration of this node). |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 40 | ClusterForeign |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 41 | // ClusterTrusted means the node is attempting to register into an already |
| 42 | // registered cluster, and has been trusted by it. The node is now |
| 43 | // attempting to finally commit into registering the cluster. |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 44 | ClusterTrusted |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 45 | // ClusterHome means the node is part of a cluster. This is the bulk of |
| 46 | // time in which this node will spend its time. |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 47 | ClusterHome |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 48 | // ClusterDisowning means the node has been disowned (ie., removed) by the |
| 49 | // cluster, and that it will not be ever part of any cluster again, and |
| 50 | // that it will be decommissioned by the operator. |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 51 | ClusterDisowning |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 52 | // ClusterSplit means that the node would usually be Home in a cluster, but |
| 53 | // has been split from the consensus of the cluster. This can happen for |
| 54 | // nodes running consensus when consensus is lost (eg. when there is no |
| 55 | // quorum or this node has been netsplit), and for other nodes if they have |
| 56 | // lost network connectivity to the consensus nodes. Clients should make |
| 57 | // their own decision what action to perform in this state, depending on |
| 58 | // the level of consistency required and whether it makes sense for the |
| 59 | // node to fence its services off. |
| 60 | ClusterSplit |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 61 | ) |
| 62 | |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 63 | func (s ClusterState) String() string { |
| 64 | switch s { |
| 65 | case ClusterForeign: |
| 66 | return "ClusterForeign" |
| 67 | case ClusterTrusted: |
| 68 | return "ClusterTrusted" |
| 69 | case ClusterHome: |
| 70 | return "ClusterHome" |
| 71 | case ClusterDisowning: |
| 72 | return "ClusterDisowning" |
Serge Bazanski | a105db5 | 2021-04-12 19:57:46 +0200 | [diff] [blame] | 73 | case ClusterSplit: |
| 74 | return "ClusterSplit" |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 75 | } |
| 76 | return fmt.Sprintf("Invalid(%d)", s) |
| 77 | } |
| 78 | |
Serge Bazanski | 42e61c6 | 2021-03-18 15:07:18 +0100 | [diff] [blame] | 79 | var ( |
| 80 | PKINamespace = pki.Namespaced("/cluster-pki/") |
| 81 | PKICA = PKINamespace.New(pki.SelfSigned, "cluster-ca", pki.CA("Metropolis Cluster CA")) |
| 82 | ) |