37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
namespace.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
package namespace
import (
"time"
"github.com/rancher/norman/api/access"
"github.com/rancher/norman/types"
"github.com/rancher/types/apis/cluster.cattle.io/v3/schema"
"github.com/rancher/types/client/cluster/v3"
"k8s.io/apimachinery/pkg/util/cache"
)
var (
namespaceOwnerMap = cache.NewLRUExpireCache(1000)
)
func updateNamespaceOwnerMap(apiContext *types.APIContext) error {
var namespaces []client.Namespace
if err := access.List(apiContext, &schema.Version, client.NamespaceType, &types.QueryOptions{}, &namespaces); err != nil {
return err
}
for _, namespace := range namespaces {
namespaceOwnerMap.Add(namespace.Name, namespace.ProjectID, time.Hour)
}
return nil
}
func ProjectMap(apiContext *types.APIContext, refresh bool) (map[string]string, error) {
if refresh {
err := updateNamespaceOwnerMap(apiContext)
if err != nil {
return nil, err
}
}
data := map[string]string{}
for _, key := range namespaceOwnerMap.Keys() {
if val, ok := namespaceOwnerMap.Get(key); ok {
data[key.(string)] = val.(string)
}
}
return data, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha19

搜索帮助

0d507c66 1850385 C8b1a773 1850385