代码拉取完成,页面将自动刷新
package pod
import (
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/clustermanager"
"github.com/rancher/rancher/pkg/ref"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"k8s.io/client-go/tools/cache"
)
const (
nodeNameIdx = "nodeNameId"
)
func New(store types.Store, clusterManager *clustermanager.Manager, scaledContext *config.ScaledContext) types.Store {
return &transform.Store{
Store: store,
Transformer: newPT(clusterManager, scaledContext),
}
}
func newPT(clusterManager *clustermanager.Manager, scaledContext *config.ScaledContext) transform.TransformerFunc {
scaledContext.Management.Nodes("").Controller().Informer().AddIndexers(cache.Indexers{
nodeNameIdx: func(obj interface{}) ([]string, error) {
node := obj.(*v3.Node)
name := node.Status.NodeName
if name == "" {
return nil, nil
}
return []string{ref.FromStrings(node.Namespace, name)}, nil
},
})
pt := &podTransformer{
clusterManager: clusterManager,
nodeIndexer: scaledContext.Management.Nodes("").Controller().Informer().GetIndexer(),
}
return pt.transformer
}
type podTransformer struct {
clusterManager *clustermanager.Manager
nodeIndexer cache.Indexer
}
func (p *podTransformer) transformer(context *types.APIContext, schema *types.Schema, data map[string]interface{}, opt *types.QueryOptions) (map[string]interface{}, error) {
if data == nil {
return data, nil
}
owner := resolveWorkloadID(context, data)
if owner != "" {
data["workloadId"] = owner
}
clusterName := p.clusterManager.ClusterName(context)
nodeName, _ := data["nodeId"].(string)
nodes, err := p.nodeIndexer.ByIndex(nodeNameIdx, ref.FromStrings(clusterName, nodeName))
if err != nil {
return nil, err
}
if len(nodes) == 1 {
node := nodes[0].(*v3.Node)
data["nodeId"] = ref.FromStrings(node.Namespace, node.Name)
}
return data, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。