diff --git a/task_opts.go b/task_opts.go index 9e998a349..0c05fcbe7 100644 --- a/task_opts.go +++ b/task_opts.go @@ -18,10 +18,12 @@ package containerd import ( "context" + "errors" "syscall" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/mount" + specs "github.com/opencontainers/runtime-spec/specs-go" ) // NewTaskOpts allows the caller to set options on a new task @@ -92,3 +94,19 @@ func WithKillExecID(execID string) KillOpts { return nil } } + +// WithResources sets the provided resources for task updates. Resources must be +// either a *specs.LinuxResources or a *specs.WindowsResources +func WithResources(resources interface{}) UpdateTaskOpts { + return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error { + switch resources.(type) { + case *specs.LinuxResources: + case *specs.WindowsResources: + default: + return errors.New("WithResources requires a *specs.LinuxResources or *specs.WindowsResources") + } + + r.Resources = resources + return nil + } +} diff --git a/task_opts_linux.go b/task_opts_linux.go index 551cb996c..b7e626206 100644 --- a/task_opts_linux.go +++ b/task_opts_linux.go @@ -21,17 +21,8 @@ import ( "errors" "github.com/containerd/containerd/runtime/linux/runctypes" - "github.com/opencontainers/runtime-spec/specs-go" ) -// WithResources sets the provided resources for task updates -func WithResources(resources *specs.LinuxResources) UpdateTaskOpts { - return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error { - r.Resources = resources - return nil - } -} - // WithNoNewKeyring causes tasks not to be created with a new keyring for secret storage. // There is an upper limit on the number of keyrings in a linux system func WithNoNewKeyring(ctx context.Context, c *Client, ti *TaskInfo) error { diff --git a/task_opts_windows.go b/task_opts_windows.go deleted file mode 100644 index 60836bc8f..000000000 --- a/task_opts_windows.go +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package containerd - -import ( - "context" - - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -// WithResources sets the provided resources on the spec for task updates -func WithResources(resources *specs.WindowsResources) UpdateTaskOpts { - return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error { - r.Resources = resources - return nil - } -}