Skip to content

Commit

Permalink
Move k8s, sriov files to sdk-k8s, sdk-sriov
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Dec 29, 2020
1 parent ccf7b5c commit c1964ca
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 1,130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- uses: actions/checkout@v2
- name: Restrict dependencies on github.com/networkservicemesh/*
env:
ALLOWED_REPOSITORIES: "sdk, api, sdk-kernel, sdk-sriov"
ALLOWED_REPOSITORIES: "sdk, api, sdk-kernel, sdk-sriov, sdk-k8s"
run: |
for i in $(grep github.com/networkservicemesh/ go.mod | grep -v '^module' | sed 's;.*\(github.com\/networkservicemesh\/[^ ]*\).*;\1;g');do
if ! [ "$(echo ${ALLOWED_REPOSITORIES} | grep ${i#github.com/networkservicemesh/})" ]; then
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ linters-settings:
golint:
min-confidence: 0.8
goimports:
local-prefixes: github.com/networkservicemesh/cmd-forwarder-sriov
local-prefixes: github.com/networkservicemesh
gocyclo:
min-complexity: 15
maligned:
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ require (
github.com/antonfisher/nested-logrus-formatter v1.1.0
github.com/edwarnicke/exechelper v1.0.2
github.com/edwarnicke/grpcfd v0.0.0-20200920223154-d5b6e1f19bd0
github.com/fsnotify/fsnotify v1.4.9
github.com/golang/protobuf v1.4.3
github.com/google/uuid v1.1.2
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20201204203731-4294f67deaa4
github.com/networkservicemesh/sdk v0.0.0-20201209081426-89944c40ef4d
github.com/networkservicemesh/sdk-kernel v0.0.0-20201209081811-0ca376659e99
github.com/networkservicemesh/sdk v0.0.0-20201228071212-4e3006826a6a
github.com/networkservicemesh/sdk-k8s v0.0.0-20201215144953-5c91828f35ea
github.com/networkservicemesh/sdk-sriov v0.0.0-20201214115506-af9f4fd3f099
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
Expand All @@ -21,3 +18,8 @@ require (
google.golang.org/grpc v1.33.2
k8s.io/kubelet v0.20.1
)

replace (
github.com/networkservicemesh/sdk-k8s => github.com/Bolodya1997/sdk-k8s v0.0.0-20201229032818-b04374a863b8
github.com/networkservicemesh/sdk-sriov => github.com/Bolodya1997/sdk-sriov v0.0.0-20201228124236-54f053b57119
)
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ github.com/Azure/go-autorest/autorest/mocks v0.4.0/go.mod h1:LTp+uSrOhSkaKrUy935
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/Bolodya1997/sdk-k8s v0.0.0-20201229032818-b04374a863b8 h1:hHDL4IZ+BBB3E5M+w0lno8HvBCMqzKkWLNwANFjmW1I=
github.com/Bolodya1997/sdk-k8s v0.0.0-20201229032818-b04374a863b8/go.mod h1:cssEp7fnK9Lao+1WVyMJgFO+DWm1vHZaUFUIrV9y7UM=
github.com/Bolodya1997/sdk-sriov v0.0.0-20201228124236-54f053b57119 h1:coBvrJuDEtJELs0LuWk/wVVtDEYRVdzSd6Vgy0F/dtc=
github.com/Bolodya1997/sdk-sriov v0.0.0-20201228124236-54f053b57119/go.mod h1:cwOvNo8dj9cmBkQa/QAaLx+n9tfSZdNzBne19Ra6gxo=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
Expand Down Expand Up @@ -395,12 +399,11 @@ 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-20201204203731-4294f67deaa4 h1:2HsHa5QtuMh5mjIqLWkiQx2cxFZMiYtQCvM8N7LjFVU=
github.com/networkservicemesh/api v0.0.0-20201204203731-4294f67deaa4/go.mod h1:qvxdY1Zt4QTtiG+uH1XmjpegeHjlt5Jj4A8iK55iJPI=
github.com/networkservicemesh/sdk v0.0.0-20201209081426-89944c40ef4d h1:sUVW+0ojn4+kY+Mw0MgZoIsLHqzyQBRExvQhJdlrYdM=
github.com/networkservicemesh/sdk v0.0.0-20201209081426-89944c40ef4d/go.mod h1:Mh4ETI2Sw9MJ4VSdTyvRYCP1SBtFy7EeRwxfJW7MvQ8=
github.com/networkservicemesh/sdk-kernel v0.0.0-20201209081811-0ca376659e99 h1:BNYQn9/yX4BQ0SUDfXeGRikoDJPcF0iYEARYtJHZQTI=
github.com/networkservicemesh/sdk-kernel v0.0.0-20201209081811-0ca376659e99/go.mod h1:8RTMv9NFwN1U6pucoOxhbjZW+pGVUMuX6RqPvqzfQsI=
github.com/networkservicemesh/sdk-sriov v0.0.0-20201214115506-af9f4fd3f099 h1:DMbqpHWb54cIK8SKA/NSCQPEoeavYEZIwOjukjG8Zts=
github.com/networkservicemesh/sdk-sriov v0.0.0-20201214115506-af9f4fd3f099/go.mod h1:CdsOsQdk4XqAajvy/gsvceY6M5hMkCSsQc25AvaSxog=
github.com/networkservicemesh/sdk v0.0.0-20201228071212-4e3006826a6a h1:LxbTguiX+B5x3y7vKpsPe3GLIZ2Nsbvm05rzEZFWC8s=
github.com/networkservicemesh/sdk v0.0.0-20201228071212-4e3006826a6a/go.mod h1:Mh4ETI2Sw9MJ4VSdTyvRYCP1SBtFy7EeRwxfJW7MvQ8=
github.com/networkservicemesh/sdk-kernel v0.0.0-20201228071507-284aec4d7ed1 h1:0qPtZfiJ4xtlL3B1tImPnwo3PBzjfmi/yPs+PLCqz8w=
github.com/networkservicemesh/sdk-kernel v0.0.0-20201228071507-284aec4d7ed1/go.mod h1:DDS5tKYsSSKhl3oKwn03wAq6tCUMOpy0JFE3r85/CPk=
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (
"sync"
"time"

pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1alpha1"

"github.com/networkservicemesh/sdk-k8s/pkg/deviceplugin"
"github.com/networkservicemesh/sdk-k8s/pkg/podresources"
"github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
"github.com/networkservicemesh/sdk/pkg/tools/log"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
podresources "k8s.io/kubelet/pkg/apis/podresources/v1alpha1"
)

// TokenPool is a token.Pool interface
Expand All @@ -37,14 +40,6 @@ type TokenPool interface {
Free(id string) error
}

// K8sManager is a bridge interface to the k8s API
type K8sManager interface {
StartDeviceServer(ctx context.Context, deviceServer pluginapi.DevicePluginServer) (string, error)
RegisterDeviceServer(ctx context.Context, request *pluginapi.RegisterRequest) error
MonitorKubeletRestart(ctx context.Context) (chan bool, error)
GetPodResourcesListerClient(ctx context.Context) (podresources.PodResourcesListerClient, error)
}

var _ pluginapi.DevicePluginServer = (*devicePluginServer)(nil)

type devicePluginServer struct {
Expand All @@ -55,26 +50,27 @@ type devicePluginServer struct {
resourcePollTimeout time.Duration
updateCh chan struct{}
allocatedTokens map[string]bool
resourceListerClient podresources.PodResourcesListerClient
resourceListerClient podresourcesapi.PodResourcesListerClient
}

// StartServers creates new SR-IOV forwarder device plugin servers and starts them
func StartServers(
ctx context.Context,
tokenPool TokenPool,
resourcePollTimeout time.Duration,
manager K8sManager,
devicePluginClient *deviceplugin.Client,
podResourcesClient *podresources.Client,
) error {
logEntry := log.Entry(ctx).WithField("devicePluginServer", "StartServers")

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

resp, err := resourceListerClient.List(ctx, new(podresources.ListPodResourcesRequest))
resp, err := resourceListerClient.List(ctx, new(podresourcesapi.ListPodResourcesRequest))
if err != nil {
logEntry.Errorf("resourceListerClient unavailable: %+v", err)
return err
Expand All @@ -95,14 +91,14 @@ func StartServers(
tokenPool.AddListener(s.update)

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

logEntry.Infof("registering server: %s", name)
if err := manager.RegisterDeviceServer(s.ctx, &pluginapi.RegisterRequest{
if err := devicePluginClient.RegisterDeviceServer(s.ctx, &pluginapi.RegisterRequest{
Version: pluginapi.Version,
Endpoint: socket,
ResourceName: name,
Expand All @@ -111,14 +107,14 @@ func StartServers(
return err
}

if err := s.monitorKubeletRestart(manager, socket); err != nil {
if err := s.monitorKubeletRestart(devicePluginClient, socket); err != nil {
logEntry.Warnf("error monitoring kubelet restart: %s %+v", name, err)
}
}
return nil
}

func respToDeviceIDs(resp *podresources.ListPodResourcesResponse) map[string][]string {
func respToDeviceIDs(resp *podresourcesapi.ListPodResourcesResponse) map[string][]string {
deviceIDs := map[string][]string{}
for _, pod := range resp.PodResources {
for _, container := range pod.Containers {
Expand All @@ -137,10 +133,10 @@ func (s *devicePluginServer) update() {
}
}

func (s *devicePluginServer) monitorKubeletRestart(manager K8sManager, socket string) error {
func (s *devicePluginServer) monitorKubeletRestart(devicePluginClient *deviceplugin.Client, socket string) error {
logEntry := log.Entry(s.ctx).WithField("devicePluginServer", "monitorKubeletRestart")

resetCh, err := manager.MonitorKubeletRestart(s.ctx)
resetCh, err := devicePluginClient.MonitorKubeletRestart(s.ctx)
if err != nil {
return err
}
Expand All @@ -157,12 +153,12 @@ func (s *devicePluginServer) monitorKubeletRestart(manager K8sManager, socket st
return
}
logEntry.Infof("re registering server: %s", s.name)
if err = manager.RegisterDeviceServer(s.ctx, &pluginapi.RegisterRequest{
if err = devicePluginClient.RegisterDeviceServer(s.ctx, &pluginapi.RegisterRequest{
Version: pluginapi.Version,
Endpoint: socket,
ResourceName: s.name,
}); err != nil {
logEntry.Errorf("error re registering server: %s %+v", s.name, err)
logEntry.Fatalf("error re registering server: %s %+v", s.name, err)
return
}
}
Expand All @@ -180,7 +176,7 @@ func (s *devicePluginServer) ListAndWatch(_ *pluginapi.Empty, server pluginapi.D
logEntry := log.Entry(s.ctx).WithField("devicePluginServer", "ListAndWatch")

for {
resp, err := s.resourceListerClient.List(s.ctx, new(podresources.ListPodResourcesRequest))
resp, err := s.resourceListerClient.List(s.ctx, new(podresourcesapi.ListPodResourcesRequest))
if err != nil {
logEntry.Errorf("resourceListerClient unavailable: %+v", err)
return err
Expand All @@ -203,7 +199,7 @@ func (s *devicePluginServer) ListAndWatch(_ *pluginapi.Empty, server pluginapi.D
}
}

func (s *devicePluginServer) respToDeviceIDs(resp *podresources.ListPodResourcesResponse) map[string]struct{} {
func (s *devicePluginServer) respToDeviceIDs(resp *podresourcesapi.ListPodResourcesResponse) map[string]struct{} {
deviceIDs := map[string]struct{}{}
for _, pod := range resp.PodResources {
for _, container := range pod.Containers {
Expand Down
31 changes: 3 additions & 28 deletions internal/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,22 @@ import (
_ "fmt"
_ "github.com/antonfisher/nested-logrus-formatter"
_ "github.com/edwarnicke/exechelper"
_ "github.com/fsnotify/fsnotify"
_ "github.com/golang/protobuf/ptypes"
_ "github.com/golang/protobuf/ptypes/empty"
_ "github.com/google/uuid"
_ "github.com/edwarnicke/grpcfd"
_ "github.com/kelseyhightower/envconfig"
_ "github.com/networkservicemesh/api/pkg/api/networkservice"
_ "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
_ "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
_ "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/noop"
_ "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vfio"
_ "github.com/networkservicemesh/api/pkg/api/registry"
_ "github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/resourcepool"
_ "github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/vfconfig"
_ "github.com/networkservicemesh/sdk-sriov/pkg/sriov"
_ "github.com/networkservicemesh/sdk-sriov/pkg/sriov/config"
_ "github.com/networkservicemesh/sdk-sriov/pkg/sriov/pci"
_ "github.com/networkservicemesh/sdk-sriov/pkg/sriov/resource"
_ "github.com/networkservicemesh/sdk-sriov/pkg/sriov/token"
_ "github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/clienturl"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/connect"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/expire"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/memory"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/recvfd"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/refresh"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/setid"
_ "github.com/networkservicemesh/sdk/pkg/registry/core/adapters"
_ "github.com/networkservicemesh/sdk/pkg/registry/core/chain"
_ "github.com/networkservicemesh/sdk/pkg/registry/memory"
_ "github.com/networkservicemesh/sdk/pkg/tools/addressof"
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
_ "github.com/networkservicemesh/sdk/pkg/tools/jaeger"
Expand All @@ -50,24 +30,19 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/tools/spanhelper"
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
_ "github.com/networkservicemesh/sdk/pkg/tools/spire"
_ "github.com/networkservicemesh/sdk/pkg/tools/token"
_ "github.com/pkg/errors"
_ "github.com/sirupsen/logrus"
_ "github.com/spiffe/go-spiffe/v2/bundle/x509bundle"
_ "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
_ "github.com/spiffe/go-spiffe/v2/svid/x509svid"
_ "github.com/spiffe/go-spiffe/v2/workloadapi"
_ "github.com/stretchr/testify/assert"
_ "github.com/stretchr/testify/mock"
_ "github.com/stretchr/testify/require"
_ "github.com/stretchr/testify/suite"
_ "google.golang.org/grpc"
_ "google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/health/grpc_health_v1"
_ "io/ioutil"
_ "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
_ "k8s.io/kubelet/pkg/apis/podresources/v1alpha1"
_ "net"
_ "net/url"
_ "os"
_ "path"
Expand Down
74 changes: 0 additions & 74 deletions internal/k8s/k8stest/deviceplugin/server.go

This file was deleted.

36 changes: 0 additions & 36 deletions internal/k8s/k8stest/podresources/server.go

This file was deleted.

Loading

0 comments on commit c1964ca

Please sign in to comment.