Skip to content

Commit

Permalink
Allow configuration of logger and build version in gvisor service lib…
Browse files Browse the repository at this point in the history
…rary
  • Loading branch information
maggie44 committed Oct 9, 2024
1 parent 16eaae3 commit df33175
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
15 changes: 14 additions & 1 deletion examples/go_service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"fmt"
"log"
"net"
"os"

"github.com/sirupsen/logrus"
"github.com/slackhq/nebula"
"github.com/slackhq/nebula/config"
"github.com/slackhq/nebula/overlay"
"github.com/slackhq/nebula/service"
)

Expand Down Expand Up @@ -59,7 +63,16 @@ pki:
if err := cfg.LoadString(configStr); err != nil {
return err
}
svc, err := service.New(&cfg)

logger := logrus.New()
logger.Out = os.Stdout

ctrl, err := nebula.Main(&cfg, false, "custom-app", logger, overlay.NewUserDeviceFromConfig)
if err != nil {
return err
}

svc, err := service.New(ctrl)
if err != nil {
return err
}
Expand Down
12 changes: 1 addition & 11 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import (
"math"
"net"
"net/netip"
"os"
"strings"
"sync"

"github.com/sirupsen/logrus"
"github.com/slackhq/nebula"
"github.com/slackhq/nebula/config"
"github.com/slackhq/nebula/overlay"
"golang.org/x/sync/errgroup"
"gvisor.dev/gvisor/pkg/buffer"
Expand Down Expand Up @@ -46,14 +43,7 @@ type Service struct {
}
}

func New(config *config.C) (*Service, error) {
logger := logrus.New()
logger.Out = os.Stdout

control, err := nebula.Main(config, false, "custom-app", logger, overlay.NewUserDeviceFromConfig)
if err != nil {
return nil, err
}
func New(control *nebula.Control) (*Service, error) {
control.Start()

ctx := control.Context()
Expand Down
14 changes: 13 additions & 1 deletion service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import (
"context"
"errors"
"net/netip"
"os"
"testing"
"time"

"dario.cat/mergo"
"github.com/sirupsen/logrus"
"github.com/slackhq/nebula"
"github.com/slackhq/nebula/cert"
"github.com/slackhq/nebula/config"
"github.com/slackhq/nebula/e2e"
"github.com/slackhq/nebula/overlay"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -71,7 +75,15 @@ func newSimpleService(caCrt *cert.NebulaCertificate, caKey []byte, name string,
panic(err)
}

s, err := New(&c)
logger := logrus.New()
logger.Out = os.Stdout

control, err := nebula.Main(&c, false, "custom-app", logger, overlay.NewUserDeviceFromConfig)
if err != nil {
panic(err)
}

s, err := New(control)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit df33175

Please sign in to comment.