Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of logger and build version in gvisor service lib… #1239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading