diff --git a/coordinator/core/core.go b/coordinator/core/core.go index 405c1fca4..299bb18f2 100644 --- a/coordinator/core/core.go +++ b/coordinator/core/core.go @@ -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, diff --git a/coordinator/core/core_test.go b/coordinator/core/core_test.go index 001ef587c..de900776a 100644 --- a/coordinator/core/core_test.go +++ b/coordinator/core/core_test.go @@ -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"), diff --git a/coordinator/nodestate/nodestate.go b/coordinator/nodestate/nodestate.go index 30d5532de..5ee224696 100644 --- a/coordinator/nodestate/nodestate.go +++ b/coordinator/nodestate/nodestate.go @@ -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 diff --git a/coordinator/nodestate/nodestate_test.go b/coordinator/nodestate/nodestate_test.go index 53e11e977..dd9c2acfd 100644 --- a/coordinator/nodestate/nodestate_test.go +++ b/coordinator/nodestate/nodestate_test.go @@ -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" diff --git a/coordinator/pubapi/coord.go b/coordinator/pubapi/coord.go index 9ba88eefe..78aa371de 100644 --- a/coordinator/pubapi/coord.go +++ b/coordinator/pubapi/coord.go @@ -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() diff --git a/coordinator/pubapi/core.go b/coordinator/pubapi/core.go index 1994045f3..2f023e4ec 100644 --- a/coordinator/pubapi/core.go +++ b/coordinator/pubapi/core.go @@ -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) diff --git a/coordinator/pubapi/core_test.go b/coordinator/pubapi/core_test.go index ece9b392c..334556425 100644 --- a/coordinator/pubapi/core_test.go +++ b/coordinator/pubapi/core_test.go @@ -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 } diff --git a/coordinator/pubapi/multicoord.go b/coordinator/pubapi/multicoord.go index 0a7398cf8..5951315d0 100644 --- a/coordinator/pubapi/multicoord.go +++ b/coordinator/pubapi/multicoord.go @@ -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() diff --git a/coordinator/pubapi/node.go b/coordinator/pubapi/node.go index 5076c2e6f..a51fb26df 100644 --- a/coordinator/pubapi/node.go +++ b/coordinator/pubapi/node.go @@ -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) }