Skip to content

Commit 8ea01cc

Browse files
authored
Merge pull request #2336 from crosbymichael/spec-alias
Type alias spec in oci package
2 parents cff5e75 + 62e22a9 commit 8ea01cc

9 files changed

Lines changed: 55 additions & 52 deletions

container.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828
"github.com/containerd/containerd/cio"
2929
"github.com/containerd/containerd/containers"
3030
"github.com/containerd/containerd/errdefs"
31+
"github.com/containerd/containerd/oci"
3132
"github.com/containerd/typeurl"
3233
prototypes "github.com/gogo/protobuf/types"
33-
specs "github.com/opencontainers/runtime-spec/specs-go"
3434
"github.com/pkg/errors"
3535
)
3636

@@ -45,7 +45,7 @@ type Container interface {
4545
// NewTask creates a new task based on the container metadata
4646
NewTask(context.Context, cio.Creator, ...NewTaskOpts) (Task, error)
4747
// Spec returns the OCI runtime specification
48-
Spec(context.Context) (*specs.Spec, error)
48+
Spec(context.Context) (*oci.Spec, error)
4949
// Task returns the current task for the container
5050
//
5151
// If cio.Attach options are passed the client will reattach to the IO for the running
@@ -126,12 +126,12 @@ func (c *container) SetLabels(ctx context.Context, labels map[string]string) (ma
126126
}
127127

128128
// Spec returns the current OCI specification for the container
129-
func (c *container) Spec(ctx context.Context) (*specs.Spec, error) {
129+
func (c *container) Spec(ctx context.Context) (*oci.Spec, error) {
130130
r, err := c.get(ctx)
131131
if err != nil {
132132
return nil, err
133133
}
134-
var s specs.Spec
134+
var s oci.Spec
135135
if err := json.Unmarshal(r.Spec.Value, &s); err != nil {
136136
return nil, err
137137
}

container_opts.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/containerd/typeurl"
2727
"github.com/gogo/protobuf/types"
2828
"github.com/opencontainers/image-spec/identity"
29-
specs "github.com/opencontainers/runtime-spec/specs-go"
3029
"github.com/pkg/errors"
3130
)
3231

@@ -196,7 +195,7 @@ func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts {
196195
}
197196

198197
// WithSpec sets the provided spec on the container
199-
func WithSpec(s *specs.Spec, opts ...oci.SpecOpts) NewContainerOpts {
198+
func WithSpec(s *oci.Spec, opts ...oci.SpecOpts) NewContainerOpts {
200199
return func(ctx context.Context, client *Client, c *containers.Container) error {
201200
for _, o := range opts {
202201
if err := o(ctx, client, c, s); err != nil {

oci/spec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ import (
2323
specs "github.com/opencontainers/runtime-spec/specs-go"
2424
)
2525

26+
// Spec is a type alias to the OCI runtime spec to allow third part SpecOpts
27+
// to be created without the "issues" with go vendoring and package imports
28+
type Spec = specs.Spec
29+
2630
// GenerateSpec will generate a default spec from the provided image
2731
// for use as a containerd container
28-
func GenerateSpec(ctx context.Context, client Client, c *containers.Container, opts ...SpecOpts) (*specs.Spec, error) {
32+
func GenerateSpec(ctx context.Context, client Client, c *containers.Container, opts ...SpecOpts) (*Spec, error) {
2933
s, err := createDefaultSpec(ctx, c.ID)
3034
if err != nil {
3135
return nil, err

oci/spec_opts.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import (
2525
)
2626

2727
// SpecOpts sets spec specific information to a newly generated OCI spec
28-
type SpecOpts func(context.Context, Client, *containers.Container, *specs.Spec) error
28+
type SpecOpts func(context.Context, Client, *containers.Container, *Spec) error
2929

3030
// Compose converts a sequence of spec operations into a single operation
3131
func Compose(opts ...SpecOpts) SpecOpts {
32-
return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error {
32+
return func(ctx context.Context, client Client, c *containers.Container, s *Spec) error {
3333
for _, o := range opts {
3434
if err := o(ctx, client, c, s); err != nil {
3535
return err
@@ -40,15 +40,15 @@ func Compose(opts ...SpecOpts) SpecOpts {
4040
}
4141

4242
// setProcess sets Process to empty if unset
43-
func setProcess(s *specs.Spec) {
43+
func setProcess(s *Spec) {
4444
if s.Process == nil {
4545
s.Process = &specs.Process{}
4646
}
4747
}
4848

4949
// WithProcessArgs replaces the args on the generated spec
5050
func WithProcessArgs(args ...string) SpecOpts {
51-
return func(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
51+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
5252
setProcess(s)
5353
s.Process.Args = args
5454
return nil
@@ -57,7 +57,7 @@ func WithProcessArgs(args ...string) SpecOpts {
5757

5858
// WithProcessCwd replaces the current working directory on the generated spec
5959
func WithProcessCwd(cwd string) SpecOpts {
60-
return func(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
60+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
6161
setProcess(s)
6262
s.Process.Cwd = cwd
6363
return nil
@@ -66,15 +66,15 @@ func WithProcessCwd(cwd string) SpecOpts {
6666

6767
// WithHostname sets the container's hostname
6868
func WithHostname(name string) SpecOpts {
69-
return func(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
69+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
7070
s.Hostname = name
7171
return nil
7272
}
7373
}
7474

7575
// WithEnv appends environment variables
7676
func WithEnv(environmentVariables []string) SpecOpts {
77-
return func(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
77+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
7878
if len(environmentVariables) > 0 {
7979
setProcess(s)
8080
s.Process.Env = replaceOrAppendEnvValues(s.Process.Env, environmentVariables)
@@ -85,7 +85,7 @@ func WithEnv(environmentVariables []string) SpecOpts {
8585

8686
// WithMounts appends mounts
8787
func WithMounts(mounts []specs.Mount) SpecOpts {
88-
return func(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
88+
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
8989
s.Mounts = append(s.Mounts, mounts...)
9090
return nil
9191
}

oci/spec_opts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
func TestWithEnv(t *testing.T) {
2626
t.Parallel()
2727

28-
s := specs.Spec{}
28+
s := Spec{}
2929
s.Process = &specs.Process{
3030
Env: []string{"DEFAULT=test"},
3131
}
@@ -59,7 +59,7 @@ func TestWithMounts(t *testing.T) {
5959

6060
t.Parallel()
6161

62-
s := specs.Spec{
62+
s := Spec{
6363
Mounts: []specs.Mount{
6464
{
6565
Source: "default-source",

0 commit comments

Comments
 (0)