Determine which nerdctl implementation

When called via the library path, the nerdctl provider is
instantiated without a binary name. We still need to do
a lookup to determine if finch or nerdctl is the installed
binary to provide the local runtime command line

Signed-off-by: Phil Estes <estesp@gmail.com>
This commit is contained in:
Phil Estes
2024-03-21 11:17:30 +01:00
parent 9ea8a5993a
commit 1759f35318

View File

@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"net"
osexec "os/exec"
"path/filepath"
"strings"
@@ -40,9 +41,21 @@ import (
// NewProvider returns a new provider based on executing `nerdctl ...`
func NewProvider(logger log.Logger, binaryName string) providers.Provider {
// if unset, default to nerdctl
// if binaryName is unset, do a lookup; we may be here via a
// library call to provider.DetectNodeProvider(), which returns
// true from nerdctl.IsAvailable() by checking for both finch
// and nerdctl. If we don't redo the lookup here, then a finch
// install that triggered IsAvailable() to be true would fail
// to be used if we default to nerdctl when unset.
if binaryName == "" {
// default to "nerdctl"; but look for "finch" if
// nerctl binary lookup fails
binaryName = "nerdctl"
if _, err := osexec.LookPath("nerdctl"); err != nil {
if _, err := osexec.LookPath("finch"); err == nil {
binaryName = "finch"
}
}
}
return &provider{
logger: logger,