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

Update to latest sdk version #116

Merged
merged 1 commit into from
Feb 10, 2021
Merged
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/golang/protobuf v1.4.3
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a
github.com/networkservicemesh/sdk v0.0.0-20210208092844-64f6aa269f63
github.com/networkservicemesh/sdk-sriov v0.0.0-20210208093945-dd849ad303ba
github.com/networkservicemesh/sdk v0.0.0-20210210091643-536f38f89868
github.com/networkservicemesh/sdk-sriov v0.0.0-20210210092545-5fb85f02b717
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-alpha.5
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ github.com/nats-io/stan.go v0.6.0/go.mod h1:eIcD5bi3pqbHT/xIIvXMwvzXYElgouBvaVRf
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a h1:26MmmU399gnahAC+f6OfWsP5MpnLdJ4UjvBa6fXYvNU=
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a/go.mod h1:qvxdY1Zt4QTtiG+uH1XmjpegeHjlt5Jj4A8iK55iJPI=
github.com/networkservicemesh/sdk v0.0.0-20210208092844-64f6aa269f63 h1:fDvXYI18q3+DIN2zuljZXavL7IILWun2zafTa4llUG8=
github.com/networkservicemesh/sdk v0.0.0-20210208092844-64f6aa269f63/go.mod h1:gqv+RfDum4HBeZA0k+F96mT2m0rh9LZTUazjtsLJ0Bs=
github.com/networkservicemesh/sdk-kernel v0.0.0-20210208093311-df0699f3186a h1:RE6Etv1dKaTFvBCHIheDop9DwD3Fyf92TNo5MhY14BM=
github.com/networkservicemesh/sdk-kernel v0.0.0-20210208093311-df0699f3186a/go.mod h1:PnV7GDtJGsSKtCBOHfy2Xg+69QqOPXm9w8IFpxtd9Hw=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210208093945-dd849ad303ba h1:sCz0K3btn1uzOl80sIVney7keH4Znd1zt3eLiQjsEy4=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210208093945-dd849ad303ba/go.mod h1:pHgSsk4ml826iC683V7wa5CSG9RlWTwbECbIg8GyVzw=
github.com/networkservicemesh/sdk v0.0.0-20210210091643-536f38f89868 h1:RaWXfrgwhu8Z/JNIEz1RimIN7TiGXioiUvzHZAId8UE=
github.com/networkservicemesh/sdk v0.0.0-20210210091643-536f38f89868/go.mod h1:gqv+RfDum4HBeZA0k+F96mT2m0rh9LZTUazjtsLJ0Bs=
github.com/networkservicemesh/sdk-kernel v0.0.0-20210210091935-d4c73a293f16 h1:wbAuETDODEuIdCI3Xvm0QWu6CuORS1F42kaAtP+v3Oo=
github.com/networkservicemesh/sdk-kernel v0.0.0-20210210091935-d4c73a293f16/go.mod h1:006SEFrd2R5LlwYhSqIwFHGw2dW9X5b6jUSD6kE/x4s=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210210092545-5fb85f02b717 h1:ovfexhDA3J6a7pABCK9htzpjnVcrHd6jUOqWR8SajXM=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210210092545-5fb85f02b717/go.mod h1:HnINRJdVBUQ0mIVFx7rTkM4EmQvsSpUXjDXS6QlDVTs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nishanths/exhaustive v0.0.0-20200811152831-6cf413ae40e0/go.mod h1:wBEpHwM2OdmeNpdCvRPUlkEbBuaFmcK4Wv8Q7FuGW3c=
Expand Down
47 changes: 23 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/jaeger"
"github.com/networkservicemesh/sdk/pkg/tools/logger"
"github.com/networkservicemesh/sdk/pkg/tools/logger/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/nsurl"
"github.com/networkservicemesh/sdk/pkg/tools/opentracing"
"github.com/networkservicemesh/sdk/pkg/tools/signalctx"
Expand All @@ -74,39 +74,38 @@ func main() {
// ********************************************************************************
logrus.Info("Starting NetworkServiceMesh Client ...")
logrus.SetFormatter(&nested.Formatter{})
ctx, _ = logruslogger.New(
logger.WithFields(ctx, map[string]interface{}{"cmd": os.Args[:1]}),
)
ctx = log.WithFields(ctx, map[string]interface{}{"cmd": os.Args[:1]})
ctx = log.WithLog(ctx, logruslogger.New(ctx))

// ********************************************************************************
// Configure open tracing
// ********************************************************************************
// Enable Jaeger
logger.EnableTracing(true)
jaegerCloser := jaeger.InitJaeger("nsc")
log.EnableTracing(true)
jaegerCloser := jaeger.InitJaeger(ctx, "nsc")
defer func() { _ = jaegerCloser.Close() }()

// ********************************************************************************
// Get config from environment
// ********************************************************************************
rootConf := &config.Config{}
if err := envconfig.Usage("nsm", rootConf); err != nil {
logger.Log(ctx).Fatal(err)
log.FromContext(ctx).Fatal(err)
}
if err := envconfig.Process("nsm", rootConf); err != nil {
logger.Log(ctx).Fatalf("error processing rootConf from env: %+v", err)
log.FromContext(ctx).Fatalf("error processing rootConf from env: %+v", err)
}

logger.Log(ctx).Infof("rootConf: %+v", rootConf)
log.FromContext(ctx).Infof("rootConf: %+v", rootConf)

// ********************************************************************************
// Connect to NSMgr
// ********************************************************************************
cleanup, err := RunClient(ctx, rootConf, nsmClientFactory(ctx, rootConf))
if err != nil {
logger.Log(ctx).Fatalf("failed to connect to network services: %v", err.Error())
log.FromContext(ctx).Fatalf("failed to connect to network services: %v", err.Error())
} else {
logger.Log(ctx).Infof("All client init operations are done.")
log.FromContext(ctx).Infof("All client init operations are done.")
}

// Wait for cancel event to terminate
Expand All @@ -115,7 +114,7 @@ func main() {
// ********************************************************************************
// Cleanup connections
// ********************************************************************************
logger.Log(ctx).Infof("Performing cleanup of connections due terminate...")
log.FromContext(ctx).Infof("Performing cleanup of connections due terminate...")

ctx, cancel = context.WithTimeout(context.Background(), rootConf.DialTimeout)
defer cancel()
Expand All @@ -129,22 +128,22 @@ func nsmClientFactory(ctx context.Context, rootConf *config.Config) func(...netw
// ********************************************************************************
source, err := workloadapi.NewX509Source(ctx)
if err != nil {
logger.Log(ctx).Fatalf("error getting x509 source: %v", err.Error())
log.FromContext(ctx).Fatalf("error getting x509 source: %v", err.Error())
}
var svid *x509svid.SVID
svid, err = source.GetX509SVID()
if err != nil {
logger.Log(ctx).Fatalf("error getting x509 svid: %v", err.Error())
log.FromContext(ctx).Fatalf("error getting x509 svid: %v", err.Error())
}
logger.Log(ctx).Infof("sVID: %q", svid.ID)
log.FromContext(ctx).Infof("sVID: %q", svid.ID)

// ********************************************************************************
// Connect to NSManager
// ********************************************************************************
connectCtx, cancel := context.WithTimeout(ctx, rootConf.DialTimeout)
defer cancel()

logger.Log(ctx).Infof("NSC: Connecting to Network Service Manager %v", rootConf.ConnectTo.String())
log.FromContext(ctx).Infof("NSC: Connecting to Network Service Manager %v", rootConf.ConnectTo.String())
var clientCC *grpc.ClientConn
clientCC, err = grpc.DialContext(
connectCtx,
Expand All @@ -160,7 +159,7 @@ func nsmClientFactory(ctx context.Context, rootConf *config.Config) func(...netw
))...,
)
if err != nil {
logger.Log(ctx).Fatalf("failed to dial NSM: %v", err.Error())
log.FromContext(ctx).Fatalf("failed to dial NSM: %v", err.Error())
}

// ********************************************************************************
Expand Down Expand Up @@ -197,14 +196,14 @@ func RunClient(
}

// Setup logging
ctx, _ = logruslogger.New(ctx)
ctx = log.WithLog(ctx, logruslogger.New(ctx))

// ********************************************************************************
// Initiate connections
// ********************************************************************************
for i := range rootConf.NetworkServices {
connID := fmt.Sprintf("%s-%d", rootConf.Name, i)
logger.Log(ctx).Infof("request: %v", connID)
log.FromContext(ctx).Infof("request: %v", connID)

// Update network services configs
u := (*nsurl.NSURL)(&rootConf.NetworkServices[i])
Expand Down Expand Up @@ -234,7 +233,7 @@ func RunClient(
var cgroupDir string
cgroupDir, err = cgroupDirPath()
if err != nil {
logger.Log(ctx).Errorf("failed to get devices cgroup: %v", err.Error())
log.FromContext(ctx).Errorf("failed to get devices cgroup: %v", err.Error())
continue
}
clients = append(clients, vfio.NewClient("/dev/vfio", cgroupDir))
Expand All @@ -248,11 +247,11 @@ func RunClient(
// Performing nsmClient connection request
conn, err := nsmClient.Request(ctx, request)
if err != nil {
logger.Log(ctx).Errorf("failed to request network service with %v: err %v", request, err.Error())
log.FromContext(ctx).Errorf("failed to request network service with %v: err %v", request, err.Error())
continue
}

logger.Log(ctx).Infof("network service established with %v\n Connection: %v", request, conn)
log.FromContext(ctx).Infof("network service established with %v\n Connection: %v", request, conn)

// Add connection cleanup
cleanupPrevious := cleanup
Expand All @@ -262,7 +261,7 @@ func RunClient(
}
_, err := nsmClient.Close(cleanupCtx, conn)
if err != nil {
logger.Log(ctx).Warnf("failed to close connection %v cause: %v", conn, err.Error())
log.FromContext(ctx).Warnf("failed to close connection %v cause: %v", conn, err.Error())
}
}
}
Expand Down