Skip to content

Commit

Permalink
Merge pull request microsoft#1239 from katiewasnothere/ncproxy_networ…
Browse files Browse the repository at this point in the history
…k_endpoint

Update ncproxy to include new ncproxy network and endpoint types
  • Loading branch information
katiewasnothere authored Jan 20, 2022
2 parents 7c1d1da + 033c894 commit 6cee62b
Show file tree
Hide file tree
Showing 17 changed files with 1,146 additions and 183 deletions.
128 changes: 86 additions & 42 deletions computeagent/computeagent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions computeagent/computeagent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ message AssignPCIInternalRequest {
string container_id = 1;
string device_id = 2;
uint32 virtual_function_index = 3;
string nic_id = 4;
}

message AssignPCIInternalResponse {
Expand Down
2 changes: 1 addition & 1 deletion devices/assigned_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func AddDevice(ctx context.Context, vm *uvm.UtilityVM, idType, deviceID string,
}
}()
if idType == uvm.VPCIDeviceIDType || idType == uvm.VPCIDeviceIDTypeLegacy {
vpci, err = vm.AssignDevice(ctx, deviceID, index)
vpci, err = vm.AssignDevice(ctx, deviceID, index, "")
if err != nil {
return vpci, nil, errors.Wrapf(err, "failed to assign device %s of type %s to pod %s", deviceID, idType, vm.ID())
}
Expand Down
17 changes: 9 additions & 8 deletions devices/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func execModprobeInstallDriver(ctx context.Context, vm *uvm.UtilityVM, driverDir
}
defer l.Close()

var pipeResults []string
var stderrOutput string
errChan := make(chan error)

go readCsPipeOutput(l, errChan, &pipeResults)
go readAllPipeOutput(l, errChan, &stderrOutput)

args := []string{
"/bin/install-drivers",
Expand All @@ -74,19 +74,20 @@ func execModprobeInstallDriver(ctx context.Context, vm *uvm.UtilityVM, driverDir
Stderr: p,
}

exitCode, err := cmd.ExecInUvm(ctx, vm, req)
if err != nil && err != noExecOutputErr {
return errors.Wrapf(err, "failed to install driver %s in uvm with exit code %d", driverDir, exitCode)
}
exitCode, execErr := cmd.ExecInUvm(ctx, vm, req)

// wait to finish parsing stdout results
select {
case err := <-errChan:
if err != nil {
return err
return errors.Wrap(err, execErr.Error())
}
case <-ctx.Done():
return ctx.Err()
return errors.Wrap(ctx.Err(), execErr.Error())
}

if execErr != nil && execErr != noExecOutputErr {
return errors.Wrapf(execErr, "failed to install driver %s in uvm with exit code %d: %v", driverDir, exitCode, stderrOutput)
}

log.G(ctx).WithField("added drivers", driverDir).Debug("installed drivers")
Expand Down
27 changes: 27 additions & 0 deletions devices/pnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,30 @@ func readCsPipeOutput(l net.Listener, errChan chan<- error, result *[]string) {

errChan <- nil
}

// readAllPipeOutput is a helper function that connects to a listener and attempts to
// read the connection's entire output. Resulting output is returned as a string
// in the `result` param. The `errChan` param is used to propagate an errors to
// the calling function.
func readAllPipeOutput(l net.Listener, errChan chan<- error, result *string) {
defer close(errChan)
c, err := l.Accept()
if err != nil {
errChan <- errors.Wrapf(err, "failed to accept named pipe")
return
}
bytes, err := ioutil.ReadAll(c)
if err != nil {
errChan <- err
return
}

*result = string(bytes)

if len(*result) == 0 {
errChan <- noExecOutputErr
return
}

errChan <- nil
}
2 changes: 1 addition & 1 deletion hcsoci/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func handleAssignedDevicesLCOW(
case uvm.VPCIDeviceIDType, uvm.VPCIDeviceIDTypeLegacy, uvm.GPUDeviceIDType:
gpuPresent = gpuPresent || d.IDType == uvm.GPUDeviceIDType
pciID, index := getDeviceInfoFromPath(d.ID)
vpci, err := vm.AssignDevice(ctx, pciID, index)
vpci, err := vm.AssignDevice(ctx, pciID, index, "")
if err != nil {
return resultDevs, closers, errors.Wrapf(err, "failed to assign device %s, function %d to pod %s", pciID, index, vm.ID())
}
Expand Down
33 changes: 33 additions & 0 deletions ncproxy/networking/endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package networking

type Endpoint struct {
EndpointName string
NamespaceID string
Settings *EndpointSettings
}

type EndpointSettings struct {
Name string
Macaddress string
IPAddress string
IPAddressPrefixLength uint32
NetworkName string
DefaultGateway string
DeviceDetails *DeviceDetails
}

type DeviceDetails struct {
PCIDeviceDetails *PCIDeviceDetails
}

type PCIDeviceDetails struct {
DeviceID string
VirtualFunctionIndex uint32
}

func NewEndpoint(settings *EndpointSettings) (*Endpoint, error) {
return &Endpoint{
EndpointName: settings.Name,
Settings: settings,
}, nil
}
17 changes: 17 additions & 0 deletions ncproxy/networking/networks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package networking

type Network struct {
NetworkName string
Settings *NetworkSettings
}

type NetworkSettings struct {
Name string
}

func NewNetwork(settings *NetworkSettings) (*Network, error) {
return &Network{
NetworkName: settings.Name,
Settings: settings,
}, nil
}
77 changes: 77 additions & 0 deletions ncproxy/store/buckets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package store

import (
bolt "go.etcd.io/bbolt"
)

const schemaVersion = "v1"

var (
bucketKeyVersion = []byte(schemaVersion)

bucketKeyNetwork = []byte("network")
bucketKeyEndpoint = []byte("endpoint")
bucketKeyComputeAgent = []byte("computeagent")
)

// Below is the current database schema. This should be updated any time the schema is
// changed or updated. The version should be incremented if breaking changes are made.
// └──v1 - Schema version bucket
// └──computeagent - Compute agent bucket
// └──containerID : <string> - Entry in compute agent bucket: Address to
// the compute agent for containerID

// taken from containerd/containerd/metadata/buckets.go
func getBucket(tx *bolt.Tx, keys ...[]byte) *bolt.Bucket {
bkt := tx.Bucket(keys[0])

for _, key := range keys[1:] {
if bkt == nil {
break
}
bkt = bkt.Bucket(key)
}

return bkt
}

// taken from containerd/containerd/metadata/buckets.go
func createBucketIfNotExists(tx *bolt.Tx, keys ...[]byte) (*bolt.Bucket, error) {
bkt, err := tx.CreateBucketIfNotExists(keys[0])
if err != nil {
return nil, err
}

for _, key := range keys[1:] {
bkt, err = bkt.CreateBucketIfNotExists(key)
if err != nil {
return nil, err
}
}

return bkt, nil
}

func createNetworkBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
return createBucketIfNotExists(tx, bucketKeyVersion, bucketKeyNetwork)
}

func getNetworkBucket(tx *bolt.Tx) *bolt.Bucket {
return getBucket(tx, bucketKeyVersion, bucketKeyNetwork)
}

func createEndpointBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
return createBucketIfNotExists(tx, bucketKeyVersion, bucketKeyEndpoint)
}

func getEndpointBucket(tx *bolt.Tx) *bolt.Bucket {
return getBucket(tx, bucketKeyVersion, bucketKeyEndpoint)
}

func createComputeAgentBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
return createBucketIfNotExists(tx, bucketKeyVersion, bucketKeyComputeAgent)
}

func getComputeAgentBucket(tx *bolt.Tx) *bolt.Bucket {
return getBucket(tx, bucketKeyVersion, bucketKeyComputeAgent)
}
Loading

0 comments on commit 6cee62b

Please sign in to comment.