-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.go
70 lines (58 loc) · 1.42 KB
/
load.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ezdeploy
import (
"encoding/json"
"github.com/karrick/godirwalk"
"path/filepath"
"strings"
)
type LoadResult struct {
Releases []Release
Resources []Resource
ResourcesExt []Resource
}
type LoadOptions struct {
Charts map[string]Chart
}
func Load(root string, namespace string, opts LoadOptions) (result LoadResult, err error) {
if err = godirwalk.Walk(filepath.Join(root, namespace), &godirwalk.Options{
FollowSymbolicLinks: true,
Callback: func(file string, entry *godirwalk.Dirent) (err error) {
if entry.IsDir() ||
strings.HasPrefix(entry.Name(), ".") ||
strings.HasPrefix(entry.Name(), "_") {
return
}
var raws []json.RawMessage
if raws, err = collectResourceFile(file, namespace); err != nil {
return
}
if len(raws) == 0 {
return
}
for _, raw := range raws {
res := Resource{
Namespace: namespace,
Raw: raw,
Path: file,
Checksum: checksumBytes(raw),
}
if err = json.Unmarshal(raw, &res.Object); err != nil {
return
}
res.ID = CreateResourceID(namespace, res.Object)
if res.Object.Metadata.Namespace == "" {
result.Resources = append(result.Resources, res)
} else {
result.ResourcesExt = append(result.ResourcesExt, res)
}
}
return
},
}); err != nil {
return
}
if result.Releases, err = collectReleases(root, namespace, opts.Charts); err != nil {
return
}
return
}