-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_store.go
61 lines (57 loc) · 1.71 KB
/
transform_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
package workload
import (
"strings"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/definition"
"github.com/rancher/norman/types/values"
"github.com/rancher/rancher/pkg/api/store/pod"
"github.com/sirupsen/logrus"
)
func New(store types.Store) types.Store {
return &transform.Store{
Store: store,
Transformer: func(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, opt *types.QueryOptions) (map[string]interface{}, error) {
hide := true
if opt != nil && opt.Options["hidden"] == "true" {
hide = false
}
if opt != nil && opt.Options["ByID"] == "true" {
hide = false
}
typeName := definition.GetType(data)
name, _ := data["name"].(string)
if hide && data["ownerReferences"] != nil {
pod.SaveOwner(apiContext, typeName, name, data)
return nil, nil
}
id, _ := data["id"].(string)
if typeName != "" && id != "" {
data["id"] = strings.ToLower(typeName) + ":" + id
}
SetPublicEnpointsFields(data)
nodeName := convert.ToString(values.GetValueN(data, "nodeId"))
if nodeName != "" {
state := getState(data)
data["nodeId"] = state[getKey(nodeName)]
}
return data, nil
},
}
}
func SetPublicEnpointsFields(data map[string]interface{}) {
if val, ok := data["publicEndpoints"]; ok {
eps := convert.ToInterfaceSlice(val)
for _, ep := range eps {
epMap, err := convert.EncodeToMap(ep)
if err != nil {
logrus.Errorf("Failed to convert public endpoint: %v", err)
continue
}
epMap["serviceId"] = epMap["serviceName"]
epMap["nodeId"] = epMap["nodeName"]
epMap["ingressId"] = epMap["ingressName"]
}
}
}