-
Notifications
You must be signed in to change notification settings - Fork 53
/
opnicluster_meta.go
153 lines (138 loc) · 4.17 KB
/
opnicluster_meta.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package v1beta2
import (
opnimeta "github.com/rancher/opni/pkg/util/meta"
corev1 "k8s.io/api/core/v1"
)
type ServiceKind int
const (
InferenceService ServiceKind = iota
DrainService
PreprocessingService
PayloadReceiverService
GPUControllerService
MetricsService
)
type OpensearchRole string
const (
OpensearchDataRole OpensearchRole = "data"
OpensearchClientRole OpensearchRole = "client"
OpensearchMasterRole OpensearchRole = "master"
OpensearchDashboardsRole OpensearchRole = "kibana"
)
func (s ServiceKind) String() string {
switch s {
case InferenceService:
return "inference"
case DrainService:
return "drain"
case PreprocessingService:
return "preprocessing"
case PayloadReceiverService:
return "payload-receiver"
case GPUControllerService:
return "gpu-controller"
case MetricsService:
return "metrics"
default:
return ""
}
}
func (s ServiceKind) ServiceName() string {
return "opni-svc-" + s.String()
}
func (s ServiceKind) ImageName() string {
switch s {
case GPUControllerService:
return "opni-gpu-service-controller"
default:
return "opni-" + s.String() + "-service"
}
}
func (s ServiceKind) GetImageSpec(opniCluster *OpniCluster) *opnimeta.ImageSpec {
switch s {
case InferenceService:
return &opniCluster.Spec.Services.Inference.ImageSpec
case DrainService:
return &opniCluster.Spec.Services.Drain.ImageSpec
case PreprocessingService:
return &opniCluster.Spec.Services.Preprocessing.ImageSpec
case PayloadReceiverService:
return &opniCluster.Spec.Services.PayloadReceiver.ImageSpec
case GPUControllerService:
return &opniCluster.Spec.Services.GPUController.ImageSpec
case MetricsService:
return &opniCluster.Spec.Services.Metrics.ImageSpec
default:
return nil
}
}
func (s ServiceKind) GetNodeSelector(opniCluster *OpniCluster) map[string]string {
switch s {
case InferenceService:
return opniCluster.Spec.Services.Inference.NodeSelector
case DrainService:
return opniCluster.Spec.Services.Drain.NodeSelector
case PreprocessingService:
return opniCluster.Spec.Services.Preprocessing.NodeSelector
case PayloadReceiverService:
return opniCluster.Spec.Services.PayloadReceiver.NodeSelector
case GPUControllerService:
return opniCluster.Spec.Services.GPUController.NodeSelector
case MetricsService:
return opniCluster.Spec.Services.Metrics.NodeSelector
default:
return map[string]string{}
}
}
func (s ServiceKind) GetTolerations(opniCluster *OpniCluster) []corev1.Toleration {
switch s {
case InferenceService:
return opniCluster.Spec.Services.Inference.Tolerations
case DrainService:
return opniCluster.Spec.Services.Drain.Tolerations
case PreprocessingService:
return opniCluster.Spec.Services.Preprocessing.Tolerations
case PayloadReceiverService:
return opniCluster.Spec.Services.PayloadReceiver.Tolerations
case GPUControllerService:
return opniCluster.Spec.Services.GPUController.Tolerations
case MetricsService:
return opniCluster.Spec.Services.Metrics.Tolerations
default:
return []corev1.Toleration{}
}
}
func (e OpensearchRole) GetNodeSelector(opniCluster *OpniCluster) map[string]string {
switch e {
case OpensearchDataRole:
return opniCluster.Spec.Opensearch.Workloads.Data.NodeSelector
case OpensearchMasterRole:
return opniCluster.Spec.Opensearch.Workloads.Master.NodeSelector
case OpensearchClientRole:
return opniCluster.Spec.Opensearch.Workloads.Client.NodeSelector
case OpensearchDashboardsRole:
return opniCluster.Spec.Opensearch.Workloads.Dashboards.NodeSelector
default:
return map[string]string{}
}
}
func (e OpensearchRole) GetTolerations(opniCluster *OpniCluster) []corev1.Toleration {
switch e {
case OpensearchDataRole:
return opniCluster.Spec.Opensearch.Workloads.Data.Tolerations
case OpensearchMasterRole:
return opniCluster.Spec.Opensearch.Workloads.Master.Tolerations
case OpensearchClientRole:
return opniCluster.Spec.Opensearch.Workloads.Client.Tolerations
case OpensearchDashboardsRole:
return opniCluster.Spec.Opensearch.Workloads.Dashboards.Tolerations
default:
return []corev1.Toleration{}
}
}
func (c *OpniCluster) GetState() string {
return string(c.Status.State)
}
func (c *OpniCluster) GetConditions() []string {
return c.Status.Conditions
}