forked from ionos-enterprise/ionos-enterprise-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s.go
282 lines (228 loc) · 8.34 KB
/
k8s.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
package profitbricks
import "net/http"
type KubernetesClusters struct {
// URL to the collection representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// Unique representation for Kubernetes Cluster as a collection on a resource.
// Read Only: true
ID string `json:"id,omitempty"`
// Slice of items in that collection
// Read Only: true
Items []KubernetesCluster `json:"items"`
// The type of resource within a collection
// Read Only: true
// Enum: [collection]
PBType string `json:"type,omitempty"`
}
type KubernetesCluster struct {
// URL to the object representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// The resource's unique identifier.
// Read Only: true
ID string `json:"id,omitempty"`
// metadata
Metadata *Metadata `json:"metadata,omitempty"`
// properties
// Required: true
Properties *KubernetesClusterProperties `json:"properties"`
// The type of object
// Read Only: true
// Enum: [k8s]
PBType string `json:"type,omitempty"`
// Entities of a cluster
Entities KubernetesClusterEntities `json:"entities,omitempty"`
}
type UpdatedKubernetesCluster struct {
// URL to the object representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// The resource's unique identifier.
// Read Only: true
ID string `json:"id,omitempty"`
// metadata
Metadata *Metadata `json:"metadata,omitempty"`
// properties
// Required: true
Properties *KubernetesClusterProperties `json:"properties"`
// The type of object
// Read Only: true
// Enum: [k8s]
PBType string `json:"type,omitempty"`
// Entities of a cluster
Entities KubernetesClusterEntities `json:"-"`
}
type KubernetesClusterEntities struct {
// NodePools of a cluster
NodePools *KubernetesNodePools `json:"nodepools,omitempty"`
}
type MaintenanceWindow struct {
// The english name of the day of the week
// Required: false
DayOfTheWeek string `json:"dayOfTheWeek,omitempty"`
// A string of the following format: 08:00:00
// Required: false
Time string `json:"time,omitempty"`
}
type KubernetesClusterProperties struct {
// A Kubernetes Cluster Name. Valid Kubernetes Cluster name must be 63 characters or less and must not be empty
// and begin and end with an alphanumeric character ([a-z0-9]) with dashes (-), dots (.) and alphanumerics
// between.
// Required: true
Name string `json:"name"`
// The desired Kubernetes Version
// Please consult the API documentation for supported versions
// Required: false
K8sVersion string `json:"k8sVersion,omitempty"`
// The desired Maintanance Window
// Required: false
MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"`
}
type KubernetesConfig struct {
// URL to the object representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// The resource's unique identifier.
// Read Only: true
ID string `json:"id,omitempty"`
// properties
// Required: true
Properties KubernetesConfigProperties `json:"properties"`
// The type of object
// Read Only: true
// Enum: [kubeconfig]
PBType string `json:"type,omitempty"`
}
type KubernetesConfigProperties struct {
// A Kubernetes Config file data
KubeConfig string `json:"kubeconfig,omitempty"`
}
type KubernetesNodePool struct {
// URL to the object representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// The resource's unique identifier.
// Read Only: true
ID string `json:"id,omitempty"`
// metadata
Metadata *Metadata `json:"metadata,omitempty"`
// properties
// Required: true
Properties *KubernetesNodePoolProperties `json:"properties"`
// The type of object
// Read Only: true
// Enum: [nodepool]
PBType string `json:"type,omitempty"`
}
type KubernetesNodePoolProperties struct {
// The availability zone in which the servers should exist
// Required: true
// Enum: [AUTO ZONE_1 ZONE_2]
AvailabilityZone string `json:"availabilityZone,omitempty"`
// Number of cores for node
// Required: true
CoresCount uint32 `json:"coresCount,omitempty"`
// A valid cpu family name
// Required: true
CPUFamily string `json:"cpuFamily,omitempty"`
// The unique identifier of the data center where the worker nodes of the node pool will be provisioned.
// Required: true
DatacenterID string `json:"datacenterId,omitempty"`
// A Kubernetes Node Pool Name. Valid Kubernetes Node Pool name must be 63 characters or less and must not be
// empty or begin and end with an alphanumeric character ([a-z0-9]) with dashes (-), dots (.) and alphanumerics
// between.
// Required: true
Name string `json:"name,omitempty"`
// Number of nodes part of the Node Pool
// Required: true
NodeCount uint32 `json:"nodeCount,omitempty"`
// RAM size for node, minimum size 2048MB is recommended
// Required: true
RAMSize uint32 `json:"ramSize,omitempty"`
// The size of the volume in GB. The size should be greater than 10GB.
// Required: true
StorageSize uint32 `json:"storageSize,omitempty"`
// Hardware type of the volume
// Required: true
// Enum: [HDD SSD]
StorageType string `json:"storageType,omitempty"`
}
type KubernetesNodePools struct {
// URL to the collection representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// Unique representation for Kubernetes Node Pool as a collection on a resource.
// Read Only: true
ID string `json:"id,omitempty"`
// Slice of items in that collection
// Read Only: true
Items []KubernetesNodePool `json:"items"`
// The type of resource within a collection
// Read Only: true
// Enum: [nodepool]
Type string `json:"type,omitempty"`
}
// ListKubernetesClusters gets a list of all clusters
func (c *Client) ListKubernetesClusters() (*KubernetesClusters, error) {
rsp := &KubernetesClusters{}
return rsp, c.GetOK(kubernetesClustersPath(), rsp)
}
// GetKubernetesCluster gets cluster with given id
func (c *Client) GetKubernetesCluster(clusterID string) (*KubernetesCluster, error) {
rsp := &KubernetesCluster{}
return rsp, c.GetOK(kubernetesClusterPath(clusterID), rsp)
}
// CreateKubernetesCluster creates a cluster
func (c *Client) CreateKubernetesCluster(cluster KubernetesCluster) (*KubernetesCluster, error) {
rsp := &KubernetesCluster{}
return rsp, c.PostAcc(kubernetesClustersPath(), cluster, rsp)
}
// DeleteKubernetesCluster deletes cluster
func (c *Client) DeleteKubernetesCluster(clusterId string) (*http.Header, error) {
h := &http.Header{}
return h, c.Delete(kubernetesClusterPath(clusterId), h, http.StatusOK)
}
// UpdateKubernetesCluster updates cluster
func (c *Client) UpdateKubernetesCluster(clusterID string, cluster UpdatedKubernetesCluster) (*KubernetesCluster, error) {
rsp := &KubernetesCluster{}
return rsp, c.Put(kubernetesClusterPath(clusterID), cluster, rsp, http.StatusOK)
}
// GetKubeconfig returns the kubeconfig of cluster
func (c *Client) GetKubeconfig(clusterID string) (string, error) {
rsp := &KubernetesConfig{}
if err := c.GetOK(kubeConfigPath(clusterID), rsp); err != nil {
return "", err
}
return rsp.Properties.KubeConfig, nil
}
// GetKubernetesNodePools gets all node pools of cluster
func (c *Client) GetKubernetesNodePools(clusterID string) (*KubernetesNodePools, error) {
rsp := &KubernetesNodePools{}
return rsp, c.GetOK(kubernetesNodePoolsPath(clusterID), rsp)
}
// CreateKubernetesNodePool creates a new node pool for cluster
func (c *Client) CreateKubernetesNodePool(clusterID string, nodePool KubernetesNodePool) (*KubernetesNodePool, error) {
rsp := &KubernetesNodePool{}
return rsp, c.PostAcc(kubernetesNodePoolsPath(clusterID), nodePool, rsp)
}
// DeleteKubernetesNodePool deletes node pool from cluster
func (c *Client) DeleteKubernetesNodePool(clusterID, nodePoolID string) (*http.Header, error) {
return c.DeleteAcc(kubernetesNodePoolPath(clusterID, nodePoolID))
}
// GetKubernetesNodePool gets node pool of the cluster
func (c *Client) GetKubernetesNodePool(clusterID, nodePoolID string) (*KubernetesNodePool, error) {
rsp := &KubernetesNodePool{}
return rsp, c.GetOK(kubernetesNodePoolPath(clusterID, nodePoolID), rsp)
}
// Update KubernetesNodePool updates node pool
func (c *Client) UpdateKubernetesNodePool(clusterID, nodePoolID string, nodePool KubernetesNodePool) (*KubernetesNodePool, error) {
rsp := &KubernetesNodePool{}
return rsp, c.PutAcc(kubernetesNodePoolPath(clusterID, nodePoolID), nodePool, rsp)
}