forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
71 lines (60 loc) · 1.79 KB
/
store.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
71
package node
import (
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/values"
"github.com/rancher/rancher/pkg/api/store/workload"
)
type nodeStore struct {
types.Store
}
func SetupStore(schema *types.Schema) {
schema.Store = &transform.Store{
Store: nodeStore{
Store: schema.Store,
},
Transformer: func(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, opt *types.QueryOptions) (map[string]interface{}, error) {
workload.SetPublicEnpointsFields(data)
if convert.ToBool(values.GetValueN(data, "unschedulable")) {
data["state"] = "cordoned"
}
return data, nil
},
}
}
func (n nodeStore) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
setName := false
for _, cond := range opt.Conditions {
if cond.Field == "name" && cond.ToCondition().Modifier == types.ModifierEQ {
setName = true
break
}
}
datas, err := n.Store.List(apiContext, schema, opt)
if err != nil || !setName {
return datas, err
}
for _, data := range datas {
if !convert.IsEmpty(data["name"]) {
continue
}
if !convert.IsEmpty(data["nodeName"]) {
data["name"] = data["nodeName"]
continue
}
if !convert.IsEmpty(data["requestedHostname"]) {
data["name"] = data["requestedHostname"]
continue
}
}
return datas, err
}
func (n nodeStore) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
format(data)
return n.Store.Update(apiContext, schema, data, id)
}
func format(data map[string]interface{}) {
data["desiredNodeLabels"] = data["labels"]
data["desiredNodeAnnotations"] = data["annotations"]
}