/
meta.go
43 lines (35 loc) 路 826 Bytes
/
meta.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
package client
import (
"github.com/derailed/popeye/types"
)
// Schema tracks resource schema.
type Schema struct {
GVR GVR
Preferred bool
}
// Meta tracks a collection of resources.
type Meta map[string][]Schema
func newMeta() Meta {
return make(map[string][]Schema)
}
// Resources tracks dictionary of resources.
var Resources = newMeta()
// Load loads resource meta from server.
func Load(f types.Factory) error {
dial, err := f.Client().CachedDiscovery()
if err != nil {
return err
}
rr, err := dial.ServerPreferredResources()
if err != nil {
return err
}
for _, r := range rr {
for _, res := range r.APIResources {
gvr := FromGVAndR(r.GroupVersion, res.Name)
res.Group, res.Version = gvr.G(), gvr.V()
Resources[gvr.R()] = []Schema{{GVR: gvr, Preferred: true}}
}
}
return nil
}