Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
runtime: Adapt runtime because shim integration into virtcontainers
Browse files Browse the repository at this point in the history
Virtcontainers now integrates the shim, meaning we don't need to
handle this from the runtime anymore. The only thing we need is to
report the PID to Docker but that's it.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
  • Loading branch information
Sebastien Boeuf committed Apr 19, 2017
1 parent 1f3d7eb commit ee185aa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 59 deletions.
33 changes: 14 additions & 19 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
defaultRuntimeConfiguration = "/etc/clear-containers/configuration.toml"
defaultHypervisor = vc.QemuHypervisor
defaultProxy = vc.CCProxyType
defaultShim = vc.CCShimType
defaultAgent = vc.HyperstartAgent
defaultKernelPath = "/usr/share/clear-containers/vmlinux.container"
defaultImagePath = "/usr/share/clear-containers/clear-containers.img"
Expand Down Expand Up @@ -208,14 +209,15 @@ func updateRuntimeConfig(tomlConf tomlConfig, config *oci.RuntimeConfig) error {
}
}

return nil
}

func updateShimConfig(tomlConf tomlConfig, config *ShimConfig) error {
for k, shim := range tomlConf.Shim {
switch k {
case ccShim:
config.Path = shim.path()
shConfig := vc.CCShimConfig{
Path: shim.path(),
}

config.ShimType = vc.CCShimType
config.ShimConfig = shConfig

break
}
Expand All @@ -224,7 +226,7 @@ func updateShimConfig(tomlConf tomlConfig, config *ShimConfig) error {
return nil
}

func loadConfiguration(configPath string) (oci.RuntimeConfig, ShimConfig, error) {
func loadConfiguration(configPath string) (oci.RuntimeConfig, error) {
defaultHypervisorConfig := vc.HypervisorConfig{
HypervisorPath: defaultHypervisorPath,
KernelPath: defaultKernelPath,
Expand All @@ -242,10 +244,7 @@ func loadConfiguration(configPath string) (oci.RuntimeConfig, ShimConfig, error)
AgentType: defaultAgent,
AgentConfig: defaultAgentConfig,
ProxyType: defaultProxy,
}

shimConfig := ShimConfig{
Path: defaultShimPath,
ShimType: defaultShim,
}

if configPath == "" {
Expand All @@ -254,28 +253,24 @@ func loadConfiguration(configPath string) (oci.RuntimeConfig, ShimConfig, error)

configData, err := ioutil.ReadFile(configPath)
if err != nil {
return config, shimConfig, err
return config, err
}

var tomlConf tomlConfig
_, err = toml.Decode(string(configData), &tomlConf)
if err != nil {
return config, shimConfig, err
return config, err
}

ccLog.Debugf("TOML configuration: %v", tomlConf)

if err := checkConfigParams(tomlConf); err != nil {
return config, shimConfig, err
return config, err
}

if err := updateRuntimeConfig(tomlConf, &config); err != nil {
return config, shimConfig, err
}

if err := updateShimConfig(tomlConf, &shimConfig); err != nil {
return config, shimConfig, err
return config, err
}

return config, shimConfig, nil
return config, nil
}
37 changes: 19 additions & 18 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const runtimeMinimalConfig = `
[proxy.cc]
url = "` + proxyURL + `"
[shim.cc]
path = "` + shimPath + `"
`

func createConfig(fileName string, fileData string) (string, error) {
Expand All @@ -77,7 +80,7 @@ func TestRuntimeConfig(t *testing.T) {
t.Fatal(err)
}

config, shimConfig, err := loadConfiguration(configPath)
config, err := loadConfiguration(configPath)
if err != nil {
t.Fatal(err)
}
Expand All @@ -96,6 +99,10 @@ func TestRuntimeConfig(t *testing.T) {
URL: proxyURL,
}

expectedShimConfig := vc.CCShimConfig{
Path: shimPath,
}

expectedConfig := oci.RuntimeConfig{
HypervisorType: defaultHypervisor,
HypervisorConfig: expectedHypervisorConfig,
Expand All @@ -105,20 +112,15 @@ func TestRuntimeConfig(t *testing.T) {

ProxyType: defaultProxy,
ProxyConfig: expectedProxyConfig,
}

expectedShimConfig := ShimConfig{
Path: shimPath,
ShimType: defaultShim,
ShimConfig: expectedShimConfig,
}

if reflect.DeepEqual(config, expectedConfig) == false {
t.Fatalf("Got %v\n expecting %v", config, expectedConfig)
}

if reflect.DeepEqual(shimConfig, expectedShimConfig) == false {
t.Fatalf("Got %v\n expecting %v", shimConfig, expectedShimConfig)
}

if err := os.Remove(configPath); err != nil {
t.Fatal(err)
}
Expand All @@ -130,7 +132,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
t.Fatal(err)
}

config, shimConfig, err := loadConfiguration(configPath)
config, err := loadConfiguration(configPath)
if err != nil {
t.Fatal(err)
}
Expand All @@ -141,12 +143,16 @@ func TestMinimalRuntimeConfig(t *testing.T) {
ImagePath: defaultImagePath,
}

expectedAgentConfig := vc.HyperConfig{
PauseBinPath: filepath.Join(defaultPauseRootPath, pauseBinRelativePath),
}

expectedProxyConfig := vc.CCProxyConfig{
URL: proxyURL,
}

expectedAgentConfig := vc.HyperConfig{
PauseBinPath: filepath.Join(defaultPauseRootPath, pauseBinRelativePath),
expectedShimConfig := vc.CCShimConfig{
Path: shimPath,
}

expectedConfig := oci.RuntimeConfig{
Expand All @@ -158,20 +164,15 @@ func TestMinimalRuntimeConfig(t *testing.T) {

ProxyType: defaultProxy,
ProxyConfig: expectedProxyConfig,
}

expectedShimConfig := ShimConfig{
Path: defaultShimPath,
ShimType: defaultShim,
ShimConfig: expectedShimConfig,
}

if reflect.DeepEqual(config, expectedConfig) == false {
t.Fatalf("Got %v\n expecting %v", config, expectedConfig)
}

if reflect.DeepEqual(shimConfig, expectedShimConfig) == false {
t.Fatalf("Got %v\n expecting %v", shimConfig, expectedShimConfig)
}

if err := os.Remove(configPath); err != nil {
t.Fatal(err)
}
Expand Down
21 changes: 9 additions & 12 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func create(containerID, bundlePath, console, pidFilePath string) error {
return err
}

podConfig, shimConfig, ociSpec, err := getConfigs(bundlePath, containerID, console)
podConfig, ociSpec, err := getConfigs(bundlePath, containerID, console)
if err != nil {
return err
}
Expand All @@ -88,10 +88,7 @@ func create(containerID, bundlePath, console, pidFilePath string) error {
return fmt.Errorf("BUG: Container list from pod is wrong, expecting only one container, found %d containers", len(containers))
}

pid, err := startContainerShim(containers[0], shimConfig, pod.URL())
if err != nil {
return err
}
process := containers[0].Process()

// config.json provides a cgroups path that has to be used to create "tasks"
// and "cgroups.procs" files. Those files have to be filled with a PID, which
Expand All @@ -103,32 +100,32 @@ func create(containerID, bundlePath, console, pidFilePath string) error {
return err
}

if err := createCgroupsFiles(cgroupsPathList, pid); err != nil {
if err := createCgroupsFiles(cgroupsPathList, process.Pid); err != nil {
return err
}

// Creation of PID file has to be the last thing done in the create
// because containerd considers the create complete after this file
// is created.
if err := createPIDFile(pidFilePath, pid); err != nil {
if err := createPIDFile(pidFilePath, process.Pid); err != nil {
return err
}

return nil
}

func getConfigs(bundlePath, containerID, console string) (vc.PodConfig, ShimConfig, specs.Spec, error) {
runtimeConfig, shimConfig, err := loadConfiguration("")
func getConfigs(bundlePath, containerID, console string) (vc.PodConfig, specs.Spec, error) {
runtimeConfig, err := loadConfiguration("")
if err != nil {
return vc.PodConfig{}, ShimConfig{}, specs.Spec{}, err
return vc.PodConfig{}, specs.Spec{}, err
}

podConfig, ociSpec, err := oci.PodConfig(runtimeConfig, bundlePath, containerID, console)
if err != nil {
return vc.PodConfig{}, ShimConfig{}, specs.Spec{}, err
return vc.PodConfig{}, specs.Spec{}, err
}

return *podConfig, shimConfig, *ociSpec, nil
return *podConfig, *ociSpec, nil
}

func createCgroupsFiles(cgroupsPathList []string, pid int) error {
Expand Down
13 changes: 3 additions & 10 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,19 @@ func execute(params execParams) error {
User: params.ociProcess.User.Username,
}

_, shimConfig, err := loadConfiguration("")
if err != nil {
return err
}

pod, _, process, err := vc.EnterContainer(params.cID, podStatus.ContainersStatus[0].ID, cmd)
if err != nil {
if _, err := loadConfiguration(""); err != nil {
return err
}

// Start the shim to retrieve its PID.
pid, err := startShim(process, shimConfig, pod.URL())
_, _, process, err := vc.EnterContainer(params.cID, podStatus.ContainersStatus[0].ID, cmd)
if err != nil {
return err
}

// Creation of PID file has to be the last thing done in the exec
// because containerd considers the exec to have finished starting
// after this file is created.
if err := createPIDFile(params.pidFile, pid); err != nil {
if err := createPIDFile(params.pidFile, process.Pid); err != nil {
return err
}

Expand Down

0 comments on commit ee185aa

Please sign in to comment.