1
+ ##################
2
+ # Waiting for scaleway merge fix https://github.com/scaleway/ansible/pull/47
3
+ ##################
4
+
5
+
1
6
#!/usr/bin/python
2
7
# -*- coding: utf-8 -*-
3
8
# Copyright: (c) 2023, Scaleway
25
30
state:
26
31
description:
27
32
- Indicate desired state of the target.
28
- - C(present) will create the resource.
33
+ - C(present) will create the resource, or update if 'pool_id' is present
29
34
- C(absent) will delete the resource, if it exists.
30
35
default: present
31
36
choices: ["present", "absent"]
137
142
autohealing: true
138
143
root_volume_type: "aaaaaa"
139
144
public_ip_disabled: true
145
+
146
+ - name: Update a pool
147
+ scaleway.scaleway.scaleway_k8s_pool:
148
+ access_key: "{{ scw_access_key }}"
149
+ secret_key: "{{ scw_secret_key }}"
150
+ cluster_id: "aaaaaa"
151
+ pool_id: "my_pool"
152
+ size: 3
140
153
"""
141
154
142
155
RETURN = r"""
201
214
def create (module : AnsibleModule , client : "Client" ) -> None :
202
215
api = K8SV1API (client )
203
216
204
- id = module .params .pop ("id" , None )
217
+ obj = lambda : None
218
+ obj .stop = None
219
+ obj .timeout = 600
220
+ obj .min_delay = 1
221
+ obj .max_delay = 30
222
+
223
+ id = module .params ["pool_id" ]
205
224
if id is not None :
206
- resource = api .get_pool (pool_id = id )
225
+ resource = api .get_pool (pool_id = id , region = module . params [ "region" ] )
207
226
208
227
if module .check_mode :
209
228
module .exit_json (changed = False )
210
229
211
- module .exit_json (changed = False , data = resource )
230
+ not_none_params = {
231
+ key : value for key , value in module .params .items () if value is not None
232
+ }
233
+ not_none_params .pop ("cluster_id" )
234
+ resource = api .update_pool (** not_none_params )
235
+ resource = api .wait_for_pool (pool_id = resource .id , options = obj , region = module .params ["region" ])
236
+
237
+ del resource .upgrade_policy
238
+ module .exit_json (changed = True , data = vars (resource ))
212
239
213
240
if module .check_mode :
214
241
module .exit_json (changed = True )
@@ -217,15 +244,16 @@ def create(module: AnsibleModule, client: "Client") -> None:
217
244
key : value for key , value in module .params .items () if value is not None
218
245
}
219
246
resource = api .create_pool (** not_none_params )
220
- resource = api .wait_for_pool (pool_id = resource .id , region = module .params ["region" ])
247
+ resource = api .wait_for_pool (pool_id = resource .id , options = obj , region = module .params ["region" ])
221
248
222
- module .exit_json (changed = True , data = resource .__dict__ )
249
+ del resource .upgrade_policy
250
+ module .exit_json (changed = True , data = vars (resource ))
223
251
224
252
225
253
def delete (module : AnsibleModule , client : "Client" ) -> None :
226
254
api = K8SV1API (client )
227
255
228
- id = module .params .pop ("id " , None )
256
+ id = module .params .pop ("pool_id " , None )
229
257
name = module .params .pop ("name" , None )
230
258
231
259
if id is not None :
@@ -276,35 +304,35 @@ def main() -> None:
276
304
argument_spec .update (scaleway_waitable_resource_argument_spec ())
277
305
argument_spec .update (
278
306
state = dict (type = "str" , default = "present" , choices = ["absent" , "present" ]),
279
- pool_id = dict (type = "str" ),
307
+ pool_id = dict (type = "str" , default = None ),
280
308
cluster_id = dict (
281
309
type = "str" ,
282
310
required = True ,
283
311
),
284
312
node_type = dict (
285
313
type = "str" ,
286
- required = True ,
314
+ required = False ,
287
315
),
288
316
autoscaling = dict (
289
317
type = "bool" ,
290
- required = True ,
318
+ required = False ,
291
319
),
292
320
size = dict (
293
321
type = "int" ,
294
- required = True ,
322
+ required = False ,
295
323
),
296
324
container_runtime = dict (
297
325
type = "str" ,
298
- required = True ,
326
+ required = False ,
299
327
choices = ["unknown_runtime" , "docker" , "containerd" , "crio" ],
300
328
),
301
329
autohealing = dict (
302
330
type = "bool" ,
303
- required = True ,
331
+ required = False ,
304
332
),
305
333
root_volume_type = dict (
306
334
type = "str" ,
307
- required = True ,
335
+ required = False ,
308
336
choices = ["default_volume_type" , "l_ssd" , "b_ssd" , "sbs_5k" , "sbs_15k" ],
309
337
),
310
338
region = dict (
@@ -351,13 +379,16 @@ def main() -> None:
351
379
),
352
380
public_ip_disabled = dict (
353
381
type = "bool" ,
354
- required = True ,
382
+ required = False ,
355
383
),
356
384
)
357
385
358
386
module = AnsibleModule (
359
387
argument_spec = argument_spec ,
360
388
required_one_of = (["pool_id" , "name" ],),
389
+ required_by = {
390
+ 'name' : ('node_type' ,'root_volume_type' ,'autohealing' ,'container_runtime' ,'size' ,'autoscaling' ,'public_ip_disabled' ,),
391
+ },
361
392
supports_check_mode = True ,
362
393
)
363
394
0 commit comments