37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
store.go 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-07-13 13:41 . Refactor IsEmpty
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.IsAPIObjectEmpty(data["name"]) {
continue
}
if !convert.IsAPIObjectEmpty(data["nodeName"]) {
data["name"] = data["nodeName"]
continue
}
if !convert.IsAPIObjectEmpty(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"]
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.7-rc1

搜索帮助

0d507c66 1850385 C8b1a773 1850385