Skip to content

Commit

Permalink
Do not return error when userdata not found
Browse files Browse the repository at this point in the history
Not finding userdata/metadata is an expected outcome, log a warning
instead of returning an error.

Signed-off-by: Fredrik Lönnegren <[email protected]>
  • Loading branch information
frelon committed Oct 1, 2024
1 parent 9d92069 commit d482c98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
9 changes: 4 additions & 5 deletions pkg/plugins/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,17 @@ func DataSources(l logger.Interface, s schema.Stage, fs vfs.FS, console Console)
}

if userdata == nil {
return fmt.Errorf("no metadata/userdata found")
l.Warn("No metadata/userdata found")
return nil
}

basePath := prv.ConfigPath
if s.DataSources.Path != "" && s.DataSources.Path != p.String() {
basePath = s.DataSources.Path
}

if userdata != nil {
if err := processUserData(l, basePath, userdata, fs, console); err != nil {
return err
}
if err := processUserData(l, basePath, userdata, fs, console); err != nil {
return err
}

//Apply the hostname if the provider extracted a hostname file
Expand Down
9 changes: 3 additions & 6 deletions pkg/plugins/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"io"
"os"
"path/filepath"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -38,7 +37,7 @@ var _ = Describe("Datasources", func() {
l := logrus.New()
l.SetLevel(logrus.DebugLevel)
l.SetOutput(io.Discard)
It("Runs datasources and fails to adquire any metadata", func() {
It("Runs datasources and fails to aquire any metadata", func() {
fs, cleanup, err := vfst.NewTestFS(map[string]interface{}{})
Expect(err).Should(BeNil())
defer cleanup()
Expand All @@ -47,8 +46,7 @@ var _ = Describe("Datasources", func() {
Providers: []string{"cdrom"},
},
}, fs, testConsole)
Expect(err).To(HaveOccurred())
Expect(strings.ToLower(err.Error())).To(ContainSubstring("no metadata/userdata found"))
Expect(err).ToNot(HaveOccurred())
_, err = fs.Stat(providers.ConfigPath)
Expect(err).ShouldNot(HaveOccurred())
})
Expand All @@ -75,8 +73,7 @@ var _ = Describe("Datasources", func() {
},
}, fs, testConsole)
elapsed := time.Since(start)
Expect(err).To(HaveOccurred())
Expect(strings.ToLower(err.Error())).To(ContainSubstring("no metadata/userdata found"))
Expect(err).ToNot(HaveOccurred())
// check if it took less than 10 seconds. If we were to run all those datasources one after the other
// it would take much more
Expect(elapsed).To(BeNumerically("<", 10*time.Second))
Expand Down

0 comments on commit d482c98

Please sign in to comment.