-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
87 lines (72 loc) · 2.47 KB
/
manager.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package manager
import (
"github.com/cloudwego/hertz/pkg/common/hlog"
k8sclient "lib/k8s-client"
"lib/k8s-client/manager/resource"
)
type K8SResourceManager interface {
}
var K8SManager *ResourceManager
type ResourceManager struct {
providers map[string]K8SResourceManager
}
// InitK8SManager 初始化 Kubernetes 资源管理器
func InitK8SManager(client *k8sclient.ClientManager) {
K8SManager = NewResourceManager()
// 初始化不同的 Kubernetes 资源管理器
jobManager := resource.NewJobManager(client)
deploymentManager := resource.NewDeploymentManager(client)
statefulSetManager := resource.NewStatefulSetManager(client)
cmManager := resource.NewConfigMapManager(client)
svcManager := resource.NewServiceManager(client)
// 注册 Kubernetes 资源管理器
K8SManager.RegisterManager(Job, jobManager)
K8SManager.RegisterManager(Deployment, deploymentManager)
K8SManager.RegisterManager(StatefulSet, statefulSetManager)
K8SManager.RegisterManager(ConfigMap, cmManager)
K8SManager.RegisterManager(Service, svcManager)
hlog.Debug("K8SManager 初始化成功,已注册 Job Deployment StatefulSet ConfigMap")
}
func NewResourceManager() *ResourceManager {
return &ResourceManager{
providers: make(map[string]K8SResourceManager),
}
}
func (rm *ResourceManager) RegisterManager(name string, provider K8SResourceManager) {
rm.providers[name] = provider
}
func (rm *ResourceManager) JobManager() *resource.JobManager {
if provider, ok := rm.providers[Job].(*resource.JobManager); ok {
return provider
}
hlog.Error("JobManager 未注册")
return nil
}
func (rm *ResourceManager) DeploymentManager() *resource.DeploymentManager {
if provider, ok := rm.providers[Deployment].(*resource.DeploymentManager); ok {
return provider
}
hlog.Error("DeploymentManager 未注册")
return nil
}
func (rm *ResourceManager) StatefulSetManager() *resource.StatefulSetManager {
if provider, ok := rm.providers[StatefulSet].(*resource.StatefulSetManager); ok {
return provider
}
hlog.Error("StatefulSetManager 未注册")
return nil
}
func (rm *ResourceManager) ConfigMapManager() *resource.ConfigMapManager {
if provider, ok := rm.providers[ConfigMap].(*resource.ConfigMapManager); ok {
return provider
}
hlog.Error("ConfigMapManager 未注册")
return nil
}
func (rm *ResourceManager) ServiceManager() *resource.ServiceManager {
if provider, ok := rm.providers[Service].(*resource.ServiceManager); ok {
return provider
}
hlog.Error("ServiceManager 未注册")
return nil
}