/
mongo_info.go
76 lines (59 loc) · 1.53 KB
/
mongo_info.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
package core
import (
corev1 "k8s.io/api/core/v1"
)
type mongoInfo int
var StaticMongoInfoUtil = new(mongoInfo)
func (*mongoInfo) GetRole(pod *corev1.Pod) string {
if pod == nil {
return ""
}
return pod.Labels[LabelKeyRole]
}
func (*mongoInfo) GetRsName(pod *corev1.Pod) string {
if pod == nil {
return ""
}
return pod.Labels[LabelKeyReplsetName]
}
func (*mongoInfo) GetRevisionHash(pod *corev1.Pod) string {
if pod == nil {
return ""
}
return pod.Labels[LabelKeyRevisionHash]
}
func (*mongoInfo) IsArbiter(pod *corev1.Pod) bool {
if pod == nil {
return false
}
return pod.Labels[LabelKeyArbiter] == LabelValTrue
}
func (*mongoInfo) IsExporter(pod *corev1.Pod) bool {
if pod == nil {
return false
}
return pod.Labels[LabelKeyRole] == LabelValExporter
}
func (*mongoInfo) IsNotNeedReConfig(pod *corev1.Pod) bool {
if pod == nil {
return false
}
// configSvr固定为3个,也不需要重新配置
// shardSvr现在没有创建用户,不支持重新配置
return pod.Labels[LabelKeyRole] == LabelValStandalone ||
pod.Labels[LabelKeyRole] == LabelValMongos ||
pod.Labels[LabelKeyRole] == LabelValConfigsvr ||
pod.Labels[LabelKeyRole] == LabelValShardsvr
}
func (*mongoInfo) IsExportPort(pod *corev1.Pod) bool {
if pod == nil {
return false
}
if StaticMongoInfoUtil.IsExporter(pod) {
return false
}
// 只有standalone、replSet、mongos需要export
return pod.Labels[LabelKeyRole] == LabelValStandalone ||
pod.Labels[LabelKeyRole] == LabelValReplset ||
pod.Labels[LabelKeyRole] == LabelValMongos
}