Merge pull request #4327 from AkihiroSuda/fix-4326
shim v2 runc: propagate options.Root to Cleanup
This commit is contained in:
commit
fb80a49ec1
@ -20,6 +20,7 @@ package runc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -88,6 +89,10 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa
|
|||||||
Options: r.Options,
|
Options: r.Options,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := WriteOptions(r.Bundle, opts); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// For historical reason, we write opts.BinaryName as well as the entire opts
|
||||||
if err := WriteRuntime(r.Bundle, opts.BinaryName); err != nil {
|
if err := WriteRuntime(r.Bundle, opts.BinaryName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -156,6 +161,39 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa
|
|||||||
return container, nil
|
return container, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const optionsFilename = "options.json"
|
||||||
|
|
||||||
|
// ReadOptions reads the option information from the path.
|
||||||
|
// When the file does not exist, ReadOptions returns nil without an error.
|
||||||
|
func ReadOptions(path string) (*options.Options, error) {
|
||||||
|
filePath := filepath.Join(path, optionsFilename)
|
||||||
|
if _, err := os.Stat(filePath); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := ioutil.ReadFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var opts options.Options
|
||||||
|
if err := json.Unmarshal(data, &opts); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &opts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteOptions writes the options information into the path
|
||||||
|
func WriteOptions(path string, opts options.Options) error {
|
||||||
|
data, err := json.Marshal(opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return ioutil.WriteFile(filepath.Join(path, optionsFilename), data, 0600)
|
||||||
|
}
|
||||||
|
|
||||||
// ReadRuntime reads the runtime information from the path
|
// ReadRuntime reads the runtime information from the path
|
||||||
func ReadRuntime(path string) (string, error) {
|
func ReadRuntime(path string) (string, error) {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(path, "runtime"))
|
data, err := ioutil.ReadFile(filepath.Join(path, "runtime"))
|
||||||
|
@ -208,7 +208,16 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r := process.NewRunc(process.RuncRoot, path, ns, runtime, "", false)
|
opts, err := runc.ReadOptions(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
root := process.RuncRoot
|
||||||
|
if opts != nil && opts.Root != "" {
|
||||||
|
root = opts.Root
|
||||||
|
}
|
||||||
|
|
||||||
|
r := process.NewRunc(root, path, ns, runtime, "", false)
|
||||||
if err := r.Delete(ctx, s.id, &runcC.DeleteOpts{
|
if err := r.Delete(ctx, s.id, &runcC.DeleteOpts{
|
||||||
Force: true,
|
Force: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -277,7 +277,16 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r := process.NewRunc(process.RuncRoot, path, ns, runtime, "", false)
|
opts, err := runc.ReadOptions(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
root := process.RuncRoot
|
||||||
|
if opts != nil && opts.Root != "" {
|
||||||
|
root = opts.Root
|
||||||
|
}
|
||||||
|
|
||||||
|
r := process.NewRunc(root, path, ns, runtime, "", false)
|
||||||
if err := r.Delete(ctx, s.id, &runcC.DeleteOpts{
|
if err := r.Delete(ctx, s.id, &runcC.DeleteOpts{
|
||||||
Force: true,
|
Force: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user