mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-13 00:19:32 -05:00
Add VPNIP to nodestate
Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
parent
f2b3fc328b
commit
f827e479b1
@ -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,
|
||||
|
@ -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"),
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user