github.com/demonoid81/containerd@v1.3.4/oci/spec_opts_windows.go (about)

     1  // +build windows
     2  
     3  /*
     4     Copyright The containerd Authors.
     5  
     6     Licensed under the Apache License, Version 2.0 (the "License");
     7     you may not use this file except in compliance with the License.
     8     You may obtain a copy of the License at
     9  
    10         http://www.apache.org/licenses/LICENSE-2.0
    11  
    12     Unless required by applicable law or agreed to in writing, software
    13     distributed under the License is distributed on an "AS IS" BASIS,
    14     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15     See the License for the specific language governing permissions and
    16     limitations under the License.
    17  */
    18  
    19  package oci
    20  
    21  import (
    22  	"context"
    23  
    24  	"github.com/containerd/containerd/containers"
    25  	specs "github.com/opencontainers/runtime-spec/specs-go"
    26  	"github.com/pkg/errors"
    27  )
    28  
    29  // WithWindowsCPUCount sets the `Windows.Resources.CPU.Count` section to the
    30  // `count` specified.
    31  func WithWindowsCPUCount(count uint64) SpecOpts {
    32  	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
    33  		if s.Windows.Resources == nil {
    34  			s.Windows.Resources = &specs.WindowsResources{}
    35  		}
    36  		if s.Windows.Resources.CPU == nil {
    37  			s.Windows.Resources.CPU = &specs.WindowsCPUResources{}
    38  		}
    39  		s.Windows.Resources.CPU.Count = &count
    40  		return nil
    41  	}
    42  }
    43  
    44  // WithWindowsIgnoreFlushesDuringBoot sets `Windows.IgnoreFlushesDuringBoot`.
    45  func WithWindowsIgnoreFlushesDuringBoot() SpecOpts {
    46  	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
    47  		if s.Windows == nil {
    48  			s.Windows = &specs.Windows{}
    49  		}
    50  		s.Windows.IgnoreFlushesDuringBoot = true
    51  		return nil
    52  	}
    53  }
    54  
    55  // WithWindowNetworksAllowUnqualifiedDNSQuery sets `Windows.IgnoreFlushesDuringBoot`.
    56  func WithWindowNetworksAllowUnqualifiedDNSQuery() SpecOpts {
    57  	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
    58  		if s.Windows == nil {
    59  			s.Windows = &specs.Windows{}
    60  		}
    61  		if s.Windows.Network == nil {
    62  			s.Windows.Network = &specs.WindowsNetwork{}
    63  		}
    64  
    65  		s.Windows.Network.AllowUnqualifiedDNSQuery = true
    66  		return nil
    67  	}
    68  }
    69  
    70  func deviceFromPath(path, permissions string) (*specs.LinuxDevice, error) {
    71  	return nil, errors.New("device from path not supported on Windows")
    72  }