From 3af54c416a02653431a376af914a52a87e65aee1 Mon Sep 17 00:00:00 2001 From: Marco Geri Date: Thu, 2 Feb 2023 23:24:20 +0100 Subject: [PATCH 1/2] give error when no matching devices are found --- hostdevice.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hostdevice.go b/hostdevice.go index 7893ff0..dbe5219 100644 --- a/hostdevice.go +++ b/hostdevice.go @@ -48,6 +48,9 @@ func (d HostDevice) Expand() ([]*ExpandedHostDevice, error) { if err != nil { return nil, err } + if len(matchedHostPath) == 0 { + return nil, fmt.Errorf("no file matched: %s", d.HostPath) + } expanded := []*ExpandedHostDevice{} baseHostPath := strings.Split(d.HostPath, "*")[0] From 1874028e8f8d1f41721e187f273eee5d5f1ff35e Mon Sep 17 00:00:00 2001 From: Marco Geri Date: Thu, 2 Feb 2023 23:40:46 +0100 Subject: [PATCH 2/2] give better error logging on fatal error --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index dcb60ed..98ab7e2 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ func main() { log.Println("Starting FS watcher.") watcher, err := newFSWatcher(pluginapi.DevicePluginPath) if err != nil { - log.Println("Failed to created FS watcher.") + log.Printf("Failed to created FS watcher: %v", err) os.Exit(1) } defer watcher.Close() @@ -34,7 +34,7 @@ func main() { log.Println("Reading /k8s-host-device-plugin/config.json") raw, err := ioutil.ReadFile(ConfigFilePath) if err != nil { - fmt.Println(err.Error()) + log.Printf("Fatal error reading config file: %v", err) os.Exit(1) } @@ -56,7 +56,7 @@ L: devicePlugin, err = NewHostDevicePlugin(config) if err != nil { - fmt.Println(err.Error()) + log.Printf("Fatal error configuring host device: %v", err) os.Exit(1) } expandedHostDevicesStr := []string{}