-
Notifications
You must be signed in to change notification settings - Fork 88
/
troubleshoot.go
52 lines (43 loc) · 1.19 KB
/
troubleshoot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package kotsutil
import (
"context"
"os"
"path/filepath"
"github.com/pkg/errors"
troubleshootloader "github.com/replicatedhq/troubleshoot/pkg/loader"
)
func LoadTSKindsFromPath(dir string) (*troubleshootloader.TroubleshootKinds, error) {
if _, err := os.Stat(dir); err != nil {
if !os.IsNotExist(err) {
return nil, errors.Wrapf(err, "failed to stat dir: %s", dir)
}
return &troubleshootloader.TroubleshootKinds{}, nil
}
var renderedFiles []string
err := filepath.Walk(dir,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return errors.Wrapf(err, "failed to walk dir: %s", dir)
}
if info.IsDir() {
return nil
}
contents, err := os.ReadFile(path)
if err != nil {
return errors.Wrap(err, "failed to read file")
}
renderedFiles = append(renderedFiles, string(contents))
return nil
})
if err != nil {
return nil, errors.Wrapf(err, "failed to walk dir: %s", dir)
}
ctx := context.Background()
tsKinds, err := troubleshootloader.LoadSpecs(ctx, troubleshootloader.LoadOptions{
RawSpecs: renderedFiles,
})
if err != nil {
return nil, errors.Wrap(err, "failed to load troubleshoot specs from archive")
}
return tsKinds, nil
}