Skip to content

Commit d55cac2

Browse files
feat(k8s): add MigratePoolsToNewImages handler (scaleway#987)
Co-authored-by: Laure-di <[email protected]>
1 parent aca3dfb commit d55cac2

File tree

8 files changed

+218
-32
lines changed

8 files changed

+218
-32
lines changed

scaleway-async/scaleway_async/k8s/v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from .types import ListPoolsResponse
7676
from .types import ListVersionsRequest
7777
from .types import ListVersionsResponse
78+
from .types import MigratePoolsToNewImagesRequest
7879
from .types import NodeMetadata
7980
from .types import RebootNodeRequest
8081
from .types import ReplaceNodeRequest
@@ -164,6 +165,7 @@
164165
"ListPoolsResponse",
165166
"ListVersionsRequest",
166167
"ListVersionsResponse",
168+
"MigratePoolsToNewImagesRequest",
167169
"NodeMetadata",
168170
"RebootNodeRequest",
169171
"ReplaceNodeRequest",

scaleway-async/scaleway_async/k8s/v1/api.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
ListNodesResponse,
5151
ListPoolsResponse,
5252
ListVersionsResponse,
53+
MigratePoolsToNewImagesRequest,
5354
Node,
5455
NodeMetadata,
5556
Pool,
@@ -92,6 +93,7 @@
9293
marshal_AddClusterACLRulesRequest,
9394
marshal_CreateClusterRequest,
9495
marshal_CreatePoolRequest,
96+
marshal_MigratePoolsToNewImagesRequest,
9597
marshal_SetClusterACLRulesRequest,
9698
marshal_SetClusterTypeRequest,
9799
marshal_UpdateClusterRequest,
@@ -1334,6 +1336,48 @@ async def delete_pool(
13341336
self._throw_on_error(res)
13351337
return unmarshal_Pool(res.json())
13361338

1339+
async def migrate_pools_to_new_images(
1340+
self,
1341+
*,
1342+
cluster_id: str,
1343+
region: Optional[ScwRegion] = None,
1344+
pool_ids: Optional[List[str]] = None,
1345+
) -> None:
1346+
"""
1347+
Migrate specific pools or all pools of a cluster to new images.
1348+
If no pool is specified, all pools of the cluster will be migrated to new images.
1349+
:param cluster_id:
1350+
:param region: Region to target. If none is passed will use default region from the config.
1351+
:param pool_ids:
1352+
1353+
Usage:
1354+
::
1355+
1356+
result = await api.migrate_pools_to_new_images(
1357+
cluster_id="example",
1358+
)
1359+
"""
1360+
1361+
param_region = validate_path_param(
1362+
"region", region or self.client.default_region
1363+
)
1364+
param_cluster_id = validate_path_param("cluster_id", cluster_id)
1365+
1366+
res = self._request(
1367+
"POST",
1368+
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/migrate-pools-to-new-images",
1369+
body=marshal_MigratePoolsToNewImagesRequest(
1370+
MigratePoolsToNewImagesRequest(
1371+
cluster_id=cluster_id,
1372+
region=region,
1373+
pool_ids=pool_ids,
1374+
),
1375+
self.client,
1376+
),
1377+
)
1378+
1379+
self._throw_on_error(res)
1380+
13371381
async def get_node_metadata(
13381382
self,
13391383
*,

scaleway-async/scaleway_async/k8s/v1/marshalling.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
CreateClusterRequest,
4949
CreatePoolRequestUpgradePolicy,
5050
CreatePoolRequest,
51+
MigratePoolsToNewImagesRequest,
5152
SetClusterACLRulesRequest,
5253
SetClusterTypeRequest,
5354
UpdateClusterRequestAutoUpgrade,
@@ -120,6 +121,14 @@ def unmarshal_Pool(data: Any) -> Pool:
120121
if field is not None:
121122
args["size"] = field
122123

124+
field = data.get("min_size", None)
125+
if field is not None:
126+
args["min_size"] = field
127+
128+
field = data.get("max_size", None)
129+
if field is not None:
130+
args["max_size"] = field
131+
123132
field = data.get("created_at", None)
124133
if field is not None:
125134
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
@@ -132,14 +141,6 @@ def unmarshal_Pool(data: Any) -> Pool:
132141
else:
133142
args["updated_at"] = None
134143

135-
field = data.get("min_size", None)
136-
if field is not None:
137-
args["min_size"] = field
138-
139-
field = data.get("max_size", None)
140-
if field is not None:
141-
args["max_size"] = field
142-
143144
field = data.get("container_runtime", None)
144145
if field is not None:
145146
args["container_runtime"] = field
@@ -190,6 +191,12 @@ def unmarshal_Pool(data: Any) -> Pool:
190191
else:
191192
args["root_volume_size"] = None
192193

194+
field = data.get("new_images_enabled", None)
195+
if field is not None:
196+
args["new_images_enabled"] = field
197+
else:
198+
args["new_images_enabled"] = None
199+
193200
return Pool(**args)
194201

195202

@@ -498,6 +505,12 @@ def unmarshal_Cluster(data: Any) -> Cluster:
498505
else:
499506
args["acl_available"] = None
500507

508+
field = data.get("new_images_enabled", None)
509+
if field is not None:
510+
args["new_images_enabled"] = field
511+
else:
512+
args["new_images_enabled"] = None
513+
501514
return Cluster(**args)
502515

503516

@@ -1424,6 +1437,18 @@ def marshal_CreatePoolRequest(
14241437
return output
14251438

14261439

1440+
def marshal_MigratePoolsToNewImagesRequest(
1441+
request: MigratePoolsToNewImagesRequest,
1442+
defaults: ProfileDefaults,
1443+
) -> Dict[str, Any]:
1444+
output: Dict[str, Any] = {}
1445+
1446+
if request.pool_ids is not None:
1447+
output["pool_ids"] = request.pool_ids
1448+
1449+
return output
1450+
1451+
14271452
def marshal_SetClusterACLRulesRequest(
14281453
request: SetClusterACLRulesRequest,
14291454
defaults: ProfileDefaults,

scaleway-async/scaleway_async/k8s/v1/types.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,24 +375,24 @@ class Pool:
375375
Size (number of nodes) of the pool.
376376
"""
377377

378-
created_at: Optional[datetime]
378+
min_size: int
379379
"""
380-
Date on which the pool was created.
380+
Defines the minimum size of the pool. Note that this field is only used when autoscaling is enabled on the pool.
381381
"""
382382

383-
updated_at: Optional[datetime]
383+
max_size: int
384384
"""
385-
Date on which the pool was last updated.
385+
Defines the maximum size of the pool. Note that this field is only used when autoscaling is enabled on the pool.
386386
"""
387387

388-
min_size: int
388+
created_at: Optional[datetime]
389389
"""
390-
Defines the minimum size of the pool. Note that this field is only used when autoscaling is enabled on the pool.
390+
Date on which the pool was created.
391391
"""
392392

393-
max_size: int
393+
updated_at: Optional[datetime]
394394
"""
395-
Defines the maximum size of the pool. Note that this field is only used when autoscaling is enabled on the pool.
395+
Date on which the pool was last updated.
396396
"""
397397

398398
container_runtime: Runtime
@@ -453,6 +453,11 @@ class Pool:
453453
System volume disk size.
454454
"""
455455

456+
new_images_enabled: Optional[bool]
457+
"""
458+
Defines whether the pool is migrated to new images.
459+
"""
460+
456461

457462
@dataclass
458463
class ACLRuleRequest:
@@ -917,6 +922,11 @@ class Cluster:
917922
Defines whether ACL is available on the cluster.
918923
"""
919924

925+
new_images_enabled: Optional[bool]
926+
"""
927+
Defines whether all pools are migrated to new images.
928+
"""
929+
920930

921931
@dataclass
922932
class Node:
@@ -1819,6 +1829,18 @@ class ListVersionsResponse:
18191829
"""
18201830

18211831

1832+
@dataclass
1833+
class MigratePoolsToNewImagesRequest:
1834+
cluster_id: str
1835+
1836+
region: Optional[ScwRegion]
1837+
"""
1838+
Region to target. If none is passed will use default region from the config.
1839+
"""
1840+
1841+
pool_ids: Optional[List[str]]
1842+
1843+
18221844
@dataclass
18231845
class NodeMetadata:
18241846
id: str

scaleway/scaleway/k8s/v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from .types import ListPoolsResponse
7676
from .types import ListVersionsRequest
7777
from .types import ListVersionsResponse
78+
from .types import MigratePoolsToNewImagesRequest
7879
from .types import NodeMetadata
7980
from .types import RebootNodeRequest
8081
from .types import ReplaceNodeRequest
@@ -164,6 +165,7 @@
164165
"ListPoolsResponse",
165166
"ListVersionsRequest",
166167
"ListVersionsResponse",
168+
"MigratePoolsToNewImagesRequest",
167169
"NodeMetadata",
168170
"RebootNodeRequest",
169171
"ReplaceNodeRequest",

scaleway/scaleway/k8s/v1/api.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
ListNodesResponse,
5151
ListPoolsResponse,
5252
ListVersionsResponse,
53+
MigratePoolsToNewImagesRequest,
5354
Node,
5455
NodeMetadata,
5556
Pool,
@@ -92,6 +93,7 @@
9293
marshal_AddClusterACLRulesRequest,
9394
marshal_CreateClusterRequest,
9495
marshal_CreatePoolRequest,
96+
marshal_MigratePoolsToNewImagesRequest,
9597
marshal_SetClusterACLRulesRequest,
9698
marshal_SetClusterTypeRequest,
9799
marshal_UpdateClusterRequest,
@@ -1334,6 +1336,48 @@ def delete_pool(
13341336
self._throw_on_error(res)
13351337
return unmarshal_Pool(res.json())
13361338

1339+
def migrate_pools_to_new_images(
1340+
self,
1341+
*,
1342+
cluster_id: str,
1343+
region: Optional[ScwRegion] = None,
1344+
pool_ids: Optional[List[str]] = None,
1345+
) -> None:
1346+
"""
1347+
Migrate specific pools or all pools of a cluster to new images.
1348+
If no pool is specified, all pools of the cluster will be migrated to new images.
1349+
:param cluster_id:
1350+
:param region: Region to target. If none is passed will use default region from the config.
1351+
:param pool_ids:
1352+
1353+
Usage:
1354+
::
1355+
1356+
result = api.migrate_pools_to_new_images(
1357+
cluster_id="example",
1358+
)
1359+
"""
1360+
1361+
param_region = validate_path_param(
1362+
"region", region or self.client.default_region
1363+
)
1364+
param_cluster_id = validate_path_param("cluster_id", cluster_id)
1365+
1366+
res = self._request(
1367+
"POST",
1368+
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/migrate-pools-to-new-images",
1369+
body=marshal_MigratePoolsToNewImagesRequest(
1370+
MigratePoolsToNewImagesRequest(
1371+
cluster_id=cluster_id,
1372+
region=region,
1373+
pool_ids=pool_ids,
1374+
),
1375+
self.client,
1376+
),
1377+
)
1378+
1379+
self._throw_on_error(res)
1380+
13371381
def get_node_metadata(
13381382
self,
13391383
*,

0 commit comments

Comments
 (0)