mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
LCOW: Remove hard-coding
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
a3ffc42b13
commit
ffdef6255e
5 changed files with 69 additions and 14 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/layer"
|
"github.com/docker/docker/layer"
|
||||||
"github.com/docker/docker/libcontainerd"
|
"github.com/docker/docker/libcontainerd"
|
||||||
|
"github.com/jhowardmsft/opengcs/gogcs/client"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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.
|
// Now add the remaining options.
|
||||||
createOptions = append(createOptions, &libcontainerd.FlushOption{IgnoreFlushesDuringBoot: !container.HasBeenStartedBefore})
|
createOptions = append(createOptions, &libcontainerd.FlushOption{IgnoreFlushesDuringBoot: !container.HasBeenStartedBefore})
|
||||||
createOptions = append(createOptions, hvOpts)
|
createOptions = append(createOptions, hvOpts)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
"github.com/docker/docker/pkg/sysinfo"
|
"github.com/docker/docker/pkg/sysinfo"
|
||||||
|
opengcs "github.com/jhowardmsft/opengcs/gogcs/client"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -289,8 +290,20 @@ 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 {
|
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)
|
logrus.Debugf("libcontainerd: createLinux(): containerId %s ", containerID)
|
||||||
|
|
||||||
// TODO @jhowardmsft LCOW Support: This needs to be configurable, not hard-coded.
|
var layerOpt *LayerOption
|
||||||
// However, good-enough for the LCOW bring-up.
|
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{
|
configuration := &hcsshim.ContainerConfig{
|
||||||
HvPartition: true,
|
HvPartition: true,
|
||||||
Name: containerID,
|
Name: containerID,
|
||||||
|
@ -298,17 +311,18 @@ func (clnt *client) createLinux(containerID string, checkpoint string, checkpoin
|
||||||
ContainerType: "linux",
|
ContainerType: "linux",
|
||||||
Owner: defaultOwner,
|
Owner: defaultOwner,
|
||||||
TerminateOnLastHandleClosed: true,
|
TerminateOnLastHandleClosed: true,
|
||||||
HvRuntime: &hcsshim.HvRuntime{
|
|
||||||
ImagePath: `c:\Program Files\Linux Containers`,
|
|
||||||
LinuxKernelFile: `bootx64.efi`,
|
|
||||||
LinuxInitrdFile: `initrd.img`,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var layerOpt *LayerOption
|
if lcowOpt.Config.ActualMode == opengcs.ModeActualVhdx {
|
||||||
for _, option := range options {
|
configuration.HvRuntime = &hcsshim.HvRuntime{
|
||||||
if l, ok := option.(*LayerOption); ok {
|
ImagePath: lcowOpt.Config.Vhdx,
|
||||||
layerOpt = l
|
}
|
||||||
|
} else {
|
||||||
|
configuration.HvRuntime = &hcsshim.HvRuntime{
|
||||||
|
ImagePath: lcowOpt.Config.KirdPath,
|
||||||
|
LinuxKernelFile: lcowOpt.Config.KernelFile,
|
||||||
|
LinuxInitrdFile: lcowOpt.Config.InitrdFile,
|
||||||
|
LinuxBootParameters: lcowOpt.Config.BootParameters,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
"github.com/docker/docker/pkg/system"
|
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
@ -89,8 +88,8 @@ func (ctr *container) start(attachStdio StdioCallback) error {
|
||||||
}
|
}
|
||||||
createProcessParms.User = ctr.ociSpec.Process.User.Username
|
createProcessParms.User = ctr.ociSpec.Process.User.Username
|
||||||
|
|
||||||
// LCOW requires the raw OCI spec passed through HCS and onwards to GCS for the utility VM.
|
// Linux containers requires the raw OCI spec passed through HCS and onwards to GCS for the utility VM.
|
||||||
if system.LCOWSupported() && ctr.ociSpec.Platform.OS == "linux" {
|
if ctr.ociSpec.Platform.OS == "linux" {
|
||||||
ociBuf, err := json.Marshal(ctr.ociSpec)
|
ociBuf, err := json.Marshal(ctr.ociSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -2,6 +2,7 @@ package libcontainerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
|
opengcs "github.com/jhowardmsft/opengcs/gogcs/client"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,6 +26,11 @@ type Stats hcsshim.Statistics
|
||||||
// Resources defines updatable container resource values.
|
// Resources defines updatable container resource values.
|
||||||
type Resources struct{}
|
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
|
// ServicingOption is a CreateOption with a no-op application that signifies
|
||||||
// the container needs to be used for a Windows servicing operation.
|
// the container needs to be used for a Windows servicing operation.
|
||||||
type ServicingOption struct {
|
type ServicingOption struct {
|
||||||
|
|
|
@ -44,3 +44,8 @@ func (s *NetworkEndpointsOption) Apply(interface{}) error {
|
||||||
func (s *CredentialsOption) Apply(interface{}) error {
|
func (s *CredentialsOption) Apply(interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply for the LCOW option is a no-op.
|
||||||
|
func (s *LCOWOption) Apply(interface{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue