From cf25dbf5e3aaf07f6b01218243ff14615be24ca7 Mon Sep 17 00:00:00 2001 From: Daniel Canter Date: Sat, 19 Dec 2020 17:27:33 -0800 Subject: [PATCH] Add containerd-shim plumbing for job containers * Add the necessary plumbing in containerd shim to be able to create a job container if asked for via the annotation. Signed-off-by: Daniel Canter --- .../options/runhcs.pb.go | 164 +++++++++++------- .../options/runhcs.proto | 4 + cmd/containerd-shim-runhcs-v1/pod.go | 58 ++++++- .../service_internal.go | 2 +- cmd/containerd-shim-runhcs-v1/task_hcs.go | 68 +++++--- .../task_wcow_podsandbox.go | 3 + internal/jobcontainers/jobcontainer.go | 2 +- internal/oci/util.go | 8 + internal/oci/uvm.go | 4 + 9 files changed, 219 insertions(+), 94 deletions(-) diff --git a/cmd/containerd-shim-runhcs-v1/options/runhcs.pb.go b/cmd/containerd-shim-runhcs-v1/options/runhcs.pb.go index 76ef109634..1719b8c767 100644 --- a/cmd/containerd-shim-runhcs-v1/options/runhcs.pb.go +++ b/cmd/containerd-shim-runhcs-v1/options/runhcs.pb.go @@ -5,15 +5,14 @@ package options import ( fmt "fmt" + proto "github.com/gogo/protobuf/proto" + _ "github.com/gogo/protobuf/types" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" io "io" math "math" reflect "reflect" strings "strings" time "time" - - proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" ) // Reference imports to suppress errors if they are not otherwise used. @@ -123,16 +122,19 @@ type Options struct { ScaleCpuLimitsToSandbox bool `protobuf:"varint,11,opt,name=scale_cpu_limits_to_sandbox,json=scaleCpuLimitsToSandbox,proto3" json:"scale_cpu_limits_to_sandbox,omitempty"` // default_container_scratch_size_in_gb is the default scratch size (sandbox.vhdx) // to be used for containers. Every container will get a sandbox of `size_in_gb` assigned - // instead of the familiar 20GB as usual. + // instead of the default of 20GB. DefaultContainerScratchSizeInGb int32 `protobuf:"varint,12,opt,name=default_container_scratch_size_in_gb,json=defaultContainerScratchSizeInGb,proto3" json:"default_container_scratch_size_in_gb,omitempty"` - // default_container_scratch_size_in_gb is the default scratch size (sandbox.vhdx) + // default_vm_scratch_size_in_gb is the default scratch size (sandbox.vhdx) // to be used for the UVM. This only applies to WCOW as LCOW doesn't mount a scratch // specifically for the UVM. DefaultVmScratchSizeInGb int32 `protobuf:"varint,13,opt,name=default_vm_scratch_size_in_gb,json=defaultVmScratchSizeInGb,proto3" json:"default_vm_scratch_size_in_gb,omitempty"` // share_scratch specifies if we'd like to reuse scratch space between multiple containers. // This currently only affects LCOW. The sandbox containers scratch space is re-used for all // subsequent containers launched in the pod. - ShareScratch bool `protobuf:"varint,14,opt,name=share_scratch,json=shareScratch,proto3" json:"share_scratch,omitempty"` + ShareScratch bool `protobuf:"varint,14,opt,name=share_scratch,json=shareScratch,proto3" json:"share_scratch,omitempty"` + // job_container specifies whether to have the runtime create job containers + // instead of the standard hcs containers. + JobContainer bool `protobuf:"varint,15,opt,name=job_container,json=jobContainer,proto3" json:"job_container,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -231,63 +233,63 @@ func init() { } var fileDescriptor_b643df6839c75082 = []byte{ - // 883 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xdb, 0x6e, 0xdb, 0x36, - 0x18, 0xc7, 0xad, 0x26, 0x71, 0xa2, 0x2f, 0x71, 0xea, 0x70, 0x06, 0x26, 0xa4, 0xab, 0x6d, 0xa4, - 0x03, 0x9a, 0x62, 0x8d, 0x94, 0x74, 0x97, 0x1b, 0x30, 0xcc, 0x87, 0xb4, 0x1e, 0x9a, 0xc4, 0x90, - 0xb3, 0x74, 0x87, 0x0b, 0x42, 0x07, 0x5a, 0x26, 0x6a, 0x8a, 0x82, 0x48, 0x7b, 0x71, 0xaf, 0xf6, - 0x08, 0x7b, 0x9b, 0xbd, 0x42, 0x2e, 0x77, 0x39, 0x60, 0x40, 0xb6, 0xfa, 0x49, 0x06, 0x52, 0x94, - 0xbb, 0x05, 0xc1, 0x6e, 0x76, 0x65, 0xea, 0xff, 0xfd, 0xf8, 0xe7, 0xc7, 0xc3, 0xdf, 0x70, 0x91, - 0x50, 0x39, 0x99, 0x85, 0x6e, 0xc4, 0x99, 0x77, 0x46, 0xa3, 0x9c, 0x0b, 0x3e, 0x96, 0xde, 0x24, - 0x12, 0x62, 0x42, 0x99, 0x17, 0xb1, 0xd8, 0x8b, 0x78, 0x2a, 0x03, 0x9a, 0x92, 0x3c, 0x3e, 0x52, - 0xda, 0x51, 0x3e, 0x4b, 0x27, 0x91, 0x38, 0x9a, 0x9f, 0x78, 0x3c, 0x93, 0x94, 0xa7, 0xc2, 0x2b, - 0x14, 0x37, 0xcb, 0xb9, 0xe4, 0xa8, 0xf1, 0x81, 0x77, 0x4d, 0x61, 0x7e, 0xb2, 0xdf, 0x48, 0x78, - 0xc2, 0x35, 0xe0, 0xa9, 0x51, 0xc1, 0xee, 0xb7, 0x12, 0xce, 0x93, 0x29, 0xf1, 0xf4, 0x57, 0x38, - 0x1b, 0x7b, 0x92, 0x32, 0x22, 0x64, 0xc0, 0xb2, 0x02, 0x38, 0xf8, 0xb5, 0x0a, 0x9b, 0x17, 0xc5, - 0x2a, 0xa8, 0x01, 0x1b, 0x31, 0x09, 0x67, 0x89, 0x63, 0xb5, 0xad, 0xc3, 0x2d, 0xbf, 0xf8, 0x40, - 0xa7, 0x00, 0x7a, 0x80, 0xe5, 0x22, 0x23, 0xce, 0x83, 0xb6, 0x75, 0xb8, 0xfb, 0xe2, 0xa9, 0x7b, - 0x5f, 0x0f, 0xae, 0x31, 0x72, 0x7b, 0x8a, 0xbf, 0x5c, 0x64, 0xc4, 0xb7, 0xe3, 0x72, 0x88, 0x9e, - 0x40, 0x2d, 0x27, 0x09, 0x15, 0x32, 0x5f, 0xe0, 0x9c, 0x73, 0xe9, 0xac, 0xb5, 0xad, 0x43, 0xdb, - 0xdf, 0x29, 0x45, 0x9f, 0x73, 0xa9, 0x20, 0x11, 0xa4, 0x71, 0xc8, 0xaf, 0x31, 0x65, 0x41, 0x42, - 0x9c, 0xf5, 0x02, 0x32, 0xe2, 0x40, 0x69, 0xe8, 0x19, 0xd4, 0x4b, 0x28, 0x9b, 0x06, 0x72, 0xcc, - 0x73, 0xe6, 0x6c, 0x68, 0xee, 0xa1, 0xd1, 0x87, 0x46, 0x46, 0x3f, 0xc2, 0xde, 0xca, 0x4f, 0xf0, - 0x69, 0xa0, 0xfa, 0x73, 0xaa, 0x7a, 0x0f, 0xee, 0x7f, 0xef, 0x61, 0x64, 0x56, 0x2c, 0x67, 0xf9, - 0xe5, 0x9a, 0x2b, 0x05, 0x79, 0xd0, 0x08, 0x39, 0x97, 0x78, 0x4c, 0xa7, 0x44, 0xe8, 0x3d, 0xe1, - 0x2c, 0x90, 0x13, 0x67, 0x53, 0xf7, 0xb2, 0xa7, 0x6a, 0xa7, 0xaa, 0xa4, 0x76, 0x36, 0x0c, 0xe4, - 0x04, 0x3d, 0x07, 0x34, 0x67, 0x38, 0xcb, 0x79, 0x44, 0x84, 0xe0, 0x39, 0x8e, 0xf8, 0x2c, 0x95, - 0xce, 0x56, 0xdb, 0x3a, 0xdc, 0xf0, 0xeb, 0x73, 0x36, 0x2c, 0x0b, 0x5d, 0xa5, 0x23, 0x17, 0x1a, - 0x73, 0x86, 0x19, 0x61, 0x3c, 0x5f, 0x60, 0x41, 0xdf, 0x11, 0x4c, 0x53, 0xcc, 0x42, 0xc7, 0x2e, - 0xf9, 0x33, 0x5d, 0x1a, 0xd1, 0x77, 0x64, 0x90, 0x9e, 0x85, 0xa8, 0x09, 0xf0, 0x72, 0xf8, 0xed, - 0xd5, 0xab, 0x9e, 0x5a, 0xcb, 0x01, 0xdd, 0xc4, 0x3f, 0x14, 0xf4, 0x25, 0x3c, 0x12, 0x51, 0x30, - 0x25, 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 0xbd, 0x48, 0x4d, - 0xe9, 0x1f, 0x0e, 0xe5, 0x09, 0x6c, 0x92, 0x6b, 0x12, 0x29, 0x4f, 0x15, 0x25, 0xbb, 0x03, 0xcb, - 0xdb, 0x56, 0xb5, 0x7f, 0x4d, 0xa2, 0x41, 0xcf, 0xaf, 0xaa, 0xd2, 0x20, 0xee, 0xc4, 0x37, 0xef, - 0x9b, 0x95, 0xdf, 0xdf, 0x37, 0x2b, 0x3f, 0x2f, 0x9b, 0xd6, 0xcd, 0xb2, 0x69, 0xfd, 0xb6, 0x6c, - 0x5a, 0x7f, 0x2d, 0x9b, 0xd6, 0x0f, 0xdf, 0xfc, 0xff, 0xff, 0xf3, 0x2f, 0xcc, 0xef, 0x77, 0x95, - 0xb0, 0xaa, 0xef, 0xfd, 0xf3, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xbb, 0xb6, 0x6d, 0x09, 0x26, - 0x06, 0x00, 0x00, + // 895 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x5b, 0x6f, 0xdb, 0x36, + 0x18, 0x86, 0xad, 0x36, 0x3e, 0xe8, 0x4b, 0x9c, 0x38, 0x9c, 0x81, 0x09, 0xe9, 0x6a, 0x1b, 0xe9, + 0x80, 0xa6, 0x58, 0x23, 0x25, 0xdd, 0xe5, 0x06, 0x0c, 0xf3, 0x21, 0xad, 0x87, 0x26, 0x31, 0xe4, + 0x2c, 0xdd, 0xe1, 0x82, 0xd0, 0x81, 0x96, 0xd5, 0x9a, 0xa2, 0x20, 0xd2, 0x5e, 0xdc, 0xab, 0xfd, + 0x84, 0xfd, 0xac, 0x5c, 0xee, 0x72, 0xc0, 0x86, 0x6c, 0xf5, 0x2f, 0x19, 0x48, 0x51, 0xce, 0x16, + 0x04, 0xbb, 0xd9, 0x95, 0xa9, 0xf7, 0x7b, 0xf8, 0xf2, 0xe3, 0xe1, 0x35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87, 0x52, 0x43, 0xcf, 0xa0, 0x51, 0x40, 0xe9, 0xcc, 0x13, 0x13, 0x96, 0x51, + 0xab, 0xac, 0xb8, 0x1d, 0xad, 0x8f, 0xb4, 0x8c, 0x7e, 0x84, 0xdd, 0xb5, 0x1f, 0x67, 0x33, 0x4f, + 0xf6, 0x67, 0x55, 0xd4, 0x1e, 0xec, 0xff, 0xde, 0xc3, 0x58, 0xaf, 0x58, 0xcc, 0x72, 0x8b, 0x35, + 0xd7, 0x0a, 0x72, 0xa0, 0xe9, 0x33, 0x26, 0xf0, 0x24, 0x9e, 0x11, 0xae, 0xf6, 0x84, 0x53, 0x4f, + 0x4c, 0xad, 0xaa, 0xea, 0x65, 0x57, 0xd6, 0x4e, 0x64, 0x49, 0xee, 0x6c, 0xe4, 0x89, 0x29, 0x7a, + 0x0e, 0x68, 0x41, 0x71, 0x9a, 0xb1, 0x80, 0x70, 0xce, 0x32, 0x1c, 0xb0, 0x79, 0x22, 0xac, 0x5a, + 0xc7, 0x38, 0x28, 0xbb, 0x8d, 0x05, 0x1d, 0x15, 0x85, 0x9e, 0xd4, 0x91, 0x0d, 0xcd, 0x05, 0xc5, + 0x94, 0x50, 0x96, 0x2d, 0x31, 0x8f, 0xdf, 0x13, 0x1c, 0x27, 0x98, 0xfa, 0x96, 0x59, 0xf0, 0xa7, + 0xaa, 0x34, 0x8e, 0xdf, 0x93, 0x61, 0x72, 0xea, 0xa3, 0x16, 0xc0, 0xcb, 0xd1, 0xb7, 0x97, 0xaf, + 0xfa, 0x72, 0x2d, 0x0b, 0x54, 0x13, 0xff, 0x50, 0xd0, 0x97, 0xf0, 0x88, 0x07, 0xde, 0x8c, 0xe0, + 0x20, 0x9d, 0xe3, 0x59, 0x4c, 0x63, 0xc1, 0xb1, 0x60, 0x58, 0x6f, 0xcb, 0xda, 0x54, 0x97, 0xfe, + 0xb1, 0x42, 0x7a, 0xe9, 0xfc, 0xb5, 0x02, 0x2e, 0x98, 0x3e, 0x07, 0x74, 0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x20, 0x3d, 0x65, 0xde, 0xcc, 0x2e, 0xac, 0x6e, 0xda, 0x95, 0xc1, + 0x15, 0x09, 0x86, 0x7d, 0xb7, 0x22, 0x4b, 0xc3, 0xb0, 0x1b, 0x5e, 0x7f, 0x68, 0x95, 0x7e, 0xfb, + 0xd0, 0x2a, 0xfd, 0xbc, 0x6a, 0x19, 0xd7, 0xab, 0x96, 0xf1, 0xeb, 0xaa, 0x65, 0xfc, 0xb5, 0x6a, + 0x19, 0x3f, 0x7c, 0xf3, 0xff, 0xff, 0xf4, 0xbf, 0xd0, 0xbf, 0xdf, 0x95, 0xfc, 0x8a, 0xba, 0xf7, + 0xcf, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x8d, 0xd0, 0xf2, 0x51, 0x4b, 0x06, 0x00, 0x00, } func (m *Options) Marshal() (dAtA []byte, err error) { @@ -395,6 +397,16 @@ func (m *Options) MarshalTo(dAtA []byte) (int, error) { } i++ } + if m.JobContainer { + dAtA[i] = 0x78 + i++ + if m.JobContainer { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } if m.XXX_unrecognized != nil { i += copy(dAtA[i:], m.XXX_unrecognized) } @@ -534,6 +546,9 @@ func (m *Options) Size() (n int) { if m.ShareScratch { n += 2 } + if m.JobContainer { + n += 2 + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -612,6 +627,7 @@ func (this *Options) String() string { `DefaultContainerScratchSizeInGb:` + fmt.Sprintf("%v", this.DefaultContainerScratchSizeInGb) + `,`, `DefaultVmScratchSizeInGb:` + fmt.Sprintf("%v", this.DefaultVmScratchSizeInGb) + `,`, `ShareScratch:` + fmt.Sprintf("%v", this.ShareScratch) + `,`, + `JobContainer:` + fmt.Sprintf("%v", this.JobContainer) + `,`, `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, `}`, }, "") @@ -1007,6 +1023,26 @@ func (m *Options) Unmarshal(dAtA []byte) error { } } m.ShareScratch = bool(v != 0) + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field JobContainer", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRunhcs + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.JobContainer = bool(v != 0) default: iNdEx = preIndex skippy, err := skipRunhcs(dAtA[iNdEx:]) diff --git a/cmd/containerd-shim-runhcs-v1/options/runhcs.proto b/cmd/containerd-shim-runhcs-v1/options/runhcs.proto index 72b2100eec..ec96ad6b42 100644 --- a/cmd/containerd-shim-runhcs-v1/options/runhcs.proto +++ b/cmd/containerd-shim-runhcs-v1/options/runhcs.proto @@ -83,6 +83,10 @@ message Options { // This currently only affects LCOW. The sandbox containers scratch space is re-used for all // subsequent containers launched in the pod. bool share_scratch = 14; + + // job_container specifies whether to have the runtime create job containers + // instead of the standard hcs containers. + bool job_container = 15; } // ProcessDetails contains additional information about a process. This is the additional diff --git a/cmd/containerd-shim-runhcs-v1/pod.go b/cmd/containerd-shim-runhcs-v1/pod.go index 6e341b83fb..a3ba4bec47 100644 --- a/cmd/containerd-shim-runhcs-v1/pod.go +++ b/cmd/containerd-shim-runhcs-v1/pod.go @@ -81,10 +81,15 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques sid) } + p := pod{ + events: events, + id: req.ID, + } + + var parent *uvm.UtilityVM owner := filepath.Base(os.Args[0]) isWCOW := oci.IsWCOW(s) - var parent *uvm.UtilityVM if oci.IsIsolated(s) { // Create the UVM parent opts, err := oci.SpecToUVMCreateOpts(ctx, s, fmt.Sprintf("%s@vm", req.ID), owner) @@ -128,7 +133,29 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques } } else if !isWCOW { return nil, errors.Wrap(errdefs.ErrFailedPrecondition, "oci spec does not contain WCOW or LCOW spec") + } else if oci.IsJobContainer(s) { + // If privileged was specified just fake a task (i.e reuse the wcowPodSandbox logic) + p.sandboxTask = newWcowPodSandboxTask(ctx, events, req.ID, req.Bundle, parent) + events.publishEvent( + ctx, + runtime.TaskCreateEventTopic, + &eventstypes.TaskCreate{ + ContainerID: req.ID, + Bundle: req.Bundle, + Rootfs: req.Rootfs, + IO: &eventstypes.TaskIO{ + Stdin: req.Stdin, + Stdout: req.Stdout, + Stderr: req.Stderr, + Terminal: req.Terminal, + }, + Checkpoint: "", + Pid: 0, + }) + p.jobContainer = true + return &p, nil } + defer func() { // clean up the uvm if we fail any further operations if err != nil && parent != nil { @@ -136,11 +163,7 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques } }() - p := pod{ - events: events, - id: req.ID, - host: parent, - } + p.host = parent // TOOD: JTERRY75 - There is a bug in the compartment activation for Windows // Process isolated that requires us to create the real pause container to // hold the network compartment open. This is not required for Windows @@ -187,7 +210,7 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques } // LCOW (and WCOW Process Isolated for the time being) requires a real // task for the sandbox. - lt, err := newHcsTask(ctx, events, parent, true, req, s) + lt, err := newHcsTask(ctx, events, parent, true, req, p.jobContainer, s) if err != nil { return nil, err } @@ -217,6 +240,11 @@ type pod struct { // It MUST be treated as read only in the lifetime of the pod. host *uvm.UtilityVM + // jobContainer specifies whether this pod is for WCOW job containers only. + // + // It MUST be treated as read only in the lifetime of the pod. + jobContainer bool + // wcl is the worload create mutex. All calls to CreateTask must hold this // lock while the ID reservation takes place. Once the ID is held it is safe // to release the lock to allow concurrent creates. @@ -259,6 +287,20 @@ func (p *pod) CreateTask(ctx context.Context, req *task.CreateTaskRequest, s *sp } }() + if p.jobContainer { + // This is a short circuit to make sure that all containers in a pod will have + // the same IP address/be added to the same compartment. + // + // There is no way to go through the HNS namespace attach flow + // (send an attach request -> compartment created -> add vnic to compartment) + // without supplying a valid container ID to HNS so this is the blocker here. + // When this is supported in the OS this check can be removed and process and + // job containers can be mixed freely. + if !oci.IsJobContainer(s) { + return nil, errors.New("cannot create a normal process isolated container if the pod sandbox is a job container") + } + } + ct, sid, err := oci.GetSandboxTypeAndID(s.Annotations) if err != nil { return nil, err @@ -289,7 +331,7 @@ func (p *pod) CreateTask(ctx context.Context, req *task.CreateTaskRequest, s *sp if templateID != "" { st, err = newClonedHcsTask(ctx, p.events, p.host, false, req, s, templateID) } else { - st, err = newHcsTask(ctx, p.events, p.host, false, req, s) + st, err = newHcsTask(ctx, p.events, p.host, false, req, p.jobContainer, s) } if err != nil { return nil, err diff --git a/cmd/containerd-shim-runhcs-v1/service_internal.go b/cmd/containerd-shim-runhcs-v1/service_internal.go index 85e41c550b..13f06d5410 100644 --- a/cmd/containerd-shim-runhcs-v1/service_internal.go +++ b/cmd/containerd-shim-runhcs-v1/service_internal.go @@ -173,7 +173,7 @@ func (s *service) createInternal(ctx context.Context, req *task.CreateTaskReques resp.Pid = uint32(e.Pid()) s.taskOrPod.Store(pod) } else { - t, err := newHcsStandaloneTask(ctx, s.events, req, &spec) + t, err := newHcsStandaloneTask(ctx, s.events, req, false, &spec) if err != nil { s.cl.Unlock() return nil, err diff --git a/cmd/containerd-shim-runhcs-v1/task_hcs.go b/cmd/containerd-shim-runhcs-v1/task_hcs.go index 676224d47d..7909c262b5 100644 --- a/cmd/containerd-shim-runhcs-v1/task_hcs.go +++ b/cmd/containerd-shim-runhcs-v1/task_hcs.go @@ -25,6 +25,7 @@ import ( "github.com/Microsoft/hcsshim/internal/cow" "github.com/Microsoft/hcsshim/internal/hcs" "github.com/Microsoft/hcsshim/internal/hcsoci" + "github.com/Microsoft/hcsshim/internal/jobcontainers" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/oci" "github.com/Microsoft/hcsshim/internal/resources" @@ -35,7 +36,7 @@ import ( "github.com/Microsoft/hcsshim/osversion" ) -func newHcsStandaloneTask(ctx context.Context, events publisher, req *task.CreateTaskRequest, s *specs.Spec) (shimTask, error) { +func newHcsStandaloneTask(ctx context.Context, events publisher, req *task.CreateTaskRequest, jobContainer bool, s *specs.Spec) (shimTask, error) { log.G(ctx).WithField("tid", req.ID).Debug("newHcsStandaloneTask") ct, _, err := oci.GetSandboxTypeAndID(s.Annotations) @@ -97,7 +98,7 @@ func newHcsStandaloneTask(ctx context.Context, events publisher, req *task.Creat return nil, errors.Wrap(errdefs.ErrFailedPrecondition, "oci spec does not contain WCOW or LCOW spec") } - shim, err := newHcsTask(ctx, events, parent, true, req, s) + shim, err := newHcsTask(ctx, events, parent, true, req, jobContainer, s) if err != nil { if parent != nil { parent.Close() @@ -117,6 +118,7 @@ func newHcsTask( parent *uvm.UtilityVM, ownsParent bool, req *task.CreateTaskRequest, + isJobContainer bool, s *specs.Spec) (_ shimTask, err error) { log.G(ctx).WithFields(logrus.Fields{ "tid": req.ID, @@ -131,7 +133,11 @@ func newHcsTask( return nil, err } - var netNS string + var ( + netNS string + resources *resources.Resources + container cow.Container + ) if s.Windows != nil && s.Windows.Network != nil { netNS = s.Windows.Network.NetworkNamespace @@ -158,29 +164,35 @@ func newHcsTask( opts.ScaleCPULimitsToSandbox = shimOpts.ScaleCpuLimitsToSandbox } - system, resources, err := hcsoci.CreateContainer(ctx, &opts) - if err != nil { - return nil, err + if isJobContainer { + container, err = jobcontainers.Create(ctx, req.ID, s) + if err != nil { + return nil, err + } + } else { + container, resources, err = hcsoci.CreateContainer(ctx, &opts) + if err != nil { + return nil, err + } } ht := &hcsTask{ - events: events, - id: req.ID, - isWCOW: oci.IsWCOW(s), - c: system, - cr: resources, - ownsHost: ownsParent, - host: parent, - closed: make(chan struct{}), - taskSpec: s, - isTemplate: isTemplate, + events: events, + id: req.ID, + isWCOW: oci.IsWCOW(s), + c: container, + cr: resources, + ownsHost: ownsParent, + jobContainer: isJobContainer, + host: parent, + closed: make(chan struct{}), } ht.init = newHcsExec( ctx, events, req.ID, parent, - system, + container, req.ID, req.Bundle, ht.isWCOW, @@ -375,6 +387,11 @@ type hcsTask struct { // `nil`. host *uvm.UtilityVM + // Determines whether this task is a job container + // + // It MUST be treated as read only in the lifetime of the task. + jobContainer bool + // ecl is the exec create lock for all non-init execs and MUST be held // durring create to prevent ID duplication. ecl sync.Mutex @@ -708,9 +725,16 @@ func (ht *hcsTask) close(ctx context.Context) { } } - // Release any resources associated with the container. - if err := resources.ReleaseResources(ctx, ht.cr, ht.host, true); err != nil { - log.G(ctx).WithError(err).Error("failed to release container resources") + if ht.jobContainer { + pc := ht.c.(*jobcontainers.JobContainer) + if err := pc.Release(ctx); err != nil { + log.G(ctx).WithError(err).Error("failed to release job container resources") + } + } else { + // Release any resources associated with the container. + if err := resources.ReleaseResources(ctx, ht.cr, ht.host, true); err != nil { + log.G(ctx).WithError(err).Error("failed to release container resources") + } } // Close the container handle invalidating all future access. @@ -832,6 +856,10 @@ func hcsPropertiesToWindowsStats(props *hcsschema.Properties) *stats.Statistics_ func (ht *hcsTask) Stats(ctx context.Context) (*stats.Statistics, error) { s := &stats.Statistics{} + if ht.jobContainer { + return s, nil + } + props, err := ht.c.PropertiesV2(ctx, hcsschema.PTStatistics) if err != nil && !isStatsNotFound(err) { return nil, err diff --git a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go index 122c2bba6e..aa2bc397de 100644 --- a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go +++ b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go @@ -250,6 +250,9 @@ func (wpst *wcowPodSandboxTask) Share(ctx context.Context, req *shimdiag.ShareRe func (wpst *wcowPodSandboxTask) Stats(ctx context.Context) (*stats.Statistics, error) { stats := &stats.Statistics{} + if wpst.host == nil { + return stats, nil + } vmStats, err := wpst.host.Stats(ctx) if err != nil && !isStatsNotFound(err) { return nil, err diff --git a/internal/jobcontainers/jobcontainer.go b/internal/jobcontainers/jobcontainer.go index c4f589357b..78f2323042 100644 --- a/internal/jobcontainers/jobcontainer.go +++ b/internal/jobcontainers/jobcontainer.go @@ -401,7 +401,7 @@ func (c *JobContainer) waitBackground(ctx context.Context) { // them to exit. <-c.init.proc.waitBlock - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() if err := c.Shutdown(ctx); err != nil { c.Terminate(ctx) diff --git a/internal/oci/util.go b/internal/oci/util.go index e57b52ae6c..40219d8de2 100644 --- a/internal/oci/util.go +++ b/internal/oci/util.go @@ -16,3 +16,11 @@ func IsWCOW(s *specs.Spec) bool { func IsIsolated(s *specs.Spec) bool { return IsLCOW(s) || (s.Windows != nil && s.Windows.HyperV != nil) } + +// IsJobContainer checks if `s` is asking for a Windows job container. +func IsJobContainer(s *specs.Spec) bool { + if _, ok := s.Annotations[AnnotationHostProcessContainer]; ok { + return true + } + return false +} diff --git a/internal/oci/uvm.go b/internal/oci/uvm.go index 6541f13d11..26039ed32d 100644 --- a/internal/oci/uvm.go +++ b/internal/oci/uvm.go @@ -518,5 +518,9 @@ func UpdateSpecFromOptions(s specs.Spec, opts *runhcsopts.Options) specs.Spec { s.Annotations[AnnotationGPUVHDPath] = opts.GPUVHDPath } + if _, ok := s.Annotations[AnnotationHostProcessContainer]; !ok && opts.JobContainer { + s.Annotations[AnnotationHostProcessContainer] = "true" + } + return s }