forked from tkestack/tke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
268 lines (225 loc) · 7.17 KB
/
types.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
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2019 Tencent. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the “License”); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://opensource.org/licenses/Apache-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package types
import (
"context"
"path"
"github.com/thoas/go-funk"
v1 "tkestack.io/tke/api/platform/v1"
)
type CreateClusterPara struct {
Cluster v1.Cluster `json:"cluster"`
Config Config `json:"Config"`
}
// Config is the installer config
type Config struct {
Basic *Basic `json:"basic"`
Auth Auth `json:"auth"`
Registry Registry `json:"registry"`
Business *Business `json:"business,omitempty"`
Monitor *Monitor `json:"monitor,omitempty"`
Logagent *Logagent `json:"logagent,omitempty"`
HA *HA `json:"ha,omitempty"`
Gateway *Gateway `json:"gateway,omitempty"`
Audit *Audit `json:"audit,omitempty"`
Application *Application `json:"application,omitempty"`
SkipSteps []string `json:"skipSteps,omitempty"`
}
type Basic struct {
Username string `json:"username"`
Password []byte `json:"password"`
}
type Auth struct {
TKEAuth *TKEAuth `json:"tke,omitempty"`
OIDCAuth *OIDCAuth `json:"oidc,omitempty"`
}
type TKEAuth struct {
TenantID string `json:"tenantID"`
Username string `json:"username"`
Password []byte `json:"password"`
}
type OIDCAuth struct {
IssuerURL string `json:"issuerURL" validate:"required"`
ClientID string `json:"clientID" validate:"required"`
CACert []byte `json:"caCert"`
}
// Registry for remote registry
type Registry struct {
TKERegistry *TKERegistry `json:"tke,omitempty"`
ThirdPartyRegistry *ThirdPartyRegistry `json:"thirdParty,omitempty"`
UserInputRegistry UserInputRegistry `json:"userInputRegistry,omitempty"`
}
type Audit struct {
ElasticSearch *ElasticSearch `json:"elasticSearch,omitempty"`
}
type ElasticSearch struct {
Address string `json:"address" validate:"required"`
ReserveDays int `json:"reserveDays" validate:"required"`
Username string `json:"username"`
Password string `json:"password"`
}
func (r *Registry) Domain() string {
if r.UserInputRegistry.Domain != "" {
return r.UserInputRegistry.Domain
}
if r.ThirdPartyRegistry != nil { // first use third party when both set
return r.ThirdPartyRegistry.Domain
}
return r.TKERegistry.Domain
}
func (r *Registry) Namespace() string {
if r.UserInputRegistry.Namespace != "" {
return r.UserInputRegistry.Namespace
}
if r.ThirdPartyRegistry != nil {
return r.ThirdPartyRegistry.Namespace
}
return r.TKERegistry.Namespace
}
func (r *Registry) Username() string {
if r.UserInputRegistry.Username != "" {
return r.UserInputRegistry.Username
}
if r.ThirdPartyRegistry != nil {
return r.ThirdPartyRegistry.Username
}
return r.TKERegistry.Username
}
func (r *Registry) Password() []byte {
if len(r.UserInputRegistry.Password) != 0 {
return r.UserInputRegistry.Password
}
if r.ThirdPartyRegistry != nil {
return r.ThirdPartyRegistry.Password
}
return r.TKERegistry.Password
}
func (r *Registry) Prefix() string {
return path.Join(r.Domain(), r.Namespace())
}
func (r *Registry) IsOfficial() bool {
return funk.ContainsString([]string{"docker.io/tkestack", "ccr.ccs.tencentyun.com/tkestack"}, r.Prefix())
}
type TKERegistry struct {
Domain string `json:"domain" validate:"hostname_rfc1123"`
HarborEnabled bool `json:"harborEnabled"`
HarborCAFile string `json:"harborCAFile"`
Namespace string `json:"namespace"`
Username string `json:"username"`
Password []byte `json:"password"`
}
type ThirdPartyRegistry struct {
Domain string `json:"domain" validate:"required"`
Namespace string `json:"namespace" validate:"required"`
Username string `json:"username"`
Password []byte `json:"password"`
}
type UserInputRegistry struct {
Domain string `json:"domain"`
Namespace string `json:"namespace"`
Username string `json:"username"`
Password []byte `json:"password"`
}
type Business struct {
}
type Application struct {
RegistryDomain string `json:"registryDomain" validate:"hostname_rfc1123"`
RegistryUsername string `json:"registryUsername"`
RegistryPassword []byte `json:"registryPassword"`
}
type Monitor struct {
ESMonitor *ESMonitor `json:"es,omitempty"`
InfluxDBMonitor *InfluxDBMonitor `json:"influxDB,omitempty"`
}
type ESMonitor struct {
URL string `json:"url" validate:"required"`
Username string `json:"username" validate:"required"`
Password []byte `json:"password" validate:"required"`
}
type InfluxDBMonitor struct {
LocalInfluxDBMonitor *LocalInfluxDBMonitor `json:"local,omitempty"`
ExternalInfluxDBMonitor *ExternalInfluxDBMonitor `json:"external,omitempty"`
}
type LocalInfluxDBMonitor struct {
}
type ExternalInfluxDBMonitor struct {
URL string `json:"url" validate:"required"`
Username string `json:"username" validate:"required"`
Password []byte `json:"password" validate:"required"`
}
type HA struct {
TKEHA *TKEHA `json:"tke,omitempty"`
ThirdPartyHA *ThirdPartyHA `json:"thirdParty,omitempty"`
}
func (ha *HA) VIP() string {
if ha.TKEHA != nil {
return ha.TKEHA.VIP
}
return ha.ThirdPartyHA.VIP
}
type TKEHA struct {
VIP string `json:"vip" validate:"required"`
}
type ThirdPartyHA struct {
VIP string `json:"vip" validate:"required"`
VPort int32 `json:"vport"`
}
type Gateway struct {
Domain string `json:"domain"`
Cert *Cert `json:"cert"`
}
type Cert struct {
SelfSignedCert *SelfSignedCert `json:"selfSigned,omitempty"`
ThirdPartyCert *ThirdPartyCert `json:"thirdParty,omitempty"`
}
type SelfSignedCert struct {
}
type ThirdPartyCert struct {
Certificate []byte `json:"certificate" validate:"required"`
PrivateKey []byte `json:"privateKey" validate:"required"`
}
type Keepalived struct {
VIP string `json:"vip,omitempty"`
}
type ClusterProgress struct {
Status ClusterProgressStatus `json:"status"`
Data string `json:"data"`
URL string `json:"url,omitempty"`
Username string `json:"username,omitempty"`
Password []byte `json:"password,omitempty"`
CACert []byte `json:"caCert,omitempty"`
Hosts []string `json:"hosts,omitempty"`
Servers []string `json:"servers,omitempty"`
Kubeconfig []byte `json:"kubeconfig,omitempty"`
}
type ClusterProgressStatus string
const (
StatusUnknown = "Unknown"
StatusDoing = "Doing"
StatusSuccess = "Success"
StatusFailed = "Failed"
StatusRetrying = "Retrying"
)
type Handler struct {
Name string
Func func(ctx context.Context) error
}
type Logagent struct {
RegistryDomain string `json:"domain,omitempty"`
RegistryNamespace string `json:"namespace:omitempty"`
}