mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
pubapi: extract StartVPNAPIServer and StartUpdateLoop as separate functions
Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
parent
77b0237dd5
commit
f2b3fc328b
@ -95,16 +95,9 @@ func (a *API) ActivateAsCoordinator(in *pubproto.ActivateAsCoordinatorRequest, s
|
||||
}
|
||||
|
||||
// run the VPN-API server
|
||||
if err := a.vpnAPIServer.Listen(net.JoinHostPort(coordPeer.VPNIP, vpnAPIPort)); err != nil {
|
||||
if err := a.StartVPNAPIServer(coordPeer.VPNIP); err != nil {
|
||||
return status.Errorf(codes.Internal, "start vpnAPIServer: %v", err)
|
||||
}
|
||||
a.wgClose.Add(1)
|
||||
go func() {
|
||||
defer a.wgClose.Done()
|
||||
if err := a.vpnAPIServer.Serve(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
if err := a.core.SwitchToPersistentStore(); err != nil {
|
||||
return status.Errorf(codes.Internal, "switch to persistent store: %v", err)
|
||||
}
|
||||
|
@ -50,16 +50,9 @@ func (a *API) ActivateAsAdditionalCoordinator(ctx context.Context, in *pubproto.
|
||||
}
|
||||
|
||||
// run the VPN-API server
|
||||
if err := a.vpnAPIServer.Listen(net.JoinHostPort(in.AssignedVpnIp, vpnAPIPort)); err != nil {
|
||||
if err := a.StartVPNAPIServer(in.AssignedVpnIp); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "start vpnAPIServer: %v", err)
|
||||
}
|
||||
a.wgClose.Add(1)
|
||||
go func() {
|
||||
defer a.wgClose.Done()
|
||||
if err := a.vpnAPIServer.Serve(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
a.logger.Info("retrieving k8s join information ")
|
||||
joinArgs, certKey, err := a.getk8SCoordinatorJoinArgs(ctx, in.ActivatingCoordinatorData.VpnIp, vpnAPIPort)
|
||||
|
@ -142,8 +142,7 @@ func (a *API) ActivateAsNode(stream pubproto.API_ActivateAsNodeServer) (reterr e
|
||||
}
|
||||
|
||||
// regularly get (peer) updates from Coordinator
|
||||
a.wgClose.Add(1)
|
||||
go a.updateLoop()
|
||||
a.StartUpdateLoop()
|
||||
|
||||
/*
|
||||
coordinator <- VPN public key <- node
|
||||
@ -206,6 +205,12 @@ func (a *API) TriggerNodeUpdate(ctx context.Context, in *pubproto.TriggerNodeUpd
|
||||
return &pubproto.TriggerNodeUpdateResponse{}, nil
|
||||
}
|
||||
|
||||
// StartUpdateLoop starts a loop that will periodically request updates from the Coordinator.
|
||||
func (a *API) StartUpdateLoop() {
|
||||
a.wgClose.Add(1)
|
||||
go a.updateLoop()
|
||||
}
|
||||
|
||||
func (a *API) updateLoop() {
|
||||
defer a.wgClose.Done()
|
||||
ticker := time.NewTicker(updateInterval)
|
||||
|
@ -4,6 +4,7 @@ package pubapi
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
@ -55,6 +56,21 @@ func (a *API) GetState(ctx context.Context, in *pubproto.GetStateRequest) (*pubp
|
||||
return &pubproto.GetStateResponse{State: uint32(a.core.GetState())}, nil
|
||||
}
|
||||
|
||||
// StartVPNAPIServer starts the VPN-API server.
|
||||
func (a *API) StartVPNAPIServer(vpnIP string) error {
|
||||
if err := a.vpnAPIServer.Listen(net.JoinHostPort(vpnIP, vpnAPIPort)); err != nil {
|
||||
return fmt.Errorf("start vpnAPIServer: %v", err)
|
||||
}
|
||||
a.wgClose.Add(1)
|
||||
go func() {
|
||||
defer a.wgClose.Done()
|
||||
if err := a.vpnAPIServer.Serve(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the API.
|
||||
func (a *API) Close() {
|
||||
a.stopUpdate <- struct{}{}
|
||||
|
Loading…
Reference in New Issue
Block a user