-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
339 lines (297 loc) · 9.94 KB
/
results.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
package clusters
import (
"encoding/json"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/openstack/common/tags"
)
type ListCluster struct {
// API type, fixed value Cluster
Kind string `json:"kind"`
//API version, fixed value v3
ApiVersion string `json:"apiVersion"`
//all Clusters
Clusters []Clusters `json:"items"`
}
type Clusters struct {
// API type, fixed value Cluster
Kind string `json:"kind" required:"true"`
//API version, fixed value v3
ApiVersion string `json:"apiversion" required:"true"`
//Metadata of a Cluster
Metadata MetaData `json:"metadata" required:"true"`
//specifications of a Cluster
Spec Spec `json:"spec" required:"true"`
//status of a Cluster
Status Status `json:"status"`
}
// Metadata required to create a cluster
type MetaData struct {
//Cluster unique name
Name string `json:"name"`
//Cluster unique Id
Id string `json:"uid"`
// Cluster tag, key/value pair format
Labels map[string]string `json:"labels,omitempty"`
//Cluster annotation, key/value pair format
Annotations map[string]string `json:"annotations,omitempty"`
}
// Specifications to create a cluster
type Spec struct {
//Cluster Type: VirtualMachine, BareMetal, or Windows
Type string `json:"type" required:"true"`
// Cluster specifications
Flavor string `json:"flavor" required:"true"`
// For the cluster version, please fill in v1.7.3-r10 or v1.9.2-r1. Currently only Kubernetes 1.7 and 1.9 clusters are supported.
Version string `json:"version,omitempty"`
//Cluster description
Description string `json:"description,omitempty"`
//Public IP ID
PublicIP string `json:"publicip_id,omitempty"`
// Node network parameters
HostNetwork HostNetworkSpec `json:"hostNetwork" required:"true"`
//Container network parameters
ContainerNetwork ContainerNetworkSpec `json:"containerNetwork" required:"true"`
//ENI network parameters
EniNetwork *EniNetworkSpec `json:"eniNetwork,omitempty"`
// Enable Distributed Cluster Management
EnableDistMgt bool `json:"enableDistMgt,omitempty"`
//Authentication parameters
Authentication AuthenticationSpec `json:"authentication,omitempty"`
// Charging mode of the cluster, which is 0 (on demand)
BillingMode int `json:"billingMode,omitempty"`
//Extended parameter for a cluster
ExtendParam map[string]interface{} `json:"extendParam,omitempty"`
//Advanced configuration of master node
Masters []MasterSpec `json:"masters,omitempty"`
//Range of kubernetes clusterIp
KubernetesSvcIPRange string `json:"kubernetesSvcIpRange,omitempty"`
//Custom san list for certificates
CustomSan []string `json:"customSan,omitempty"`
// Tags of cluster, key value pair format
ClusterTags []tags.ResourceTag `json:"clusterTags,omitempty"`
}
// Node network parameters
type HostNetworkSpec struct {
//The ID of the VPC used to create the node
VpcId string `json:"vpc" required:"true"`
//The ID of the subnet used to create the node
SubnetId string `json:"subnet" required:"true"`
// The ID of the high speed network used to create bare metal nodes.
// This parameter is required when creating a bare metal cluster.
HighwaySubnet string `json:"highwaySubnet,omitempty"`
//The ID of the Security Group used to create the node
SecurityGroup string `json:"SecurityGroup,omitempty"`
}
// Container network parameters
type ContainerNetworkSpec struct {
//Container network type: overlay_l2 , underlay_ipvlan or vpc-router
Mode string `json:"mode" required:"true"`
//Container network segment: 172.16.0.0/16 ~ 172.31.0.0/16. If there is a network segment conflict, it will be automatically reselected.
Cidr string `json:"cidr,omitempty"`
// List of container CIDR blocks. In clusters of v1.21 and later, the cidrs field is used.
// When the cluster network type is vpc-router, you can add multiple container CIDR blocks.
// In versions earlier than v1.21, if the cidrs field is used, the first CIDR element in the array is used as the container CIDR block.
Cidrs []CidrSpec `json:"cidrs,omitempty"`
}
type CidrSpec struct {
// Container network segment. Recommended: 10.0.0.0/12-19, 172.16.0.0/16-19, and 192.168.0.0/16-19
Cidr string `json:"cidr" required:"true"`
}
type EniNetworkSpec struct {
//Eni network subnet id, will be deprecated in the future
SubnetId string `json:"eniSubnetId,omitempty"`
//Eni network cidr, will be deprecated in the future
Cidr string `json:"eniSubnetCIDR,omitempty"`
// Eni network subnet IDs
Subnets []EniSubnetSpec `json:"subnets" required:"true"`
}
type EniSubnetSpec struct {
SubnetID string `json:"subnetID" required:"true"`
}
// Authentication parameters
type AuthenticationSpec struct {
//Authentication mode: rbac , x509 or authenticating_proxy
Mode string `json:"mode" required:"true"`
AuthenticatingProxy map[string]string `json:"authenticatingProxy" required:"true"`
}
type MasterSpec struct {
// AZ of master node
MasterAZ string `json:"availabilityZone,omitempty"`
}
type Status struct {
//The state of the cluster
Phase string `json:"phase"`
//The ID of the Job that is operating asynchronously in the cluster
JobID string `json:"jobID"`
//Reasons for the cluster to become current
Reason string `json:"reason"`
//The status of each component in the cluster
Conditions Conditions `json:"conditions"`
//Kube-apiserver access address in the cluster
Endpoints []Endpoints `json:"-"`
}
type Conditions struct {
//The type of component
Type string `json:"type"`
//The state of the component
Status string `json:"status"`
//The reason that the component becomes current
Reason string `json:"reason"`
}
type Endpoints struct {
//The address accessed within the user's subnet - Huawei
Url string `json:"url"`
//Public network access address - Huawei
Type string `json:"type"`
//Internal network address - OTC
Internal string `json:"internal"`
//External network address - OTC
External string `json:"external"`
//Endpoint of the cluster to be accessed through API Gateway - OTC
ExternalOTC string `json:"external_otc"`
}
type Certificate struct {
//API type, fixed value Config
Kind string `json:"kind"`
//API version, fixed value v1
ApiVersion string `json:"apiVersion"`
//Cluster list
Clusters []CertClusters `json:"clusters"`
//User list
Users []CertUsers `json:"users"`
//Context list
Contexts []CertContexts `json:"contexts"`
//The current context
CurrentContext string `json:"current-context"`
}
type CertClusters struct {
//Cluster name
Name string `json:"name"`
//Cluster information
Cluster CertCluster `json:"cluster"`
}
type CertCluster struct {
//Server IP address
Server string `json:"server"`
//Certificate data
CertAuthorityData string `json:"certificate-authority-data"`
}
type CertUsers struct {
//User name
Name string `json:"name"`
//Cluster information
User CertUser `json:"user"`
}
type CertUser struct {
//Client certificate
ClientCertData string `json:"client-certificate-data"`
//Client key data
ClientKeyData string `json:"client-key-data"`
}
type CertContexts struct {
//Context name
Name string `json:"name"`
//Context information
Context CertContext `json:"context"`
}
type CertContext struct {
//Cluster name
Cluster string `json:"cluster"`
//User name
User string `json:"user"`
}
// UnmarshalJSON helps to unmarshal Status fields into needed values.
// OTC and Huawei have different data types and child fields for `endpoints` field in Cluster Status.
// This function handles the unmarshal for both
func (r *Status) UnmarshalJSON(b []byte) error {
type tmp Status
var s struct {
tmp
Endpoints []Endpoints `json:"endpoints"`
}
err := json.Unmarshal(b, &s)
if err != nil {
switch err.(type) {
case *json.UnmarshalTypeError: //check if type error occurred (handles the different endpoint structure for huawei and otc)
var s struct {
tmp
Endpoints Endpoints `json:"endpoints"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = Status(s.tmp)
r.Endpoints = []Endpoints{{Internal: s.Endpoints.Internal,
External: s.Endpoints.External,
ExternalOTC: s.Endpoints.ExternalOTC}}
return nil
default:
return err
}
}
*r = Status(s.tmp)
r.Endpoints = s.Endpoints
return err
}
type commonResult struct {
golangsdk.Result
}
// Extract is a function that accepts a result and extracts a cluster.
func (r commonResult) Extract() (*Clusters, error) {
var s Clusters
err := r.ExtractInto(&s)
return &s, err
}
// ExtractCluster is a function that accepts a ListOpts struct, which allows you to filter and sort
// the returned collection for greater efficiency.
func (r commonResult) ExtractClusters() ([]Clusters, error) {
var s ListCluster
err := r.ExtractInto(&s)
if err != nil {
return nil, err
}
return s.Clusters, nil
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Cluster.
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Cluster.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Cluster.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its ExtractErr
// method to determine if the request succeeded or failed.
type DeleteResult struct {
golangsdk.ErrResult
}
// ListResult represents the result of a list operation. Call its ExtractCluster
// method to interpret it as a Cluster.
type ListResult struct {
commonResult
}
type GetCertResult struct {
golangsdk.Result
}
// Extract is a function that accepts a result and extracts a cluster.
func (r GetCertResult) Extract() (*Certificate, error) {
var s Certificate
err := r.ExtractInto(&s)
return &s, err
}
// UpdateIpResult represents the result of an update operation. Call its Extract
// method to interpret it as a Cluster.
type UpdateIpResult struct {
golangsdk.ErrResult
}
type OperationResult struct {
golangsdk.ErrResult
}