3 Star 0 Fork 0

neuro-netw0rk/server-golib

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
clustersets.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
wangxianyu 提交于 2023-07-10 14:18 +08:00 . init project
package k8s
import (
"sync"
)
var clusterSets IClusterSet
func GetClusterSets() IClusterSet {
return clusterSets
}
type IClusterSet interface {
Add(clusterName string, clientSets *ClientSets)
Update(clusterName string, clientSets *ClientSets)
Delete(clusterName string)
Get(clusterName string) *ClientSets
List() map[string]*ClientSets
}
var _ IClusterSet = (*ClusterSet)(nil)
func NewClusterSet() {
clusterSets = &ClusterSet{clientSets: map[string]*ClientSets{}}
}
type ClusterSet struct {
lock sync.RWMutex
clientSets map[string]*ClientSets
}
func (c *ClusterSet) Add(clusterName string, clientSets *ClientSets) {
c.lock.Lock()
defer c.lock.Unlock()
c.clientSets[clusterName] = clientSets
}
func (c *ClusterSet) Update(clusterName string, clientSets *ClientSets) {
c.lock.Lock()
defer c.lock.Unlock()
c.clientSets[clusterName] = clientSets
}
func (c *ClusterSet) Delete(clusterName string) {
c.lock.Lock()
defer c.lock.Unlock()
if _, ok := c.clientSets[clusterName]; ok {
delete(c.clientSets, clusterName)
}
}
func (c *ClusterSet) Get(clusterName string) *ClientSets {
c.lock.Lock()
defer c.lock.Unlock()
item, exists := c.clientSets[clusterName]
if !exists {
return &ClientSets{
K8sClient: nil,
MetricsClient: nil,
InformerClient: nil,
}
}
return item
}
func (c *ClusterSet) List() map[string]*ClientSets {
c.lock.Lock()
defer c.lock.Unlock()
return c.clientSets
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/neuro-netw0rk/server-golib.git
git@gitee.com:neuro-netw0rk/server-golib.git
neuro-netw0rk
server-golib
server-golib
v0.0.5-beta2

搜索帮助