@@ -4,6 +4,7 @@ package uvm
44
55import (
66 "context"
7+ "errors"
78 "fmt"
89 "os"
910 "slices"
@@ -12,7 +13,6 @@ import (
1213 "github.com/Microsoft/go-winio"
1314 "github.com/Microsoft/go-winio/pkg/guid"
1415 "github.com/containerd/ttrpc"
15- "github.com/pkg/errors"
1616 "github.com/sirupsen/logrus"
1717
1818 "github.com/Microsoft/hcsshim/hcn"
@@ -147,7 +147,7 @@ func (n *ncproxyClient) Close() error {
147147func (uvm * UtilityVM ) GetNCProxyClient () (* ncproxyClient , error ) {
148148 conn , err := winio .DialPipe (uvm .ncProxyClientAddress , nil )
149149 if err != nil {
150- return nil , errors . Wrap ( err , "failed to connect to ncproxy service" )
150+ return nil , fmt . Errorf ( "failed to connect to ncproxy service: %w" , err )
151151 }
152152 raw := ttrpc .NewClient (conn , ttrpc .WithOnClose (func () { conn .Close () }))
153153 return & ncproxyClient {raw , ncproxyttrpc .NewNetworkConfigProxyClient (raw )}, nil
@@ -298,7 +298,7 @@ func (e *externalNetworkSetup) ConfigureNetworking(ctx context.Context, namespac
298298
299299 client , err := e .vm .GetNCProxyClient ()
300300 if err != nil {
301- return errors . Wrapf ( err , "no ncproxy client for UVM %q" , e .vm .ID ())
301+ return fmt . Errorf ( "no ncproxy client for UVM %q: %w " , e .vm .ID (), err )
302302 }
303303 defer client .Close ()
304304
@@ -523,16 +523,25 @@ func (uvm *UtilityVM) RemoveNetNS(ctx context.Context, id string) error {
523523
524524 ns , ok := uvm .namespaces [id ]
525525 if ! ok {
526- entry .Warn ("cannot remove non-existant namespace from uVM" )
526+ entry .Warn ("cannot remove non-existent namespace from uVM" )
527527 return nil
528528 }
529529
530530 entry .WithField ("nics" , log .Format (ctx , ns .nics )).Debug ("removing NICs from namespace" )
531+ var errs []error
531532 for _ , ninfo := range ns .nics {
532533 if err := uvm .removeNIC (ctx , ninfo .ID , ninfo .Endpoint ); err != nil {
533- return err
534+ entry .WithFields (logrus.Fields {
535+ logrus .ErrorKey : err ,
536+ "nic-id" : ninfo .ID ,
537+ }).Warn ("failed to remove NIC from uVM" )
538+ errs = append (errs , err )
539+ } else {
540+ ns .nics [ninfo .Endpoint .Id ] = nil
534541 }
535- ns .nics [ninfo .Endpoint .Id ] = nil
542+ }
543+ if len (errs ) > 0 {
544+ return fmt .Errorf ("remove nic from uVM %q: %w" , uvm .ID (), errors .Join (errs ... ))
536545 }
537546
538547 // Remove the Guest Network namespace
0 commit comments