-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benedict Schlueter <[email protected]>
- Loading branch information
1 parent
e937b3c
commit 414c9f7
Showing
37 changed files
with
2,142 additions
and
1,973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* SPDX-License-Identifier: AGPL-3.0-only | ||
* Copyright (c) Benedict Schlueter | ||
*/ | ||
|
||
package containerapi | ||
|
||
// Core interface contains functions to access the state Core data. | ||
type Core interface{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* SPDX-License-Identifier: AGPL-3.0-only | ||
* Copyright (c) Benedict Schlueter | ||
* Copyright (c) Edgeless Systems GmbH | ||
*/ | ||
|
||
package core | ||
|
||
import ( | ||
"sync" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// Core is responsible for maintaining state information of the container-agent. | ||
type Core struct { | ||
zaplogger *zap.Logger | ||
mux sync.Mutex | ||
} | ||
|
||
// NewCore creates and initializes a new Core object. | ||
func NewCore(zapLogger *zap.Logger) (*Core, error) { | ||
c := &Core{ | ||
zaplogger: zapLogger, | ||
mux: sync.Mutex{}, | ||
} | ||
return c, nil | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* SPDX-License-Identifier: AGPL-3.0-only | ||
* Copyright (c) Edgeless Systems GmbH | ||
* Copyright (c) Benedict Schlueter | ||
* Copyright (c) Leonard Cohnen | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"sync" | ||
|
||
"github.com/benschlueter/delegatio/agent/manageapi" | ||
"github.com/benschlueter/delegatio/agent/manageapi/manageproto" | ||
"github.com/benschlueter/delegatio/agent/vm/core" | ||
"github.com/benschlueter/delegatio/agent/vm/core/state" | ||
"github.com/benschlueter/delegatio/internal/config" | ||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" | ||
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" | ||
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" | ||
"go.uber.org/zap" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
var version = "0.0.0" | ||
|
||
/* | ||
* This will run on the VM's bare matel. We try to contact the control plane | ||
* via the loadbalancerIPAddr to give us the join token. At the same time | ||
* we are waiting for the init-request from a user *only* if we are a control plane. | ||
*/ | ||
func run(dialer manageapi.Dialer, bindIP, bindPort string, zapLoggerCore *zap.Logger, containerMode *bool, loadbalancerIPAddr string) { | ||
defer func() { _ = zapLoggerCore.Sync() }() | ||
zapLoggerCore.Info("starting delegatio agent", zap.String("version", version), zap.String("commit", config.Commit)) | ||
|
||
if *containerMode { | ||
zapLoggerCore.Info("running in container mode") | ||
} else { | ||
zapLoggerCore.Info("running in qemu mode") | ||
} | ||
|
||
core, err := core.NewCore(zapLoggerCore, loadbalancerIPAddr) | ||
if err != nil { | ||
zapLoggerCore.Fatal("failed to create core", zap.Error(err)) | ||
} | ||
|
||
vapi := manageapi.New(zapLoggerCore.Named("vmapi"), core, dialer) | ||
zapLoggergRPC := zapLoggerCore.Named("gRPC") | ||
|
||
grpcServer := grpc.NewServer( | ||
grpc.Creds(insecure.NewCredentials()), | ||
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( | ||
grpc_ctxtags.StreamServerInterceptor(), | ||
grpc_zap.StreamServerInterceptor(zapLoggergRPC), | ||
)), | ||
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( | ||
grpc_ctxtags.UnaryServerInterceptor(), | ||
grpc_zap.UnaryServerInterceptor(zapLoggergRPC), | ||
)), | ||
) | ||
manageproto.RegisterAPIServer(grpcServer, vapi) | ||
|
||
lis, err := net.Listen("tcp", net.JoinHostPort(bindIP, bindPort)) | ||
if err != nil { | ||
zapLoggergRPC.Fatal("failed to create listener", zap.Error(err)) | ||
} | ||
zapLoggergRPC.Info("server listener created", zap.String("address", lis.Addr().String())) | ||
core.State.Advance(state.AcceptingInit) | ||
go core.TryJoinCluster(context.Background()) | ||
|
||
var wg sync.WaitGroup | ||
defer wg.Wait() | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
if err := grpcServer.Serve(lis); err != nil { | ||
zapLoggergRPC.Fatal("failed to serve gRPC", zap.Error(err)) | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* SPDX-License-Identifier: AGPL-3.0-only | ||
* Copyright (c) Benedict Schlueter | ||
*/ | ||
|
||
package manageapi | ||
|
||
// Core interface contains functions to access the state Core data. | ||
type Core interface{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.