Add context and client to SpecOpts

In order to do more advanced spec generation with images, snapshots,
etc, we need to inject the context and client into the spec generation
code.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-08-22 12:03:21 -04:00
parent ba69f5d488
commit fa14f2ef3a
15 changed files with 100 additions and 92 deletions

View File

@@ -12,8 +12,8 @@ import (
const newLine = "\r\n"
func generateSpec(opts ...SpecOpts) (*specs.Spec, error) {
spec, err := GenerateSpec(opts...)
func generateSpec(ctx context.Context, client *Client, opts ...SpecOpts) (*specs.Spec, error) {
spec, err := GenerateSpec(ctx, client, opts...)
if err != nil {
return nil, err
}
@@ -24,7 +24,7 @@ func generateSpec(opts ...SpecOpts) (*specs.Spec, error) {
}
func withExitStatus(es int) SpecOpts {
return func(s *specs.Spec) error {
return func(_ context.Context, _ *Client, s *specs.Spec) error {
s.Process.Args = []string{"powershell", "-noprofile", "exit", strconv.Itoa(es)}
return nil
}
@@ -50,11 +50,9 @@ func withExecArgs(s *specs.Process, args ...string) {
s.Args = append([]string{"powershell", "-noprofile"}, args...)
}
func withImageConfig(ctx context.Context, i Image) SpecOpts {
func withImageConfig(i Image) SpecOpts {
// TODO: when windows has a snapshotter remove the withImageConfig helper
return func(s *specs.Spec) error {
return nil
}
return withNoop
}
func withNewSnapshot(id string, i Image) NewContainerOpts {
@@ -65,9 +63,7 @@ func withNewSnapshot(id string, i Image) NewContainerOpts {
}
func withUserNamespace(u, g, s uint32) SpecOpts {
return func(s *specs.Spec) error {
return nil
}
return withNoop
}
func withRemappedSnapshot(id string, i Image, u, g uint32) NewContainerOpts {
@@ -75,3 +71,7 @@ func withRemappedSnapshot(id string, i Image, u, g uint32) NewContainerOpts {
return nil
}
}
func withNoop(_ context.Context, _ *Client, _ *specs.Spec) error {
return nil
}