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 19package server 20 21import ( 22 "github.com/containerd/containerd" 23 "github.com/containerd/containerd/oci" 24 imagespec "github.com/opencontainers/image-spec/specs-go/v1" 25 runtimespec "github.com/opencontainers/runtime-spec/specs-go" 26 "github.com/pkg/errors" 27 runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" 28 29 "github.com/containerd/containerd/pkg/cri/annotations" 30 customopts "github.com/containerd/containerd/pkg/cri/opts" 31) 32 33func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxConfig, 34 imageConfig *imagespec.ImageConfig, nsPath string, runtimePodAnnotations []string) (*runtimespec.Spec, error) { 35 // Creates a spec Generator with the default spec. 36 specOpts := []oci.SpecOpts{ 37 oci.WithEnv(imageConfig.Env), 38 oci.WithHostname(config.GetHostname()), 39 } 40 if imageConfig.WorkingDir != "" { 41 specOpts = append(specOpts, oci.WithProcessCwd(imageConfig.WorkingDir)) 42 } 43 44 if len(imageConfig.Entrypoint) == 0 && len(imageConfig.Cmd) == 0 { 45 // Pause image must have entrypoint or cmd. 46 return nil, errors.Errorf("invalid empty entrypoint and cmd in image config %+v", imageConfig) 47 } 48 specOpts = append(specOpts, oci.WithProcessArgs(append(imageConfig.Entrypoint, imageConfig.Cmd...)...)) 49 50 specOpts = append(specOpts, 51 // Clear the root location since hcsshim expects it. 52 // NOTE: readonly rootfs doesn't work on windows. 53 customopts.WithoutRoot, 54 customopts.WithWindowsNetworkNamespace(nsPath), 55 ) 56 57 specOpts = append(specOpts, customopts.WithWindowsDefaultSandboxShares) 58 59 for pKey, pValue := range getPassthroughAnnotations(config.Annotations, 60 runtimePodAnnotations) { 61 specOpts = append(specOpts, customopts.WithAnnotation(pKey, pValue)) 62 } 63 64 specOpts = append(specOpts, 65 customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox), 66 customopts.WithAnnotation(annotations.SandboxID, id), 67 customopts.WithAnnotation(annotations.SandboxNamespace, config.GetMetadata().GetNamespace()), 68 customopts.WithAnnotation(annotations.SandboxName, config.GetMetadata().GetName()), 69 customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()), 70 ) 71 72 return c.runtimeSpec(id, "", specOpts...) 73} 74 75// No sandbox container spec options for windows yet. 76func (c *criService) sandboxContainerSpecOpts(config *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig) ([]oci.SpecOpts, error) { 77 return nil, nil 78} 79 80// No sandbox files needed for windows. 81func (c *criService) setupSandboxFiles(id string, config *runtime.PodSandboxConfig) error { 82 return nil 83} 84 85// No sandbox files needed for windows. 86func (c *criService) cleanupSandboxFiles(id string, config *runtime.PodSandboxConfig) error { 87 return nil 88} 89 90// No task options needed for windows. 91func (c *criService) taskOpts(runtimeType string) []containerd.NewTaskOpts { 92 return nil 93} 94