-
Notifications
You must be signed in to change notification settings - Fork 83
/
lke_node_pools.go
202 lines (167 loc) · 6.48 KB
/
lke_node_pools.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
package linodego
import (
"context"
)
// LKELinodeStatus constants start with LKELinode and include
// Linode API LKENodePool Linode Status values
type LKELinodeStatus string
// LKENodePoolStatus constants reflect the current status of an LKENodePool
const (
LKELinodeReady LKELinodeStatus = "ready"
LKELinodeNotReady LKELinodeStatus = "not_ready"
)
// LKENodePoolDisk represents a Node disk in an LKENodePool object
type LKENodePoolDisk struct {
Size int `json:"size"`
Type string `json:"type"`
}
type LKENodePoolAutoscaler struct {
Enabled bool `json:"enabled"`
Min int `json:"min"`
Max int `json:"max"`
}
// LKENodePoolLinode represents a LKENodePoolLinode object
type LKENodePoolLinode struct {
ID string `json:"id"`
InstanceID int `json:"instance_id"`
Status LKELinodeStatus `json:"status"`
}
// LKENodePoolTaintEffect represents the effect value of a taint
type LKENodePoolTaintEffect string
const (
LKENodePoolTaintEffectNoSchedule LKENodePoolTaintEffect = "NoSchedule"
LKENodePoolTaintEffectPreferNoSchedule LKENodePoolTaintEffect = "PreferNoSchedule"
LKENodePoolTaintEffectNoExecute LKENodePoolTaintEffect = "NoExecute"
)
// LKENodePoolTaint represents a corev1.Taint to add to an LKENodePool
type LKENodePoolTaint struct {
Key string `json:"key"`
Value string `json:"value,omitempty"`
Effect LKENodePoolTaintEffect `json:"effect"`
}
// LKENodePoolLabels represents Kubernetes labels to add to an LKENodePool
type LKENodePoolLabels map[string]string
// LKENodePool represents a LKENodePool object
type LKENodePool struct {
ID int `json:"id"`
Count int `json:"count"`
Type string `json:"type"`
Disks []LKENodePoolDisk `json:"disks"`
Linodes []LKENodePoolLinode `json:"nodes"`
Tags []string `json:"tags"`
Labels LKENodePoolLabels `json:"labels"`
Taints []LKENodePoolTaint `json:"taints"`
Autoscaler LKENodePoolAutoscaler `json:"autoscaler"`
// NOTE: Disk encryption may not currently be available to all users.
DiskEncryption InstanceDiskEncryption `json:"disk_encryption,omitempty"`
}
// LKENodePoolCreateOptions fields are those accepted by CreateLKENodePool
type LKENodePoolCreateOptions struct {
Count int `json:"count"`
Type string `json:"type"`
Disks []LKENodePoolDisk `json:"disks"`
Tags []string `json:"tags"`
Labels LKENodePoolLabels `json:"labels"`
Taints []LKENodePoolTaint `json:"taints"`
Autoscaler *LKENodePoolAutoscaler `json:"autoscaler,omitempty"`
}
// LKENodePoolUpdateOptions fields are those accepted by UpdateLKENodePoolUpdate
type LKENodePoolUpdateOptions struct {
Count int `json:"count,omitempty"`
Tags *[]string `json:"tags,omitempty"`
Labels *LKENodePoolLabels `json:"labels,omitempty"`
Taints *[]LKENodePoolTaint `json:"taints,omitempty"`
Autoscaler *LKENodePoolAutoscaler `json:"autoscaler,omitempty"`
}
// GetCreateOptions converts a LKENodePool to LKENodePoolCreateOptions for
// use in CreateLKENodePool
func (l LKENodePool) GetCreateOptions() (o LKENodePoolCreateOptions) {
o.Count = l.Count
o.Disks = l.Disks
o.Tags = l.Tags
o.Labels = l.Labels
o.Taints = l.Taints
o.Autoscaler = &l.Autoscaler
return
}
// GetUpdateOptions converts a LKENodePool to LKENodePoolUpdateOptions for use in UpdateLKENodePoolUpdate
func (l LKENodePool) GetUpdateOptions() (o LKENodePoolUpdateOptions) {
o.Count = l.Count
o.Tags = &l.Tags
o.Labels = &l.Labels
o.Taints = &l.Taints
o.Autoscaler = &l.Autoscaler
return
}
// ListLKENodePools lists LKENodePools
func (c *Client) ListLKENodePools(ctx context.Context, clusterID int, opts *ListOptions) ([]LKENodePool, error) {
response, err := getPaginatedResults[LKENodePool](ctx, c, formatAPIPath("lke/clusters/%d/pools", clusterID), opts)
if err != nil {
return nil, err
}
return response, nil
}
// GetLKENodePool gets the LKENodePool with the provided ID
func (c *Client) GetLKENodePool(ctx context.Context, clusterID, poolID int) (*LKENodePool, error) {
e := formatAPIPath("lke/clusters/%d/pools/%d", clusterID, poolID)
response, err := doGETRequest[LKENodePool](ctx, c, e)
if err != nil {
return nil, err
}
return response, nil
}
// CreateLKENodePool creates a LKENodePool
func (c *Client) CreateLKENodePool(ctx context.Context, clusterID int, opts LKENodePoolCreateOptions) (*LKENodePool, error) {
e := formatAPIPath("lke/clusters/%d/pools", clusterID)
response, err := doPOSTRequest[LKENodePool](ctx, c, e, opts)
if err != nil {
return nil, err
}
return response, nil
}
// RecycleLKENodePool recycles a LKENodePool
func (c *Client) RecycleLKENodePool(ctx context.Context, clusterID, poolID int) error {
e := formatAPIPath("lke/clusters/%d/pools/%d/recycle", clusterID, poolID)
_, err := doPOSTRequest[LKENodePool, any](ctx, c, e)
if err != nil {
return err
}
return nil
}
// UpdateLKENodePool updates the LKENodePool with the specified id
func (c *Client) UpdateLKENodePool(ctx context.Context, clusterID, poolID int, opts LKENodePoolUpdateOptions) (*LKENodePool, error) {
e := formatAPIPath("lke/clusters/%d/pools/%d", clusterID, poolID)
response, err := doPUTRequest[LKENodePool](ctx, c, e, opts)
if err != nil {
return nil, err
}
return response, nil
}
// DeleteLKENodePool deletes the LKENodePool with the specified id
func (c *Client) DeleteLKENodePool(ctx context.Context, clusterID, poolID int) error {
e := formatAPIPath("lke/clusters/%d/pools/%d", clusterID, poolID)
return doDELETERequest(ctx, c, e)
}
// GetLKENodePoolNode gets the LKENodePoolLinode with the provided ID
func (c *Client) GetLKENodePoolNode(ctx context.Context, clusterID int, nodeID string) (*LKENodePoolLinode, error) {
e := formatAPIPath("lke/clusters/%d/nodes/%s", clusterID, nodeID)
response, err := doGETRequest[LKENodePoolLinode](ctx, c, e)
if err != nil {
return nil, err
}
return response, nil
}
// RecycleLKENodePoolNode recycles a LKENodePoolLinode
func (c *Client) RecycleLKENodePoolNode(ctx context.Context, clusterID int, nodeID string) error {
e := formatAPIPath("lke/clusters/%d/nodes/%s/recycle", clusterID, nodeID)
_, err := doPOSTRequest[LKENodePoolLinode, any](ctx, c, e)
if err != nil {
return err
}
return nil
}
// DeleteLKENodePoolNode deletes a given node from a node pool
func (c *Client) DeleteLKENodePoolNode(ctx context.Context, clusterID int, nodeID string) error {
e := formatAPIPath("lke/clusters/%d/nodes/%s", clusterID, nodeID)
return doDELETERequest(ctx, c, e)
}