Add VPNIP to nodestate

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-04-28 10:10:02 +02:00 committed by Malte Poll
parent f2b3fc328b
commit f827e479b1
9 changed files with 14 additions and 8 deletions

View File

@ -225,13 +225,14 @@ func (c *Core) Initialize() (nodeActivated bool, err error) {
}
// PersistNodeState persists node state to disk.
func (c *Core) PersistNodeState(role role.Role, ownerID []byte, clusterID []byte) error {
func (c *Core) PersistNodeState(role role.Role, vpnIP string, ownerID []byte, clusterID []byte) error {
vpnPrivKey, err := c.vpn.GetPrivateKey()
if err != nil {
return fmt.Errorf("failed to retrieve VPN private key: %w", err)
}
nodeState := nodestate.NodeState{
Role: role,
VPNIP: vpnIP,
VPNPrivKey: vpnPrivKey,
OwnerID: ownerID,
ClusterID: clusterID,

View File

@ -268,7 +268,7 @@ func TestPersistNodeState(t *testing.T) {
}
core, err := NewCore(tc.vpn, nil, nil, nil, nil, nil, nil, zaptest.NewLogger(t), nil, nil, fileHandler)
require.NoError(err)
err = core.PersistNodeState(role.Coordinator, []byte("owner-id"), []byte("cluster-id"))
err = core.PersistNodeState(role.Coordinator, "192.0.2.1", []byte("owner-id"), []byte("cluster-id"))
if tc.wantErr {
assert.Error(err)
return
@ -278,6 +278,7 @@ func TestPersistNodeState(t *testing.T) {
assert.NoError(err)
assert.Equal(nodestate.NodeState{
Role: role.Coordinator,
VPNIP: "192.0.2.1",
VPNPrivKey: []byte("private-key"),
OwnerID: []byte("owner-id"),
ClusterID: []byte("cluster-id"),

View File

@ -13,6 +13,7 @@ const nodeStatePath = "/run/state/constellation/node_state.json"
// Can be persisted to disk and reloaded later.
type NodeState struct {
Role role.Role
VPNIP string
VPNPrivKey []byte
OwnerID []byte
ClusterID []byte

View File

@ -18,9 +18,10 @@ func TestFromFile(t *testing.T) {
wantErr bool
}{
"nodestate exists": {
fileContents: `{ "Role": "Coordinator", "VPNPrivKey": "dGVzdA==", "OwnerID": "T3duZXJJRA==", "ClusterID": "Q2x1c3RlcklE" }`,
fileContents: `{ "Role": "Coordinator", "VPNIP": "192.0.2.1", "VPNPrivKey": "dGVzdA==", "OwnerID": "T3duZXJJRA==", "ClusterID": "Q2x1c3RlcklE" }`,
wantState: &NodeState{
Role: role.Coordinator,
VPNIP: "192.0.2.1",
VPNPrivKey: []byte("test"),
OwnerID: []byte("OwnerID"),
ClusterID: []byte("ClusterID"),
@ -63,12 +64,14 @@ func TestToFile(t *testing.T) {
"writing works": {
state: &NodeState{
Role: role.Coordinator,
VPNIP: "192.0.2.1",
VPNPrivKey: []byte("test"),
OwnerID: []byte("OwnerID"),
ClusterID: []byte("ClusterID"),
},
wantFile: `{
"Role": "Coordinator",
"VPNIP": "192.0.2.1",
"VPNPrivKey": "dGVzdA==",
"OwnerID": "T3duZXJJRA==",
"ClusterID": "Q2x1c3RlcklE"

View File

@ -113,7 +113,7 @@ func (a *API) ActivateAsCoordinator(in *pubproto.ActivateAsCoordinatorRequest, s
return status.Errorf(codes.Internal, "node initialization: %v", err)
}
// persist node state on disk
if err := a.core.PersistNodeState(role.Coordinator, ownerID, clusterID); err != nil {
if err := a.core.PersistNodeState(role.Coordinator, coordPeer.VPNIP, ownerID, clusterID); err != nil {
return status.Errorf(codes.Internal, "persist node state: %v", err)
}
diskUUID, err := a.core.GetDiskUUID()

View File

@ -19,7 +19,7 @@ type Core interface {
GetNextCoordinatorIP() (string, error)
SwitchToPersistentStore() error
GetIDs(masterSecret []byte) (ownerID []byte, clusterID []byte, err error)
PersistNodeState(role role.Role, ownerID []byte, clusterID []byte) error
PersistNodeState(role role.Role, vpnIP string, ownerID []byte, clusterID []byte) error
SetUpKMS(ctx context.Context, storageURI, kmsURI, kekID string, useExisting bool) error
GetKMSInfo() (kms.KMSInformation, error)
GetDataKey(ctx context.Context, keyID string, length int) ([]byte, error)

View File

@ -129,7 +129,7 @@ func (c *fakeCore) JoinCluster(args *kubeadm.BootstrapTokenDiscovery, _ string,
return c.joinClusterErr
}
func (c *fakeCore) PersistNodeState(role role.Role, ownerID []byte, clusterID []byte) error {
func (c *fakeCore) PersistNodeState(role role.Role, vpnIP string, ownerID []byte, clusterID []byte) error {
c.persistNodeStateRoles = append(c.persistNodeStateRoles, role)
return c.persistNodeStateErr
}

View File

@ -85,7 +85,7 @@ func (a *API) ActivateAsAdditionalCoordinator(ctx context.Context, in *pubproto.
}
// persist node state on disk
if err := a.core.PersistNodeState(role.Coordinator, in.OwnerId, in.ClusterId); err != nil {
if err := a.core.PersistNodeState(role.Coordinator, in.AssignedVpnIp, in.OwnerId, in.ClusterId); err != nil {
return nil, status.Errorf(codes.Internal, "persist node state: %v", err)
}
diskUUID, err := a.core.GetDiskUUID()

View File

@ -106,7 +106,7 @@ func (a *API) ActivateAsNode(stream pubproto.API_ActivateAsNodeServer) (reterr e
}
// persist node state on disk
if err := a.core.PersistNodeState(role.Node, in.OwnerId, in.ClusterId); err != nil {
if err := a.core.PersistNodeState(role.Node, in.NodeVpnIp, in.OwnerId, in.ClusterId); err != nil {
return status.Errorf(codes.Internal, "persist node state: %v", err)
}