Skip to content

Commit

Permalink
Refactoring data_plane/main.go, control_plane/main.go and worker_node…
Browse files Browse the repository at this point in the history
…/main.go
  • Loading branch information
francois141 committed Feb 23, 2024
1 parent 04242b0 commit 67e9400
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 46 deletions.
4 changes: 2 additions & 2 deletions api/data_plane_api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type DpApiServer struct {
Proxy *proxy.ProxyingService
}

func NewDpApiServer(dataplane *data_plane.Dataplane) *DpApiServer {
func NewDpApiServer(dataPlane *data_plane.Dataplane) *DpApiServer {
return &DpApiServer{
dataplane: dataplane,
dataplane: dataPlane,
}
}

Expand Down
25 changes: 5 additions & 20 deletions cmd/data_plane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ import (
"cluster_manager/api"
"cluster_manager/api/proto"
"cluster_manager/internal/data_plane"
"cluster_manager/internal/data_plane/function_metadata"
"cluster_manager/pkg/config"
"cluster_manager/pkg/grpc_helpers"
"cluster_manager/pkg/logger"
"cluster_manager/pkg/network"
"context"
"cluster_manager/pkg/utils"
"flag"
"os/signal"
"syscall"

"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
Expand All @@ -34,12 +29,7 @@ func main() {

logger.SetupLogger(cfg.Verbosity)

if cfg.DataPlaneIp == "dynamic" {
cfg.DataPlaneIp = network.GetLocalIP()
}

cache := function_metadata.NewDeploymentList()
dataPlane := data_plane.NewDataplane(cfg, cache)
dataPlane := data_plane.NewDataplane(cfg)

apiServer := api.NewDpApiServer(dataPlane)

Expand All @@ -56,13 +46,8 @@ func main() {
go proxyServer.StartProxyServer()

go dataPlane.SetupHeartbeatLoop(proxyServer)
defer dataPlane.DeregisterControlPlaneConnection()

ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

select {
case <-ctx.Done():
logrus.Info("Received interruption signal, try to gracefully stop")
}
utils.WaitTerminationSignal(func() {
dataPlane.DeregisterControlPlaneConnection()
})
}
4 changes: 1 addition & 3 deletions cmd/simulator_workers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"cluster_manager/internal/data_plane"
"cluster_manager/internal/data_plane/function_metadata"
"cluster_manager/internal/worker_node"
"cluster_manager/pkg/config"
"cluster_manager/pkg/grpc_helpers"
Expand Down Expand Up @@ -45,8 +44,7 @@ func main() {
dataplanes := make([]*data_plane.Dataplane, 0)

for i := 0; i < *nbWorkers; i++ {
cache := function_metadata.NewDeploymentList()
dataPlane := data_plane.NewDataplane(cfg, cache)
dataPlane := data_plane.NewDataplane(cfg)
dataplanes = append(dataplanes, dataPlane)
}

Expand Down
21 changes: 6 additions & 15 deletions cmd/worker_node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import (
"cluster_manager/pkg/grpc_helpers"
"cluster_manager/pkg/logger"
"cluster_manager/pkg/network"
"context"
"cluster_manager/pkg/utils"
"flag"
"os/exec"
"os/signal"
"strconv"
"syscall"

"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"os/exec"
"strconv"
)

var (
Expand Down Expand Up @@ -59,19 +56,13 @@ func main() {
proto.RegisterWorkerNodeInterfaceServer(sr, api.NewWorkerNodeApi(workerNode))
})

ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

select {
case <-ctx.Done():
logrus.Info("Received interruption signal, try to gracefully stop")

utils.WaitTerminationSignal(func() {
firecracker.DeleteAllSnapshots()
err = firecracker.DeleteUnusedNetworkDevices()
err := firecracker.DeleteUnusedNetworkDevices()
if err != nil {
logrus.Warn("Interruption received, but failed to delete leftover network devices.")
}
}
})
}

func resetIPTables() {
Expand Down
2 changes: 1 addition & 1 deletion internal/control_plane/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *ControlPlane) RegisterDataplane(ctx context.Context, in *proto.Dataplan
}

func (c *ControlPlane) DeregisterDataplane(ctx context.Context, in *proto.DataplaneInfo) (*proto.ActionStatus, error) {
logrus.Trace("Received a data plane deregistration")
logrus.Info("Received a data plane deregistration")

dataplaneInfo := proto.DataplaneInformation{
Address: in.IP,
Expand Down
4 changes: 2 additions & 2 deletions internal/data_plane/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ type Dataplane struct {
deployments *function_metadata.Deployments
}

func NewDataplane(config config.DataPlaneConfig, deployements *function_metadata.Deployments) *Dataplane {
func NewDataplane(config config.DataPlaneConfig) *Dataplane {
return &Dataplane{
config: config,
deployments: deployements,
deployments: function_metadata.NewDeploymentList(),
}
}

Expand Down
4 changes: 1 addition & 3 deletions internal/data_plane/data_plane_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package data_plane

import (
"cluster_manager/internal/data_plane/function_metadata"
"cluster_manager/pkg/config"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
Expand All @@ -21,6 +20,5 @@ func TestCreationWorkerNode(t *testing.T) {
LoadBalancingPolicy: "",
}

cache := function_metadata.NewDeploymentList()
assert.NotNil(t, NewDataplane(mockConfig, cache), "Generated dataplane should not be nil")
assert.NotNil(t, NewDataplane(mockConfig), "Generated dataplane should not be nil")
}
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"cluster_manager/pkg/network"
"github.com/sirupsen/logrus"
"path/filepath"
"strings"
Expand Down Expand Up @@ -126,6 +127,10 @@ func ReadDataPlaneConfiguration(configPath string) (DataPlaneConfig, error) {
return DataPlaneConfig{}, err
}

if dataPlaneConfig.DataPlaneIp == "dynamic" {
dataPlaneConfig.DataPlaneIp = network.GetLocalIP()
}

return dataPlaneConfig, nil
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package utils

import (
"context"
"github.com/sirupsen/logrus"
"os/signal"
"syscall"
)

func WaitTerminationSignal(cleanFunction func()) {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

select {
case <-ctx.Done():
logrus.Info("Received interruption signal, try to gracefully stop")

cleanFunction()
}
}

0 comments on commit 67e9400

Please sign in to comment.