blob: b194f2504e0e9d2ed65a92ff5d35e28a92e758a6 [file] [log] [blame]
Serge Bazanski42e61c62021-03-18 15:07:18 +01001// 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
17package cluster
18
19import (
20 "fmt"
21
22 "source.monogon.dev/metropolis/pkg/pki"
23)
24
Serge Bazanskia105db52021-04-12 19:57:46 +020025// 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 Bazanski42e61c62021-03-18 15:07:18 +010028type ClusterState int
29
30const (
Serge Bazanskia105db52021-04-12 19:57:46 +020031 // 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 Bazanski42e61c62021-03-18 15:07:18 +010034 ClusterUnknown ClusterState = iota
Serge Bazanskia105db52021-04-12 19:57:46 +020035 // 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 Bazanski42e61c62021-03-18 15:07:18 +010040 ClusterForeign
Serge Bazanskia105db52021-04-12 19:57:46 +020041 // 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 Bazanski42e61c62021-03-18 15:07:18 +010044 ClusterTrusted
Serge Bazanskia105db52021-04-12 19:57:46 +020045 // 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 Bazanski42e61c62021-03-18 15:07:18 +010047 ClusterHome
Serge Bazanskia105db52021-04-12 19:57:46 +020048 // 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 Bazanski42e61c62021-03-18 15:07:18 +010051 ClusterDisowning
Serge Bazanskia105db52021-04-12 19:57:46 +020052 // 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 Bazanski42e61c62021-03-18 15:07:18 +010061)
62
Serge Bazanski42e61c62021-03-18 15:07:18 +010063func (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 Bazanskia105db52021-04-12 19:57:46 +020073 case ClusterSplit:
74 return "ClusterSplit"
Serge Bazanski42e61c62021-03-18 15:07:18 +010075 }
76 return fmt.Sprintf("Invalid(%d)", s)
77}
78
Serge Bazanski42e61c62021-03-18 15:07:18 +010079var (
80 PKINamespace = pki.Namespaced("/cluster-pki/")
81 PKICA = PKINamespace.New(pki.SelfSigned, "cluster-ca", pki.CA("Metropolis Cluster CA"))
82)