-
Notifications
You must be signed in to change notification settings - Fork 28
/
cluster.go
47 lines (36 loc) · 1.02 KB
/
cluster.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
package collectors
import (
"path/filepath"
"github.com/sirupsen/logrus"
)
type clusterModule struct {
c *common
name string
}
func NewClusterModule(common *common, name string) *clusterModule {
return &clusterModule{
c: common,
name: name,
}
}
func (module clusterModule) generateYAMLs() {
logrus.Infof("[%s] generate YAMLs, yamlsDir: %s", module.name, module.c.yamlsDir)
// Cluster scope
globalDir := filepath.Join(module.c.yamlsDir, "cluster")
objs, err := module.c.discovery.ResourcesForCluster(module.toObj, module.c.exclude, module.c.errorLog)
if err != nil {
logrus.Error("Unable to fetch cluster resources")
return
}
for name, obj := range objs {
file := filepath.Join(globalDir, name+".yaml")
module.c.encodeFunc(obj, file, module.c.errorLog)
}
}
func (module clusterModule) toObj(b []byte, groupVersion, kind string, resources ...string) (interface{}, error) {
jsonParsed, err := module.c.toObjCommon(b, groupVersion, kind)
if err != nil {
return nil, err
}
return jsonParsed.Data(), nil
}