Fix 'not a directory' error when restoring bootstrap.json
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
cf75cfa32c
commit
f76eaf5a6b
@ -18,6 +18,7 @@ package v2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -205,7 +206,7 @@ func (m *ShimManager) Start(ctx context.Context, id string, opts runtime.CreateO
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
params, err := restoreBootstrapParams(filepath.Join(m.state, process.Namespace(), opts.SandboxID, "bootstrap.json"))
|
params, err := restoreBootstrapParams(filepath.Join(m.state, process.Namespace(), opts.SandboxID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -288,13 +289,12 @@ func (m *ShimManager) startShim(ctx context.Context, bundle *Bundle, id string,
|
|||||||
// configuration (version = 2, protocol = ttrpc, and address).
|
// configuration (version = 2, protocol = ttrpc, and address).
|
||||||
func restoreBootstrapParams(bundlePath string) (shimbinary.BootstrapParams, error) {
|
func restoreBootstrapParams(bundlePath string) (shimbinary.BootstrapParams, error) {
|
||||||
filePath := filepath.Join(bundlePath, "bootstrap.json")
|
filePath := filepath.Join(bundlePath, "bootstrap.json")
|
||||||
params, err := readBootstrapParams(filePath)
|
|
||||||
if err == nil {
|
|
||||||
return params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !os.IsNotExist(err) {
|
// Read bootstrap.json if exists
|
||||||
return shimbinary.BootstrapParams{}, fmt.Errorf("failed to read bootstrap.json for bundle %s: %w", bundlePath, err)
|
if _, err := os.Stat(filePath); err == nil {
|
||||||
|
return readBootstrapParams(filePath)
|
||||||
|
} else if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return shimbinary.BootstrapParams{}, fmt.Errorf("failed to stat %s: %w", filePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// File not found, likely its an older shim. Try migrate.
|
// File not found, likely its an older shim. Try migrate.
|
||||||
@ -304,7 +304,7 @@ func restoreBootstrapParams(bundlePath string) (shimbinary.BootstrapParams, erro
|
|||||||
return shimbinary.BootstrapParams{}, fmt.Errorf("unable to migrate shim: failed to get socket address for bundle %s: %w", bundlePath, err)
|
return shimbinary.BootstrapParams{}, fmt.Errorf("unable to migrate shim: failed to get socket address for bundle %s: %w", bundlePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
params = shimbinary.BootstrapParams{
|
params := shimbinary.BootstrapParams{
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Address: address,
|
Address: address,
|
||||||
Protocol: "ttrpc",
|
Protocol: "ttrpc",
|
||||||
|
@ -96,7 +96,7 @@ func loadShim(ctx context.Context, bundle *Bundle, onClose func()) (_ ShimInstan
|
|||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
params, err := restoreBootstrapParams(filepath.Join(bundle.Path, "bootstrap.json"))
|
params, err := restoreBootstrapParams(bundle.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read boostrap.json when restoring bundle %q: %w", bundle.ID, err)
|
return nil, fmt.Errorf("failed to read boostrap.json when restoring bundle %q: %w", bundle.ID, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user