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 #65

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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ require (
github.com/edwarnicke/grpcfd v0.0.0-20200920223154-d5b6e1f19bd0
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-k8s v0.0.0-20210208125256-646833e9c8a5
github.com/networkservicemesh/sdk-sriov v0.0.0-20210208093945-dd849ad303ba
github.com/networkservicemesh/sdk v0.0.0-20210210091643-536f38f89868
github.com/networkservicemesh/sdk-k8s v0.0.0-20210210092208-aea47dd39d62
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.4.0.20200528145730-dc11d0c74e85
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,14 @@ 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-k8s v0.0.0-20210208125256-646833e9c8a5 h1:K7ICXheVFbhsmCIBQMbei2b5xsT3CR6gAUgPVGnNLP4=
github.com/networkservicemesh/sdk-k8s v0.0.0-20210208125256-646833e9c8a5/go.mod h1:wW4iQRDzBzKRPOP3Vqa8U2Xrz4SjNboVnCJ73Pc7FZU=
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-k8s v0.0.0-20210210092208-aea47dd39d62 h1:fIzYmGxJeadoxK5ECm7DlwViWDnpG/AY/4HGUDozAU0=
github.com/networkservicemesh/sdk-k8s v0.0.0-20210210092208-aea47dd39d62/go.mod h1:mj9UjnYfdLov9S7+YXMs8q2hryXiEQQh5YQ/sfRYgPQ=
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
38 changes: 19 additions & 19 deletions internal/deviceplugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/networkservicemesh/sdk-k8s/pkg/tools/deviceplugin"
"github.com/networkservicemesh/sdk-k8s/pkg/tools/podresources"
"github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
"github.com/networkservicemesh/sdk/pkg/tools/logger"
"github.com/networkservicemesh/sdk/pkg/tools/log"
)

