Add initial containerd *Client

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-05-23 15:50:06 -07:00
parent 17033dcaf2
commit d0e5732f0b
10 changed files with 482 additions and 0 deletions

44
spec.go Normal file
View File

@@ -0,0 +1,44 @@
package containerd
import specs "github.com/opencontainers/runtime-spec/specs-go"
type SpecOpts func(s *specs.Spec) error
func WithImageRef(ref string) SpecOpts {
return func(s *specs.Spec) error {
if s.Annotations == nil {
s.Annotations = make(map[string]string)
}
s.Annotations["image"] = ref
return nil
}
}
func WithHostname(id string) SpecOpts {
return func(s *specs.Spec) error {
s.Hostname = id
return nil
}
}
func WithArgs(args ...string) SpecOpts {
return func(s *specs.Spec) error {
s.Process.Args = args
return nil
}
}
// GenerateSpec will generate a default spec from the provided image
// for use as a containerd container
func GenerateSpec(opts ...SpecOpts) (*specs.Spec, error) {
s, err := createDefaultSpec()
if err != nil {
return nil, err
}
for _, o := range opts {
if err := o(s); err != nil {
return nil, err
}
}
return s, nil
}