Skip to content

Commit

Permalink
LCOW: Remove hard-coding
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <[email protected]>
  • Loading branch information
John Howard committed Aug 3, 2017
1 parent a3ffc42 commit ffdef62
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
31 changes: 31 additions & 0 deletions daemon/start_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/docker/container"
"github.com/docker/docker/layer"
"github.com/docker/docker/libcontainerd"
"github.com/jhowardmsft/opengcs/gogcs/client"
"golang.org/x/sys/windows/registry"
)

Expand Down Expand Up @@ -142,6 +143,36 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
}
}

// LCOW options.
if container.Platform == "linux" {
config := &client.Config{}
if err := config.GenerateDefault(daemon.configStore.GraphOptions); err != nil {
return nil, err
}
// Override from user-supplied options.
for k, v := range container.HostConfig.StorageOpt {
switch k {
case "lcow.kirdpath":
config.KirdPath = v
case "lcow.kernel":
config.KernelFile = v
case "lcow.initrd":
config.InitrdFile = v
case "lcow.vhdx":
config.Vhdx = v
case "lcow.bootparameters":
config.BootParameters = v
}
}
if err := config.Validate(); err != nil {
return nil, err
}
lcowOpts := &libcontainerd.LCOWOption{
Config: config,
}
createOptions = append(createOptions, lcowOpts)
}

// Now add the remaining options.
createOptions = append(createOptions, &libcontainerd.FlushOption{IgnoreFlushesDuringBoot: !container.HasBeenStartedBefore})
createOptions = append(createOptions, hvOpts)
Expand Down
36 changes: 25 additions & 11 deletions libcontainerd/client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/Microsoft/hcsshim"
"github.com/docker/docker/pkg/sysinfo"
opengcs "github.com/jhowardmsft/opengcs/gogcs/client"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -289,26 +290,39 @@ func (clnt *client) createWindows(containerID string, checkpoint string, checkpo
func (clnt *client) createLinux(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) error {
logrus.Debugf("libcontainerd: createLinux(): containerId %s ", containerID)

// TODO @jhowardmsft LCOW Support: This needs to be configurable, not hard-coded.
// However, good-enough for the LCOW bring-up.
var layerOpt *LayerOption
var lcowOpt *LCOWOption
for _, option := range options {
if layer, ok := option.(*LayerOption); ok {
layerOpt = layer
}
if lcow, ok := option.(*LCOWOption); ok {
lcowOpt = lcow
}
}
if lcowOpt == nil || lcowOpt.Config == nil {
return fmt.Errorf("lcow option must be supplied to the runtime")
}

configuration := &hcsshim.ContainerConfig{
HvPartition: true,
Name: containerID,
SystemType: "container",
ContainerType: "linux",
Owner: defaultOwner,
TerminateOnLastHandleClosed: true,
HvRuntime: &hcsshim.HvRuntime{
ImagePath: `c:\Program Files\Linux Containers`,
LinuxKernelFile: `bootx64.efi`,
LinuxInitrdFile: `initrd.img`,
},
}

var layerOpt *LayerOption
for _, option := range options {
if l, ok := option.(*LayerOption); ok {
layerOpt = l
if lcowOpt.Config.ActualMode == opengcs.ModeActualVhdx {
configuration.HvRuntime = &hcsshim.HvRuntime{
ImagePath: lcowOpt.Config.Vhdx,
}
} else {
configuration.HvRuntime = &hcsshim.HvRuntime{
ImagePath: lcowOpt.Config.KirdPath,
LinuxKernelFile: lcowOpt.Config.KernelFile,
LinuxInitrdFile: lcowOpt.Config.InitrdFile,
LinuxBootParameters: lcowOpt.Config.BootParameters,
}
}

Expand Down
5 changes: 2 additions & 3 deletions libcontainerd/container_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/Microsoft/hcsshim"
"github.com/docker/docker/pkg/system"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
Expand Down Expand Up @@ -89,8 +88,8 @@ func (ctr *container) start(attachStdio StdioCallback) error {
}
createProcessParms.User = ctr.ociSpec.Process.User.Username

// LCOW requires the raw OCI spec passed through HCS and onwards to GCS for the utility VM.
if system.LCOWSupported() && ctr.ociSpec.Platform.OS == "linux" {
// Linux containers requires the raw OCI spec passed through HCS and onwards to GCS for the utility VM.
if ctr.ociSpec.Platform.OS == "linux" {
ociBuf, err := json.Marshal(ctr.ociSpec)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions libcontainerd/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libcontainerd

import (
"github.com/Microsoft/hcsshim"
opengcs "github.com/jhowardmsft/opengcs/gogcs/client"
"github.com/opencontainers/runtime-spec/specs-go"
)

Expand All @@ -25,6 +26,11 @@ type Stats hcsshim.Statistics
// Resources defines updatable container resource values.
type Resources struct{}

// LCOWOption is a CreateOption required for LCOW configuration
type LCOWOption struct {
Config *opengcs.Config
}

// ServicingOption is a CreateOption with a no-op application that signifies
// the container needs to be used for a Windows servicing operation.
type ServicingOption struct {
Expand Down
5 changes: 5 additions & 0 deletions libcontainerd/utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ func (s *NetworkEndpointsOption) Apply(interface{}) error {
func (s *CredentialsOption) Apply(interface{}) error {
return nil
}

// Apply for the LCOW option is a no-op.
func (s *LCOWOption) Apply(interface{}) error {
return nil
}

0 comments on commit ffdef62

Please sign in to comment.