Add a Windows section for Linux oci on LCOW
When creating a default OCI spec on Windows that is targeting the LCOW platform it needs to contain a Windows section as well. This adds the Windows section by default. It also protects against this case for all OCI creation that doesnt use the OCI package in the runhcs-shim. Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
31
oci/spec.go
31
oci/spec.go
@@ -19,6 +19,7 @@ package oci
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
@@ -51,24 +52,32 @@ func GenerateSpec(ctx context.Context, client Client, c *containers.Container, o
|
||||
// GenerateSpecWithPlatform will generate a default spec from the provided image
|
||||
// for use as a containerd container in the platform requested.
|
||||
func GenerateSpecWithPlatform(ctx context.Context, client Client, platform string, c *containers.Container, opts ...SpecOpts) (*Spec, error) {
|
||||
plat, err := platforms.Parse(platform)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var s Spec
|
||||
if plat.OS == "windows" {
|
||||
err = populateDefaultWindowsSpec(ctx, &s, c.ID)
|
||||
} else {
|
||||
err = populateDefaultUnixSpec(ctx, &s, c.ID)
|
||||
}
|
||||
if err != nil {
|
||||
if err := generateDefaultSpecWithPlatform(ctx, platform, c.ID, &s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &s, ApplyOpts(ctx, client, c, &s, opts...)
|
||||
}
|
||||
|
||||
func generateDefaultSpecWithPlatform(ctx context.Context, platform, id string, s *Spec) error {
|
||||
plat, err := platforms.Parse(platform)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if plat.OS == "windows" {
|
||||
err = populateDefaultWindowsSpec(ctx, s, id)
|
||||
} else {
|
||||
err = populateDefaultUnixSpec(ctx, s, id)
|
||||
if err == nil && runtime.GOOS == "windows" {
|
||||
// To run LCOW we have a Linux and Windows section. Add an empty one now.
|
||||
s.Windows = &specs.Windows{}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ApplyOpts applys the options to the given spec, injecting data from the
|
||||
// context, client and container instance.
|
||||
func ApplyOpts(ctx context.Context, client Client, c *containers.Container, s *Spec, opts ...SpecOpts) error {
|
||||
|
||||
Reference in New Issue
Block a user