Skip to content

Commit 399dba5

Browse files
authored
Merge pull request #2599 from jterry75/windows_task_opt
Merge WithResources for Linux/Windows TaskOpts
2 parents ccebed2 + c48f8de commit 399dba5

3 files changed

Lines changed: 18 additions & 40 deletions

File tree

task_opts.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package containerd
1818

1919
import (
2020
"context"
21+
"errors"
2122
"syscall"
2223

2324
"github.com/containerd/containerd/errdefs"
2425
"github.com/containerd/containerd/mount"
26+
specs "github.com/opencontainers/runtime-spec/specs-go"
2527
)
2628

2729
// NewTaskOpts allows the caller to set options on a new task
@@ -92,3 +94,19 @@ func WithKillExecID(execID string) KillOpts {
9294
return nil
9395
}
9496
}
97+
98+
// WithResources sets the provided resources for task updates. Resources must be
99+
// either a *specs.LinuxResources or a *specs.WindowsResources
100+
func WithResources(resources interface{}) UpdateTaskOpts {
101+
return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error {
102+
switch resources.(type) {
103+
case *specs.LinuxResources:
104+
case *specs.WindowsResources:
105+
default:
106+
return errors.New("WithResources requires a *specs.LinuxResources or *specs.WindowsResources")
107+
}
108+
109+
r.Resources = resources
110+
return nil
111+
}
112+
}

task_opts_linux.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,8 @@ import (
2121
"errors"
2222

2323
"github.com/containerd/containerd/runtime/linux/runctypes"
24-
"github.com/opencontainers/runtime-spec/specs-go"
2524
)
2625

27-
// WithResources sets the provided resources for task updates
28-
func WithResources(resources *specs.LinuxResources) UpdateTaskOpts {
29-
return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error {
30-
r.Resources = resources
31-
return nil
32-
}
33-
}
34-
3526
// WithNoNewKeyring causes tasks not to be created with a new keyring for secret storage.
3627
// There is an upper limit on the number of keyrings in a linux system
3728
func WithNoNewKeyring(ctx context.Context, c *Client, ti *TaskInfo) error {

task_opts_windows.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)