diff --git a/hcn/hcnnamespace.go b/hcn/hcnnamespace.go index e855f5a3aa..90fc2c142b 100644 --- a/hcn/hcnnamespace.go +++ b/hcn/hcnnamespace.go @@ -9,6 +9,7 @@ import ( "syscall" "github.com/Microsoft/go-winio/pkg/guid" + "github.com/Microsoft/hcsshim" icni "github.com/Microsoft/hcsshim/internal/cni" "github.com/Microsoft/hcsshim/internal/interop" "github.com/Microsoft/hcsshim/internal/regstate" @@ -309,9 +310,22 @@ func GetNamespaceContainerIds(namespaceID string) ([]string, error) { // NewNamespace creates a new Namespace object func NewNamespace(nsType NamespaceType) *HostComputeNamespace { + /* + // HNS versions >= 15.2 change how network compartments are + // initialized for pods and depends on ReadyOnCreate flag in + // HCN namespace. It primarily supports removal of pause containers + // for process isolation. + isReadyOnCreate := false + hnsGlobals, err := hcsshim.GetHNSGlobals() + if err == nil { + isReadyOnCreate = (hnsGlobals.Version.Major > 15) || + (hnsGlobals.Version.Major == 15 && hnsGlobals.Version.Minor >= 2) + } + */ return &HostComputeNamespace{ Type: nsType, SchemaVersion: V2SchemaVersion(), + //ReadyOnCreate: isReadyOnCreate, } } @@ -319,6 +333,18 @@ func NewNamespace(nsType NamespaceType) *HostComputeNamespace { func (namespace *HostComputeNamespace) Create() (*HostComputeNamespace, error) { logrus.Debugf("hcn::HostComputeNamespace::Create id=%s", namespace.Id) + // HNS versions >= 15.2 change how network compartments are + // initialized for pods and depends on ReadyOnCreate flag in + // HCN namespace. It primarily supports removal of pause containers + // for process isolation. + isReadyOnCreate := false + hnsGlobals, err := hcsshim.GetHNSGlobals() + if err == nil { + isReadyOnCreate = (hnsGlobals.Version.Major > 15) || + (hnsGlobals.Version.Major == 15 && hnsGlobals.Version.Minor >= 2) + } + namespace.ReadyOnCreate = isReadyOnCreate + jsonString, err := json.Marshal(namespace) if err != nil { return nil, err