From f76eaf5a6be624dfe66787eda8fddf9ecb1a65b7 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sat, 14 Oct 2023 09:37:19 -0700 Subject: [PATCH] Fix 'not a directory' error when restoring bootstrap.json Signed-off-by: Maksym Pavlenko --- runtime/v2/manager.go | 16 ++++++++-------- runtime/v2/shim.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 4a62f59fd..923489eed 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -18,6 +18,7 @@ package v2 import ( "context" + "errors" "fmt" "os" "os/exec" @@ -205,7 +206,7 @@ func (m *ShimManager) Start(ctx context.Context, id string, opts runtime.CreateO 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 { 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). func restoreBootstrapParams(bundlePath string) (shimbinary.BootstrapParams, error) { filePath := filepath.Join(bundlePath, "bootstrap.json") - params, err := readBootstrapParams(filePath) - if err == nil { - return params, nil - } - if !os.IsNotExist(err) { - return shimbinary.BootstrapParams{}, fmt.Errorf("failed to read bootstrap.json for bundle %s: %w", bundlePath, err) + // Read bootstrap.json if exists + 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. @@ -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) } - params = shimbinary.BootstrapParams{ + params := shimbinary.BootstrapParams{ Version: 2, Address: address, Protocol: "ttrpc", diff --git a/runtime/v2/shim.go b/runtime/v2/shim.go index ed776a71c..72635144c 100644 --- a/runtime/v2/shim.go +++ b/runtime/v2/shim.go @@ -96,7 +96,7 @@ func loadShim(ctx context.Context, bundle *Bundle, onClose func()) (_ ShimInstan f.Close() } - params, err := restoreBootstrapParams(filepath.Join(bundle.Path, "bootstrap.json")) + params, err := restoreBootstrapParams(bundle.Path) if err != nil { return nil, fmt.Errorf("failed to read boostrap.json when restoring bundle %q: %w", bundle.ID, err) }