// TokenPool is a token.Pool interface
Expand Down Expand Up @@ -63,18 +63,18 @@ func StartServers(
devicePluginClient *deviceplugin.Client,
podResourcesClient *podresources.Client,
) error {
logEntry := logger.Log(ctx).WithField("devicePluginServer", "StartServers")
logger := log.FromContext(ctx).WithField("devicePluginServer", "StartServers")

logEntry.Info("get resource lister client")
logger.Info("get resource lister client")
resourceListerClient, err := podResourcesClient.GetPodResourcesListerClient(ctx)
if err != nil {
logEntry.Error("failed to get resource lister client")
logger.Error("failed to get resource lister client")
return err
}

resp, err := resourceListerClient.List(ctx, new(podresourcesapi.ListPodResourcesRequest))
if err != nil {
logEntry.Errorf("resourceListerClient unavailable: %+v", err)
logger.Errorf("resourceListerClient unavailable: %+v", err)
return err
}
_ = tokenPool.Restore(respToDeviceIDs(resp))
Expand All @@ -92,25 +92,25 @@ func StartServers(

tokenPool.AddListener(s.update)

logEntry.Infof("starting server: %v", name)
logger.Infof("starting server: %v", name)
socket, err := devicePluginClient.StartDeviceServer(s.ctx, s)
if err != nil {
logEntry.Errorf("error starting server: %v", name)
logger.Errorf("error starting server: %v", name)
return err
}

logEntry.Infof("registering server: %s", name)
logger.Infof("registering server: %s", name)
if err := devicePluginClient.RegisterDeviceServer(s.ctx, &pluginapi.RegisterRequest{
Version: pluginapi.Version,
Endpoint: socket,
ResourceName: name,
}); err != nil {
logEntry.Errorf("error registering server: %s", name)
logger.Errorf("error registering server: %s", name)
return err
}

if err := s.monitorKubeletRestart(devicePluginClient, socket); err != nil {
logEntry.Warnf("error monitoring kubelet restart: %s %+v", name, err)
logger.Warnf("error monitoring kubelet restart: %s %+v", name, err)
}
}
return nil
Expand All @@ -136,16 +136,16 @@ func (s *devicePluginServer) update() {
}

func (s *devicePluginServer) monitorKubeletRestart(devicePluginClient *deviceplugin.Client, socket string) error {
logEntry := logger.Log(s.ctx).WithField("devicePluginServer", "monitorKubeletRestart")
logger := log.FromContext(s.ctx).WithField("devicePluginServer", "monitorKubeletRestart")

resetCh, err := devicePluginClient.MonitorKubeletRestart(s.ctx)
if err != nil {
return err
}

go func() {
logEntry.Infof("start monitoring kubelet restart: %s", s.name)
defer logEntry.Infof("stop monitoring kubelet restart: %s", s.name)
logger.Infof("start monitoring kubelet restart: %s", s.name)
defer logger.Infof("stop monitoring kubelet restart: %s", s.name)
for {
select {
case <-s.ctx.Done():
Expand All @@ -154,13 +154,13 @@ func (s *devicePluginServer) monitorKubeletRestart(devicePluginClient *deviceplu
if !ok {
return
}
logEntry.Infof("re registering server: %s", s.name)
logger.Infof("re registering server: %s", s.name)
if err = devicePluginClient.RegisterDeviceServer(s.ctx, &pluginapi.RegisterRequest{
Version: pluginapi.Version,
Endpoint: socket,
ResourceName: s.name,
}); err != nil {
logEntry.Fatalf("error re registering server: %s %+v", s.name, err)
logger.Fatalf("error re registering server: %s %+v", s.name, err)
return
}
}
Expand All @@ -175,25 +175,25 @@ func (s *devicePluginServer) GetDevicePluginOptions(_ context.Context, _ *plugin
}

func (s *devicePluginServer) ListAndWatch(_ *pluginapi.Empty, server pluginapi.DevicePlugin_ListAndWatchServer) error {
logEntry := logger.Log(s.ctx).WithField("devicePluginServer", "ListAndWatch")
logger := log.FromContext(s.ctx).WithField("devicePluginServer", "ListAndWatch")

for {
resp, err := s.resourceListerClient.List(s.ctx, new(podresourcesapi.ListPodResourcesRequest))
if err != nil {
logEntry.Errorf("resourceListerClient unavailable: %+v", err)
logger.Errorf("resourceListerClient unavailable: %+v", err)
return err
}

s.updateDevices(s.respToDeviceIDs(resp))

if err := server.Send(s.listAndWatchResponse()); err != nil {
logEntry.Errorf("server unavailable: %+v", err)
logger.Errorf("server unavailable: %+v", err)
return err
}

select {
case <-s.ctx.Done():
logEntry.Info("server stopped")
logger.Info("server stopped")
return s.ctx.Err()
case <-time.After(s.resourcePollTimeout):
case <-s.updateCh:
Expand Down
4 changes: 2 additions & 2 deletions internal/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "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/opentracing"
_ "github.com/networkservicemesh/sdk/pkg/tools/signalctx"
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
Expand Down
85 changes: 42 additions & 43 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/debug"
"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/opentracing"
"github.com/networkservicemesh/sdk/pkg/tools/signalctx"
"github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
Expand Down Expand Up @@ -87,79 +87,78 @@ func main() {
// setup logging
// ********************************************************************************
logrus.SetFormatter(&nested.Formatter{})
ctx, _ = logruslogger.New(
logger.WithFields(ctx, map[string]interface{}{"cmd": os.Args[0]}),
)
ctx = log.WithFields(ctx, map[string]interface{}{"cmd": os.Args[0]})
ctx = log.WithLog(ctx, logruslogger.New(ctx))

// ********************************************************************************
// Configure open tracing
// ********************************************************************************
logger.EnableTracing(true)
jaegerCloser := jaeger.InitJaeger("cmd-forwarder-sriov")
log.EnableTracing(true)
jaegerCloser := jaeger.InitJaeger(ctx, "cmd-forwarder-sriov")
defer func() { _ = jaegerCloser.Close() }()

// ********************************************************************************
// Debug self if necessary
// ********************************************************************************
if err := debug.Self(); err != nil {
logger.Log(ctx).Infof("%s", err)
log.FromContext(ctx).Infof("%s", err)
}

starttime := time.Now()

// enumerating phases
logger.Log(ctx).Infof("there are 8 phases which will be executed followed by a success message:")
logger.Log(ctx).Infof("the phases include:")
logger.Log(ctx).Infof("1: get config from environment")
logger.Log(ctx).Infof("2: get SR-IOV config from file")
logger.Log(ctx).Infof("3: init pools")
logger.Log(ctx).Infof("4: start device plugin server")
logger.Log(ctx).Infof("5: retrieve spiffe svid")
logger.Log(ctx).Infof("6: create sriovns network service endpoint")
logger.Log(ctx).Infof("7: create grpc server and register sriovns")
logger.Log(ctx).Infof("8: register xconnectns with the registry")
logger.Log(ctx).Infof("a final success message with start time duration")
log.FromContext(ctx).Infof("there are 8 phases which will be executed followed by a success message:")
log.FromContext(ctx).Infof("the phases include:")
log.FromContext(ctx).Infof("1: get config from environment")
log.FromContext(ctx).Infof("2: get SR-IOV config from file")
log.FromContext(ctx).Infof("3: init pools")
log.FromContext(ctx).Infof("4: start device plugin server")
log.FromContext(ctx).Infof("5: retrieve spiffe svid")
log.FromContext(ctx).Infof("6: create sriovns network service endpoint")
log.FromContext(ctx).Infof("7: create grpc server and register sriovns")
log.FromContext(ctx).Infof("8: register xconnectns with the registry")
log.FromContext(ctx).Infof("a final success message with start time duration")

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 1: get config from environment (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 1: get config from environment (time since start: %s)", time.Since(starttime))
// ********************************************************************************
config := &Config{}
if err := envconfig.Usage("nsm", config); err != nil {
logger.Log(ctx).Fatal(err)
log.FromContext(ctx).Fatal(err)
}
if err := envconfig.Process("nsm", config); err != nil {
logger.Log(ctx).Fatalf("error processing config from env: %+v", err)
log.FromContext(ctx).Fatalf("error processing config from env: %+v", err)
}

logger.Log(ctx).Infof("Config: %#v", config)
log.FromContext(ctx).Infof("Config: %#v", config)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 2: get SR-IOV config from file (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 2: get SR-IOV config from file (time since start: %s)", time.Since(starttime))
// ********************************************************************************
sriovConfig, err := sriovconfig.ReadConfig(ctx, config.SRIOVConfigFile)
if err != nil {
logger.Log(ctx).Fatalf("failed to get PCI resources config: %+v", err)
log.FromContext(ctx).Fatalf("failed to get PCI resources config: %+v", err)
}

if err = pci.UpdateConfig(config.PCIDevicesPath, config.PCIDriversPath, sriovConfig); err != nil {
logger.Log(ctx).Fatalf("failed to update PCI resources config with VFs: %+v", err)
log.FromContext(ctx).Fatalf("failed to update PCI resources config with VFs: %+v", err)
}

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 3: init pools (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 3: init pools (time since start: %s)", time.Since(starttime))
// ********************************************************************************

tokenPool := token.NewPool(sriovConfig)

pciPool, err := pci.NewPool(config.PCIDevicesPath, config.PCIDriversPath, config.VFIOPath, sriovConfig)
if err != nil {
logger.Log(ctx).Fatalf("failed to init PCI pool: %+v", err)
log.FromContext(ctx).Fatalf("failed to init PCI pool: %+v", err)
}

resourcePool := resource.NewPool(tokenPool, sriovConfig)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 4: start device plugin server (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 4: start device plugin server (time since start: %s)", time.Since(starttime))
// ********************************************************************************

// Start device plugin server
Expand All @@ -170,24 +169,24 @@ func main() {
k8sdeviceplugin.NewClient(config.DevicePluginPath),
k8spodresources.NewClient(config.PodResourcesPath),
); err != nil {
logger.Log(ctx).Fatalf("failed to start a device plugin server: %+v", err)
log.FromContext(ctx).Fatalf("failed to start a device plugin server: %+v", err)
}

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 5: retrieving svid, check spire agent logs if this is the last line you see (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 5: retrieving svid, check spire agent logs if this is the last line you see (time since start: %s)", time.Since(starttime))
// ********************************************************************************
source, err := workloadapi.NewX509Source(ctx)
if err != nil {
logger.Log(ctx).Fatalf("error getting x509 source: %+v", err)
log.FromContext(ctx).Fatalf("error getting x509 source: %+v", err)
}
svid, err := source.GetX509SVID()
if err != nil {
logger.Log(ctx).Fatalf("error getting x509 svid: %+v", err)
log.FromContext(ctx).Fatalf("error getting x509 svid: %+v", err)
}
logger.Log(ctx).Infof("SVID: %q", svid.ID)
log.FromContext(ctx).Infof("SVID: %q", svid.ID)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 6: create sriovns network service endpoint (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 6: create sriovns network service endpoint (time since start: %s)", time.Since(starttime))
// ********************************************************************************
endpoint := sriovns.NewServer(
ctx,
Expand All @@ -208,11 +207,11 @@ func main() {
)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 7: create grpc server and register sriovns (time since start: %s)", time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 7: create grpc server and register sriovns (time since start: %s)", time.Since(starttime))
// ********************************************************************************
tmpDir, err := ioutil.TempDir("", "sriov-forwarder")
if err != nil {
logger.Log(ctx).Fatalf("error creating tmpDir: %+v", err)
log.FromContext(ctx).Fatalf("error creating tmpDir: %+v", err)
}
defer func() { _ = os.RemoveAll(tmpDir) }()
listenOn := &url.URL{Scheme: "unix", Path: path.Join(tmpDir, "listen_on.io.sock")}
Expand All @@ -229,7 +228,7 @@ func main() {
exitOnErr(ctx, cancel, srvErrCh)

// ********************************************************************************
logger.Log(ctx).Infof("executing phase 8: register %s with the registry (time since start: %s)", config.NSName, time.Since(starttime))
log.FromContext(ctx).Infof("executing phase 8: register %s with the registry (time since start: %s)", config.NSName, time.Since(starttime))
// ********************************************************************************
clientOptions := append(
opentracing.WithTracingDial(),
Expand All @@ -248,7 +247,7 @@ func main() {
clientOptions...,
)
if err != nil {
logger.Log(ctx).Fatalf("failed to connect to registry: %+v", err)
log.FromContext(ctx).Fatalf("failed to connect to registry: %+v", err)
}

registryClient := registrychain.NewNetworkServiceEndpointRegistryClient(
Expand All @@ -263,10 +262,10 @@ func main() {
Url: grpcutils.URLToTarget(listenOn),
})
if err != nil {
logger.Log(ctx).Fatalf("failed to connect to registry: %+v", err)
log.FromContext(ctx).Fatalf("failed to connect to registry: %+v", err)
}

logger.Log(ctx).Infof("Startup completed in %v", time.Since(starttime))
log.FromContext(ctx).Infof("Startup completed in %v", time.Since(starttime))

<-ctx.Done()
}
Expand All @@ -275,13 +274,13 @@ func exitOnErr(ctx context.Context, cancel context.CancelFunc, errCh <-chan erro
// If we already have an error, log it and exit
select {
case err := <-errCh:
logger.Log(ctx).Fatal(err)
log.FromContext(ctx).Fatal(err)
default:
}
// Otherwise wait for an error in the background to log and cancel
go func(ctx context.Context, errCh <-chan error) {
err := <-errCh
logger.Log(ctx).Error(err)
log.FromContext(ctx).Error(err)
cancel()
}(ctx, errCh)
}
Loading