-
Notifications
You must be signed in to change notification settings - Fork 71
/
cluster.go
346 lines (260 loc) · 12.6 KB
/
cluster.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// Copyright 2019 Baidu Inc. All rights reserved
// Use of this source code is governed by a CCE
// license that can be found in the LICENSE file.
/*
modification history
--------------------
2020/07/28 16:26:00, by jichao04@baidu.com, create
*/
package types
const (
// LatestSupportedK8SVersion latest K8S Version that we supported
LatestSupportedK8SVersion = "1.16.8"
// DefaultRuntime default runtime
DefaultRuntime = "docker"
// LatestSupportedDockerVersion default docker version
LatestSupportedDockerVersion = "18.09.2"
CCEPrefix = "cce-"
// ClusterIDLabelKey 关联 ClusterCRD 和 InstanceCRD 或 InstanceGroupCRD
ClusterIDLabelKey = "cluster-id"
ClusterRoleLabelKey = "cluster-role"
DoNotHandle = "not-handler-by-cce"
)
// 创建集群时使用的ClusterSpec
type ClusterSpec struct {
// 创建集群时无需传入ClusterID
ClusterID string `json:"clusterID,omitempty" validate:"readonly"`
// ClusterName 由用户指定
ClusterName string `json:"clusterName" valid:"Required" validate:"modifiable"`
ClusterType ClusterType `json:"clusterType,omitempty" valid:"Required" validate:"readonly"`
Description string `json:"description,omitempty" validate:"modifiable"`
K8SVersion K8SVersion `json:"k8sVersion,omitempty"`
RuntimeType RuntimeType `json:"runtimeType,omitempty"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
// VPCUUID && VPCCIDR 无需用户设置
VPCID string `json:"vpcID,omitempty" valid:"Required" validate:"readonly"`
VPCUUID string `json:"vpcUUID,omitempty" validate:"readonly"`
VPCCIDR string `json:"vpcCIDR,omitempty" validate:"readonly"`
VPCCIDRIPv6 string `json:"vpcCIDRIPv6,omitempty" validate:"readonly"`
// PluginListType CCE 插件类型
Plugins []string `json:"plugins,omitempty"`
// PluginsConfig 插件 Helm 安装配置
PluginsConfig map[string]PluginHelmConfig `json:"pluginsConfig,omitempty"`
MasterConfig MasterConfig `json:"masterConfig,omitempty" valid:"Required" validate:"inline"`
ContainerNetworkConfig ContainerNetworkConfig `json:"containerNetworkConfig,omitempty" valid:"Required" validate:"inline"`
// 集群删除保护标识,true 表示开启删除保护不允许删除集群;false 表示关闭删除保护允许删除集群
ForbidDelete bool `json:"forbidDelete"`
// IaaS资源付费选项
ResourceChargingOption ResourceChargingOption `json:"resourceChargingOption,omitempty" validate:"inline"`
// K8S 自定义配置
K8SCustomConfig K8SCustomConfig `json:"k8sCustomConfig,omitempty"`
// APIServer 认证模式
AuthenticateMode AuthenticateMode `json:"authenticateMode,omitempty" validate:"readonly"`
Tags []Tag `json:"tags,omitempty" validate:"readonly"`
}
// ResourceChargingOption 定义IaaS资源付费配置
type ResourceChargingOption struct {
ChargingType PaymentTiming `json:"chargingType,omitempty"` // 后付费或预付费
PurchaseTime int `json:"purchaseTime,omitempty"` // 预付费才生效:单位月,12 = 12 月
PurchaseTimeUnit string `json:"purchaseTimeUnit,omitempty"` // 预付费时间单位
AutoRenew bool `json:"autoRenew,omitempty"` // 是否自动续费
AutoRenewTime int `json:"autoRenewTime,omitempty"` // 12 = 12 个月
AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` // 续费单位:月
}
// PluginHelmConfig 使用 Helm 部署插件的插件的参数
type PluginHelmConfig struct {
// 插件类型(插件名称) 非必要 用户要部署的是哪个插件,传空时和PluginName保持一致
PluginType string `json:"pluginType,omitempty"`
// 插件别名 非必要 有时用户是可以自定义部署的插件名称的 (如多个 NGINX Ingress Controller 场景) 所以不能用PluginName来判断用户部署的是什么插件
PluginName string `json:"pluginName,omitempty"`
// 插件在云端的ChartName是什么 用户无需传递这个值
ChartName string `json:"chartName,omitempty"`
// 使用的Chart版本 除非用户要指定版本否则无需传递此值
ChartVersion string `json:"chartVersion,omitempty"`
// 插件部署到哪个命名空间 非必要
Namespaces string `json:"namespaces,omitempty"`
// 非必要
Description string `json:"description,omitempty"`
// 取决于插件 系统插件传空值即可
Values string `json:"values,omitempty"`
}
// K8SCustomConfig - K8S 自定义配置
type K8SCustomConfig struct {
MasterFeatureGates map[string]bool `json:"masterFeatureGates,omitempty"` // 自定义 FeatureGates
NodeFeatureGates map[string]bool `json:"nodeFeatureGates,omitempty"` // 自定义 FeatureGates
AdmissionPlugins []string `json:"admissionPlugins,omitempty"` // 自定义 AdmissionPlugins
PauseImage string `json:"pauseImage,omitempty"` // 自定义 PauseImage
KubeAPIQPS int `json:"kubeAPIQPS,omitempty"` // 自定义 KubeAPIQPS
KubeAPIBurst int `json:"kubeAPIBurst,omitempty"` // 自定义 KubeAPIBurst
SchedulerPredicates []string `json:"schedulerPredicates,omitempty"` // 自定义 SchedulerPredicates
SchedulerPriorities map[string]int `json:"schedulerPriorities,omitempty"` // 自定义 SchedulerPriorities
ETCDDataPath string `json:"etcdDataPath,omitempty"` // 自定义 etcd数据目录
}
// ClusterType usually used to init Provider
// and it represents the difference between IaaS
type ClusterType string
const (
// ClusterTypeNormal = 普通类型集群
ClusterTypeNormal ClusterType = "normal"
)
// K8SVersion defines the k8stypes version of cluster
type K8SVersion string
const (
// 1.6和1.8不再支持,扩缩容需要联系CCE人员手动操作
// K8S_1_6_2 K8SVersion = "1.6.2"
// K8S_1_8_6 K8SVersion = "1.8.6"
// K8S_1_8_12 K8SVersion = "1.8.12"
// 1.11.1 1.11.5 1.13.4仅支持已有集群扩容节点,不支持新创建集群
// K8S_1_11_1 K8SVersion = "1.11.1"
// K8S_1_11_5 K8SVersion = "1.11.5"
// K8S_1_13_4 K8SVersion = "1.13.4"
// 支持在console创建集群
// K8S_1_13_10 K8SVersion = "1.13.10"
// K8S_1_16_3 K8SVersion = "1.16.3"
// K8S_1_16_8 K8SVersion = "1.16.8"
// K8S_1_17_17 K8SVersion = "1.17.17"
K8S_1_18_9 K8SVersion = "1.18.9"
K8S_1_20_8 K8SVersion = "1.20.8"
K8S_1_21_14 K8SVersion = "1.21.14"
K8S_1_22_5 K8SVersion = "1.22.5"
K8S_1_24_4 K8SVersion = "1.24.4"
K8S_1_26_9 K8SVersion = "1.26.9"
)
// MasterConfig Master 配置
type MasterConfig struct {
// MasterTypes: 托管, 自定义, 已有 BCC, 已有 BBC
MasterType MasterType `json:"masterType,omitempty"`
// ClusterHA 对 3 种集群都有效: 对于 Custom 和 Existed 作为校验和展示作用
ClusterHA ClusterHA `json:"clusterHA,omitempty"`
ExposedPublic bool `json:"exposedPublic,omitempty"`
ClusterBLBVPCSubnetID string `json:"clusterBLBVPCSubnetID,omitempty"`
ManagedClusterMasterOption `json:"managedClusterMasterOption,omitempty"`
}
// ManagedClusterMasterOption 托管集群 Master 配置
type ManagedClusterMasterOption struct {
MasterVPCSubnetZone AvailableZone `json:"masterVPCSubnetZone,omitempty"`
}
// RuntimeType defines the runtime on each node
type RuntimeType string
const (
RuntimeTypeDocker RuntimeType = "docker"
RuntimeTypeContainerd RuntimeType = "containerd"
)
// ContainerNetworkConfig defines the network config
// Some attrs have default value
type ContainerNetworkConfig struct {
// CCE 支持网络类型: kubenet 及 vpc-cni
Mode ContainerNetworkMode `json:"mode,omitempty"` // If not set, set mode = kubenet
// ENI 网络模式子网
ENIVPCSubnetIDs map[AvailableZone][]string `json:"eniVPCSubnetIDs,omitempty"`
ENISecurityGroupID string `json:"eniSecurityGroupID,omitempty"`
// CCE 支持集群 IP version: dual stack, ipv4 only, ipv6 only
IPVersion ContainerNetworkIPType `json:"ipVersion,omitempty"` // if not set, set ipv4
// LB Service 关联 BLB 所在子网, 目前只能为普通子网
LBServiceVPCSubnetID string `json:"lbServiceVPCSubnetID,omitempty" valid:"Required"`
// 指定 NodePort Service 的端口范围
NodePortRangeMin int `json:"nodePortRangeMin,omitempty"`
NodePortRangeMax int `json:"nodePortRangeMax,omitempty"`
// 集群 PodIP CIDR, 在 kubenet 网络模式下有效
ClusterPodCIDR string `json:"clusterPodCIDR,omitempty"`
ClusterPodCIDRIPv6 string `json:"clusterPodCIDRIPv6,omitempty"`
// Service ClusterIP 的 CIDR
ClusterIPServiceCIDR string `json:"clusterIPServiceCIDR,omitempty"`
ClusterIPServiceCIDRIPv6 string `json:"clusterIPServiceCIDRIPv6,omitempty"`
// 每个 Node 上最大的 Pod 数, 限制 NodeCIDR 的分配
MaxPodsPerNode int `json:"maxPodsPerNode,omitempty"` // If not set, MaxPodsPerNode = 128
// KubeProxy 的模式: iptables 和 ipvs
KubeProxyMode KubeProxyMode `json:"kubeProxyMode,omitempty"` // If not set, kubeProxyMode=ipvs
}
// ContainerNetworkIPType - 容器 IP 类型
type ContainerNetworkIPType string
const (
// ContainerNetworkIPTypeIPv4 - 容器网段 IPv4
ContainerNetworkIPTypeIPv4 ContainerNetworkIPType = "ipv4"
// ContainerNetworkIPTypeIPv6 - 容器网段 IPv6
ContainerNetworkIPTypeIPv6 ContainerNetworkIPType = "ipv6"
// ContainerNetworkIPTypeDualStack - 容器网段双栈
ContainerNetworkIPTypeDualStack ContainerNetworkIPType = "dualStack"
)
// ContainerNetworkMode defines container config
type ContainerNetworkMode string
const (
// ContainerNetworkModeKubenet using kubenet
ContainerNetworkModeKubenet ContainerNetworkMode = "kubenet"
// ContainerNetworkModeVPCCNI using vpc-cni
ContainerNetworkModeVPCCNI ContainerNetworkMode = "vpc-cni"
// ContainerNetworkModeVPCRouteVeth using vpc route plus veth
ContainerNetworkModeVPCRouteVeth ContainerNetworkMode = "vpc-route-veth"
// ContainerNetworkModeVPCRouteIPVlan using vpc route plus ipvlan
ContainerNetworkModeVPCRouteIPVlan ContainerNetworkMode = "vpc-route-ipvlan"
// ContainerNetworkModeVPCRouteAutoDetect using vpc route and auto detects veth or ipvlan due to kernel version
ContainerNetworkModeVPCRouteAutoDetect ContainerNetworkMode = "vpc-route-auto-detect"
// ContainerNetworkModeVPCSecondaryIPVeth using vpc secondary ip plus veth
ContainerNetworkModeVPCSecondaryIPVeth ContainerNetworkMode = "vpc-secondary-ip-veth"
// ContainerNetworkModeVPCSecondaryIPIPVlan using vpc secondary ip plus ipvlan
ContainerNetworkModeVPCSecondaryIPIPVlan ContainerNetworkMode = "vpc-secondary-ip-ipvlan"
// ContainerNetworkModeVPCSecondaryIPAutoDetect using vpc secondary ip and auto detects veth or ipvlan due to kernel version
ContainerNetworkModeVPCSecondaryIPAutoDetect ContainerNetworkMode = "vpc-secondary-ip-auto-detect"
)
// KubeProxyMode defines kube-proxy --proxy-mode
// If not set, using KubeProxyModeIPVS as default
type KubeProxyMode string
const (
// KubeProxyModeIPVS --proxy-mode=ipvs
KubeProxyModeIPVS KubeProxyMode = "ipvs"
// KubeProxyModeIptables --proxy-mode=iptables
KubeProxyModeIptables KubeProxyMode = "iptables"
)
// MasterType 定义 Master 机器来源
type MasterType string
const (
// MasterTypeManaged 托管 Master
MasterTypeManaged MasterType = "managed"
// MasterTypeCustom 自定义集群, 包含:
// 1. 新建 BCC;
// 2. 已有 BCC;
// 3. 已有 BBC.
MasterTypeCustom MasterType = "custom"
// MasterTypeServerless Serverless集群Master
MasterTypeServerless MasterType = "serverless"
)
// ClusterHA Cluster Master 对应副本数
type ClusterHA int
const (
// ClusterHALow 单 Master
ClusterHALow ClusterHA = 1
// ClusterHAMedium 三 Master
ClusterHAMedium ClusterHA = 3
// ClusterHAHigh 五 Master
ClusterHAHigh ClusterHA = 5
// ClusterHAServerless Cluster Master 副本数
ClusterHAServerless ClusterHA = 2
)
// ClusterPhase for CCE K8S Cluster Phase
type ClusterPhase string
const (
// ClusterPhasePending 创建 Cluster 时默认状态
ClusterPhasePending ClusterPhase = "pending"
// ClusterPhaseProvisioning IaaS 相关资源正在创建中
ClusterPhaseProvisioning ClusterPhase = "provisioning"
// ClusterPhaseProvisioned IaaS 相关资源已经 Ready
ClusterPhaseProvisioned ClusterPhase = "provisioned"
// ClusterPhaseRunning 集群运行正常
ClusterPhaseRunning ClusterPhase = "running"
// ClusterPhaseCreateFailed 集群创建失败
ClusterPhaseCreateFailed ClusterPhase = "create_failed"
// ClusterPhaseDeleting 集群正在删除
ClusterPhaseDeleting ClusterPhase = "deleting"
// ClusterPhaseDeleted 集群删除完成
ClusterPhaseDeleted ClusterPhase = "deleted"
// ClusterPhaseDeleteFailed 集群删除失败
ClusterPhaseDeleteFailed ClusterPhase = "delete_failed"
)
// AuthenticateMode - 认证类型
type AuthenticateMode string
const (
// AuthenticateModeX509 - X509
AuthenticateModeX509 AuthenticateMode = "x509"
// AuthenticateModeOIDC - OIDC
AuthenticateModeOIDC AuthenticateMode = "oidc"
)