...

Source file src/github.com/Microsoft/hcsshim/internal/hcsoci/network.go

Documentation: github.com/Microsoft/hcsshim/internal/hcsoci

     1  //go:build windows
     2  
     3  package hcsoci
     4  
     5  import (
     6  	"context"
     7  
     8  	"github.com/Microsoft/hcsshim/hcn"
     9  	"github.com/Microsoft/hcsshim/internal/log"
    10  	"github.com/Microsoft/hcsshim/internal/logfields"
    11  	"github.com/Microsoft/hcsshim/internal/resources"
    12  	"github.com/Microsoft/hcsshim/internal/uvm"
    13  	"github.com/sirupsen/logrus"
    14  )
    15  
    16  func createNetworkNamespace(ctx context.Context, coi *createOptionsInternal, r *resources.Resources) error {
    17  	op := "hcsoci::createNetworkNamespace"
    18  	l := log.G(ctx).WithField(logfields.ContainerID, coi.ID)
    19  	l.Debug(op + " - Begin")
    20  	defer func() {
    21  		l.Debug(op + " - End")
    22  	}()
    23  
    24  	ns, err := hcn.NewNamespace("").Create()
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	log.G(ctx).WithFields(logrus.Fields{
    30  		"netID":               ns.Id,
    31  		logfields.ContainerID: coi.ID,
    32  	}).Info("created network namespace for container")
    33  
    34  	r.SetNetNS(ns.Id)
    35  	r.SetCreatedNetNS(true)
    36  
    37  	endpoints := make([]string, 0)
    38  	for _, endpointID := range coi.Spec.Windows.Network.EndpointList {
    39  		err = hcn.AddNamespaceEndpoint(ns.Id, endpointID)
    40  		if err != nil {
    41  			return err
    42  		}
    43  		log.G(ctx).WithFields(logrus.Fields{
    44  			"netID":      ns.Id,
    45  			"endpointID": endpointID,
    46  		}).Info("added network endpoint to namespace")
    47  		endpoints = append(endpoints, endpointID)
    48  	}
    49  	r.Add(&uvm.NetworkEndpoints{EndpointIDs: endpoints, Namespace: ns.Id})
    50  	return nil
    51  }
    52  

View as plain text