Revise possible states for a peering. (#13661)

These changes are primarily for Consul's UI, where we want to be more
specific about the state a peering is in.

- The "initial" state was renamed to pending, and no longer applies to
  peerings being established from a peering token.

- Upon request to establish a peering from a peering token, peerings
  will be set as "establishing". This will help distinguish between the
  two roles: the cluster that generates the peering token and the
  cluster that establishes the peering.

- When marked for deletion, peering state will be set to "deleting".
  This way the UI determines the deletion via the state rather than the
  "DeletedAt" field.

Co-authored-by: freddygv <freddy@hashicorp.com>
This commit is contained in:
Chris S. Kim 2022-07-04 10:47:58 -04:00 committed by GitHub
parent 27e50ae925
commit f07132dacc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 110 additions and 72 deletions

View File

@ -226,9 +226,9 @@ func (s *Store) PeeringWrite(idx uint64, p *pbpeering.Peering) error {
if !p.IsActive() {
return fmt.Errorf("cannot create a new peering marked for deletion")
}
// TODO(peering): consider keeping PeeringState enum elsewhere?
p.State = pbpeering.PeeringState_INITIAL
if p.State == 0 {
p.State = pbpeering.PeeringState_PENDING
}
p.CreateIndex = idx
p.ModifyIndex = idx
}

View File

@ -31,7 +31,7 @@ func insertTestPeerings(t *testing.T, s *Store) {
Name: "foo",
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
ID: testFooPeerID,
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
CreateIndex: 1,
ModifyIndex: 1,
})
@ -111,7 +111,7 @@ func TestStateStore_PeeringReadByID(t *testing.T) {
Name: "foo",
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
ID: testFooPeerID,
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
CreateIndex: 1,
ModifyIndex: 1,
},
@ -165,7 +165,7 @@ func TestStateStore_PeeringRead(t *testing.T) {
Name: "foo",
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
ID: testFooPeerID,
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
CreateIndex: 1,
ModifyIndex: 1,
},
@ -303,7 +303,7 @@ func TestStore_PeeringList(t *testing.T) {
Name: "foo",
Partition: structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty(),
ID: testFooPeerID,
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
CreateIndex: 1,
ModifyIndex: 1,
},
@ -423,10 +423,7 @@ func TestStore_PeeringWrite(t *testing.T) {
_, p, err := s.PeeringRead(nil, q)
require.NoError(t, err)
require.NotNil(t, p)
if tc.input.State == 0 {
require.Equal(t, pbpeering.PeeringState_INITIAL, p.State)
}
require.Equal(t, tc.input.State, p.State)
require.Equal(t, tc.input.Name, p.Name)
}
tcs := []testcase{
@ -1079,7 +1076,7 @@ func TestStateStore_PeeringsForService(t *testing.T) {
{
peering: &pbpeering.Peering{
Name: "peer1",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
},
},
{
@ -1108,7 +1105,7 @@ func TestStateStore_PeeringsForService(t *testing.T) {
query: []string{"foo"},
expect: [][]*pbpeering.Peering{
{
{Name: "peer1", State: pbpeering.PeeringState_INITIAL},
{Name: "peer1", State: pbpeering.PeeringState_PENDING},
},
},
expectIdx: uint64(6), // config entries max index
@ -1123,13 +1120,13 @@ func TestStateStore_PeeringsForService(t *testing.T) {
{
peering: &pbpeering.Peering{
Name: "peer1",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
},
},
{
peering: &pbpeering.Peering{
Name: "peer2",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
},
},
},
@ -1157,10 +1154,10 @@ func TestStateStore_PeeringsForService(t *testing.T) {
query: []string{"foo", "bar"},
expect: [][]*pbpeering.Peering{
{
{Name: "peer1", State: pbpeering.PeeringState_INITIAL},
{Name: "peer1", State: pbpeering.PeeringState_PENDING},
},
{
{Name: "peer2", State: pbpeering.PeeringState_INITIAL},
{Name: "peer2", State: pbpeering.PeeringState_PENDING},
},
},
expectIdx: uint64(6), // config entries max index
@ -1175,19 +1172,19 @@ func TestStateStore_PeeringsForService(t *testing.T) {
{
peering: &pbpeering.Peering{
Name: "peer1",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
},
},
{
peering: &pbpeering.Peering{
Name: "peer2",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
},
},
{
peering: &pbpeering.Peering{
Name: "peer3",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
},
},
},
@ -1218,11 +1215,11 @@ func TestStateStore_PeeringsForService(t *testing.T) {
query: []string{"foo", "bar"},
expect: [][]*pbpeering.Peering{
{
{Name: "peer1", State: pbpeering.PeeringState_INITIAL},
{Name: "peer2", State: pbpeering.PeeringState_INITIAL},
{Name: "peer1", State: pbpeering.PeeringState_PENDING},
{Name: "peer2", State: pbpeering.PeeringState_PENDING},
},
{
{Name: "peer3", State: pbpeering.PeeringState_INITIAL},
{Name: "peer3", State: pbpeering.PeeringState_PENDING},
},
},
expectIdx: uint64(7),

View File

@ -217,7 +217,7 @@ func TestHTTP_Peering_MethodNotAllowed(t *testing.T) {
foo := &pbpeering.PeeringWriteRequest{
Peering: &pbpeering.Peering{
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},
@ -252,7 +252,7 @@ func TestHTTP_Peering_Read(t *testing.T) {
foo := &pbpeering.PeeringWriteRequest{
Peering: &pbpeering.Peering{
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},
@ -317,7 +317,7 @@ func TestHTTP_Peering_Delete(t *testing.T) {
foo := &pbpeering.PeeringWriteRequest{
Peering: &pbpeering.Peering{
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},
@ -387,7 +387,7 @@ func TestHTTP_Peering_List(t *testing.T) {
foo := &pbpeering.PeeringWriteRequest{
Peering: &pbpeering.Peering{
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},

View File

@ -309,6 +309,7 @@ func (s *Service) Establish(
PeerServerName: tok.ServerName,
PeerID: tok.PeerID,
Meta: req.Meta,
State: pbpeering.PeeringState_ESTABLISHING,
},
}
if err = s.Backend.Apply().PeeringWrite(writeReq); err != nil {
@ -481,6 +482,7 @@ func (s *Service) PeeringDelete(ctx context.Context, req *pbpeering.PeeringDelet
ID: existing.ID,
Name: req.Name,
Partition: req.Partition,
State: pbpeering.PeeringState_DELETING,
DeletedAt: structs.TimeToProto(time.Now().UTC()),
},
}

View File

@ -108,7 +108,7 @@ func TestPeeringService_GenerateToken(t *testing.T) {
Name: "peerB",
Partition: acl.DefaultPartitionName,
ID: token.PeerID,
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_PENDING,
Meta: map[string]string{"foo": "bar"},
}
require.Equal(t, expect, peers[0])
@ -208,7 +208,7 @@ func TestPeeringService_Establish(t *testing.T) {
expectResp: &pbpeering.EstablishResponse{},
expectPeering: peering.TestPeering(
"peer1-usw1",
pbpeering.PeeringState_INITIAL,
pbpeering.PeeringState_ESTABLISHING,
map[string]string{"foo": "bar"},
),
},
@ -228,7 +228,7 @@ func TestPeeringService_Read(t *testing.T) {
p := &pbpeering.Peering{
ID: testUUID(t),
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "test",
PeerServerAddresses: []string{"addr1"},
@ -286,7 +286,7 @@ func TestPeeringService_Delete(t *testing.T) {
p := &pbpeering.Peering{
ID: testUUID(t),
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "test",
PeerServerAddresses: []string{"addr1"},
@ -324,7 +324,7 @@ func TestPeeringService_List(t *testing.T) {
foo := &pbpeering.Peering{
ID: testUUID(t),
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},
@ -419,7 +419,7 @@ func TestPeeringService_TrustBundleListByService(t *testing.T) {
require.NoError(t, s.Server.FSM().State().PeeringWrite(lastIdx, &pbpeering.Peering{
ID: testUUID(t),
Name: "foo",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerServerName: "test",
PeerServerAddresses: []string{"addr1"},
}))
@ -428,7 +428,7 @@ func TestPeeringService_TrustBundleListByService(t *testing.T) {
require.NoError(t, s.Server.FSM().State().PeeringWrite(lastIdx, &pbpeering.Peering{
ID: testUUID(t),
Name: "bar",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerServerName: "test-bar",
PeerServerAddresses: []string{"addr2"},
}))

View File

@ -116,7 +116,7 @@ func TestUINodes(t *testing.T) {
peerOne := &pbpeering.PeeringWriteRequest{
Peering: &pbpeering.Peering{
Name: "peer1",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},
@ -281,7 +281,7 @@ func TestUIServices(t *testing.T) {
},
},
},
//register api service on node foo
// register api service on node foo
{
Datacenter: "dc1",
Node: "foo",
@ -400,7 +400,7 @@ func TestUIServices(t *testing.T) {
peerOne := &pbpeering.PeeringWriteRequest{
Peering: &pbpeering.Peering{
Name: "peer1",
State: pbpeering.PeeringState_INITIAL,
State: pbpeering.PeeringState_ESTABLISHING,
PeerCAPems: nil,
PeerServerName: "fooservername",
PeerServerAddresses: []string{"addr1"},

View File

@ -14,9 +14,14 @@ const (
// writes.
PeeringStateUndefined PeeringState = "UNDEFINED"
// PeeringStateInitial means a Peering has been initialized and is awaiting
// acknowledgement from a remote peer.
PeeringStateInitial PeeringState = "INITIAL"
// PeeringStatePending means the peering was created by generating a peering token.
// Peerings stay in a pending state until the peer uses the token to dial
// the local cluster.
PeeringStatePending PeeringState = "PENDING"
// PeeringStateEstablishing means the peering is being established from a peering token.
// This is the initial state for dialing peers.
PeeringStateEstablishing PeeringState = "ESTABLISHING"
// PeeringStateActive means that the peering connection is active and
// healthy.
@ -26,6 +31,10 @@ const (
// but has not yet been terminated.
PeeringStateFailing PeeringState = "FAILING"
// PeeringStateDeleting means a peering was marked for deletion and is in the process
// of being deleted.
PeeringStateDeleting PeeringState = "DELETING"
// PeeringStateTerminated means the peering relationship has been removed.
PeeringStateTerminated PeeringState = "TERMINATED"
)

View File

@ -183,7 +183,7 @@ func TestAPI_Peering_GenerateToken_Read_Establish_Delete(t *testing.T) {
// token specific assertions on the "server"
require.Equal(t, "peer1", resp.Name)
require.Equal(t, PeeringStateInitial, resp.State)
require.Equal(t, PeeringStatePending, resp.State)
require.Equal(t, map[string]string{"foo": "bar"}, resp.Meta)
})
@ -205,7 +205,7 @@ func TestAPI_Peering_GenerateToken_Read_Establish_Delete(t *testing.T) {
require.NotNil(r, qm)
// require that the peering state is not undefined
require.Equal(r, PeeringStateInitial, resp.State)
require.Equal(r, PeeringStateEstablishing, resp.State)
require.Equal(r, map[string]string{"foo": "bar"}, resp.Meta)
})
})

View File

@ -144,12 +144,16 @@ func (b *PeeringTrustBundle) ConcatenatedRootPEMs() string {
// enumcover:PeeringState
func PeeringStateToAPI(s PeeringState) api.PeeringState {
switch s {
case PeeringState_INITIAL:
return api.PeeringStateInitial
case PeeringState_PENDING:
return api.PeeringStatePending
case PeeringState_ESTABLISHING:
return api.PeeringStateEstablishing
case PeeringState_ACTIVE:
return api.PeeringStateActive
case PeeringState_FAILING:
return api.PeeringStateFailing
case PeeringState_DELETING:
return api.PeeringStateDeleting
case PeeringState_TERMINATED:
return api.PeeringStateTerminated
case PeeringState_UNDEFINED:
@ -162,12 +166,16 @@ func PeeringStateToAPI(s PeeringState) api.PeeringState {
// enumcover:api.PeeringState
func PeeringStateFromAPI(t api.PeeringState) PeeringState {
switch t {
case api.PeeringStateInitial:
return PeeringState_INITIAL
case api.PeeringStatePending:
return PeeringState_PENDING
case api.PeeringStateEstablishing:
return PeeringState_ESTABLISHING
case api.PeeringStateActive:
return PeeringState_ACTIVE
case api.PeeringStateFailing:
return PeeringState_FAILING
case api.PeeringStateDeleting:
return PeeringState_DELETING
case api.PeeringStateTerminated:
return PeeringState_TERMINATED
case api.PeeringStateUndefined:

View File

@ -30,33 +30,44 @@ const (
// Undefined represents an unset value for PeeringState during
// writes.
PeeringState_UNDEFINED PeeringState = 0
// Initial means a Peering has been initialized and is awaiting
// acknowledgement from a remote peer.
PeeringState_INITIAL PeeringState = 1
// Pending means the peering was created by generating a peering token.
// Peerings stay in a pending state until the peer uses the token to dial
// the local cluster.
PeeringState_PENDING PeeringState = 1
// Establishing means the peering is being established from a peering token.
// This is the initial state for dialing peers.
PeeringState_ESTABLISHING PeeringState = 2
// Active means that the peering connection is active and healthy.
PeeringState_ACTIVE PeeringState = 2
PeeringState_ACTIVE PeeringState = 3
// Failing means the peering connection has been interrupted but has not yet
// been terminated.
PeeringState_FAILING PeeringState = 3
PeeringState_FAILING PeeringState = 4
// Deleting means a peering was marked for deletion and is in the process
// of being deleted.
PeeringState_DELETING PeeringState = 5
// Terminated means the peering relationship has been removed.
PeeringState_TERMINATED PeeringState = 4
PeeringState_TERMINATED PeeringState = 6
)
// Enum value maps for PeeringState.
var (
PeeringState_name = map[int32]string{
0: "UNDEFINED",
1: "INITIAL",
2: "ACTIVE",
3: "FAILING",
4: "TERMINATED",
1: "PENDING",
2: "ESTABLISHING",
3: "ACTIVE",
4: "FAILING",
5: "DELETING",
6: "TERMINATED",
}
PeeringState_value = map[string]int32{
"UNDEFINED": 0,
"INITIAL": 1,
"ACTIVE": 2,
"FAILING": 3,
"TERMINATED": 4,
"UNDEFINED": 0,
"PENDING": 1,
"ESTABLISHING": 2,
"ACTIVE": 3,
"FAILING": 4,
"DELETING": 5,
"TERMINATED": 6,
}
)
@ -2272,12 +2283,14 @@ var file_proto_pbpeering_peering_proto_rawDesc = []byte{
0x65, 0x64, 0x42, 0x09, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x29, 0x0a,
0x0d, 0x4c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x18,
0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2a, 0x53, 0x0a, 0x0c, 0x50, 0x65, 0x65, 0x72,
0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2a, 0x73, 0x0a, 0x0c, 0x50, 0x65, 0x65, 0x72,
0x69, 0x6e, 0x67, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, 0x45,
0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x4e, 0x49, 0x54, 0x49,
0x41, 0x4c, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x43, 0x54, 0x49, 0x56, 0x45, 0x10, 0x02,
0x12, 0x0b, 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x49, 0x4e, 0x47, 0x10, 0x03, 0x12, 0x0e, 0x0a,
0x0a, 0x54, 0x45, 0x52, 0x4d, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x44, 0x10, 0x04, 0x32, 0xed, 0x05,
0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49,
0x4e, 0x47, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53,
0x48, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x43, 0x54, 0x49, 0x56, 0x45,
0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x49, 0x4e, 0x47, 0x10, 0x04, 0x12,
0x0c, 0x0a, 0x08, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x49, 0x4e, 0x47, 0x10, 0x05, 0x12, 0x0e, 0x0a,
0x0a, 0x54, 0x45, 0x52, 0x4d, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x44, 0x10, 0x06, 0x32, 0xed, 0x05,
0x0a, 0x0e, 0x50, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x12, 0x4e, 0x0a, 0x0d, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65,
0x6e, 0x12, 0x1d, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x47, 0x65, 0x6e, 0x65,

View File

@ -39,19 +39,28 @@ enum PeeringState {
// writes.
UNDEFINED = 0;
// Initial means a Peering has been initialized and is awaiting
// acknowledgement from a remote peer.
INITIAL = 1;
// Pending means the peering was created by generating a peering token.
// Peerings stay in a pending state until the peer uses the token to dial
// the local cluster.
PENDING = 1;
// Establishing means the peering is being established from a peering token.
// This is the initial state for dialing peers.
ESTABLISHING = 2;
// Active means that the peering connection is active and healthy.
ACTIVE = 2;
ACTIVE = 3;
// Failing means the peering connection has been interrupted but has not yet
// been terminated.
FAILING = 3;
FAILING = 4;
// Deleting means a peering was marked for deletion and is in the process
// of being deleted.
DELETING = 5;
// Terminated means the peering relationship has been removed.
TERMINATED = 4;
TERMINATED = 6;
}
// Peering defines a peering relationship between two disparate Consul clusters