Skip to content

Commit 7ef50d8

Browse files
authored
feat(k8s): add pools labels, taints and startup_taints (scaleway#1565)
1 parent 077736a commit 7ef50d8

File tree

6 files changed

+376
-112
lines changed

6 files changed

+376
-112
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,41 +1040,44 @@ async def list_pools_all(
10401040
async def create_pool(
10411041
self,
10421042
*,
1043-
region: Optional[ScwRegion] = None,
10441043
cluster_id: str,
10451044
node_type: str,
10461045
autoscaling: bool,
10471046
size: int,
1047+
region: Optional[ScwRegion] = None,
10481048
name: Optional[str] = None,
10491049
placement_group_id: Optional[str] = None,
10501050
min_size: Optional[int] = None,
1051-
autohealing: bool,
1052-
public_ip_disabled: bool,
10531051
max_size: Optional[int] = None,
10541052
container_runtime: Optional[Runtime] = None,
1053+
autohealing: bool,
1054+
public_ip_disabled: bool,
10551055
tags: Optional[list[str]] = None,
10561056
kubelet_args: Optional[dict[str, str]] = None,
10571057
upgrade_policy: Optional[CreatePoolRequestUpgradePolicy] = None,
10581058
zone: Optional[ScwZone] = None,
10591059
root_volume_type: Optional[PoolVolumeType] = None,
10601060
root_volume_size: Optional[int] = None,
10611061
security_group_id: Optional[str] = None,
1062+
labels: Optional[dict[str, str]] = None,
1063+
taints: Optional[list[CoreV1Taint]] = None,
1064+
startup_taints: Optional[list[CoreV1Taint]] = None,
10621065
) -> Pool:
10631066
"""
10641067
Create a new Pool in a Cluster.
10651068
Create a new pool in a specific Kubernetes cluster.
1066-
:param region: Region to target. If none is passed will use default region from the config.
10671069
:param cluster_id: Cluster ID to which the pool will be attached.
10681070
:param node_type: Node type is the type of Scaleway Instance wanted for the pool. Nodes with insufficient memory are not eligible (DEV1-S, PLAY2-PICO, STARDUST). 'external' is a special node type used to provision instances from other cloud providers in a Kosmos Cluster.
10691071
:param autoscaling: Defines whether the autoscaling feature is enabled for the pool.
10701072
:param size: Size (number of nodes) of the pool.
1073+
:param region: Region to target. If none is passed will use default region from the config.
10711074
:param name: Pool name.
10721075
:param placement_group_id: Placement group ID in which all the nodes of the pool will be created, placement groups are limited to 20 instances.
10731076
:param min_size: Defines the minimum size of the pool. Note that this field is only used when autoscaling is enabled on the pool.
1074-
:param autohealing: Defines whether the autohealing feature is enabled for the pool.
1075-
:param public_ip_disabled: Defines if the public IP should be removed from Nodes. To use this feature, your Cluster must have an attached Private Network set up with a Public Gateway.
10761077
:param max_size: Defines the maximum size of the pool. Note that this field is only used when autoscaling is enabled on the pool.
10771078
:param container_runtime: Customization of the container runtime is available for each pool.
1079+
:param autohealing: Defines whether the autohealing feature is enabled for the pool.
1080+
:param public_ip_disabled: Defines if the public IP should be removed from Nodes. To use this feature, your Cluster must have an attached Private Network set up with a Public Gateway.
10781081
:param tags: Tags associated with the pool, see [managing tags](https://www.scaleway.com/en/docs/kubernetes/api-cli/managing-tags).
10791082
:param kubelet_args: Kubelet arguments to be used by this pool. Note that this feature is experimental.
10801083
:param upgrade_policy: Pool upgrade policy.
@@ -1085,6 +1088,9 @@ async def create_pool(
10851088
* `b_ssd` is the legacy remote block storage which means your system is stored on a centralized and resilient cluster. Not available for new pools, use `sbs_5k` or `sbs_15k` instead.
10861089
:param root_volume_size: System volume disk size.
10871090
:param security_group_id: Security group ID in which all the nodes of the pool will be created. If unset, the pool will use default Kapsule security group in current zone.
1091+
:param labels: Kubernetes labels applied and reconciled on the nodes.
1092+
:param taints: Kubernetes taints applied and reconciled on the nodes.
1093+
:param startup_taints: Kubernetes taints applied at node creation but not reconciled afterwards.
10881094
:return: :class:`Pool <Pool>`
10891095
10901096
Usage:
@@ -1129,6 +1135,9 @@ async def create_pool(
11291135
root_volume_type=root_volume_type,
11301136
root_volume_size=root_volume_size,
11311137
security_group_id=security_group_id,
1138+
labels=labels,
1139+
taints=taints,
1140+
startup_taints=startup_taints,
11321141
),
11331142
self.client,
11341143
),

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

Lines changed: 118 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ClusterStatus,
1717
ClusterTypeAvailability,
1818
ClusterTypeResiliency,
19+
CoreV1TaintEffect,
1920
MaintenanceWindowDayOfTheWeek,
2021
NodeStatus,
2122
PoolStatus,
@@ -28,6 +29,7 @@
2829
ClusterOpenIDConnectConfig,
2930
Cluster,
3031
Node,
32+
CoreV1Taint,
3133
PoolUpgradePolicy,
3234
Pool,
3335
ACLRule,
@@ -60,7 +62,6 @@
6062
SetClusterACLRulesRequest,
6163
SetClusterTypeRequest,
6264
SetPoolLabelsRequest,
63-
CoreV1Taint,
6465
SetPoolStartupTaintsRequest,
6566
SetPoolTaintsRequest,
6667
UpdateClusterRequestAutoUpgrade,
@@ -469,6 +470,12 @@ def unmarshal_Cluster(data: Any) -> Cluster:
469470
else:
470471
args["apiserver_cert_sans"] = []
471472

473+
field = data.get("acl_available", None)
474+
if field is not None:
475+
args["acl_available"] = field
476+
else:
477+
args["acl_available"] = False
478+
472479
field = data.get("iam_nodes_group_id", None)
473480
if field is not None:
474481
args["iam_nodes_group_id"] = field
@@ -507,12 +514,6 @@ def unmarshal_Cluster(data: Any) -> Cluster:
507514
else:
508515
args["commitment_ends_at"] = None
509516

510-
field = data.get("acl_available", None)
511-
if field is not None:
512-
args["acl_available"] = field
513-
else:
514-
args["acl_available"] = False
515-
516517
return Cluster(**args)
517518

518519

@@ -560,6 +561,12 @@ def unmarshal_Node(data: Any) -> Node:
560561
else:
561562
args["name"] = None
562563

564+
field = data.get("conditions", None)
565+
if field is not None:
566+
args["conditions"] = field
567+
else:
568+
args["conditions"] = {}
569+
563570
field = data.get("public_ip_v4", None)
564571
if field is not None:
565572
args["public_ip_v4"] = field
@@ -572,12 +579,6 @@ def unmarshal_Node(data: Any) -> Node:
572579
else:
573580
args["public_ip_v6"] = None
574581

575-
field = data.get("conditions", None)
576-
if field is not None:
577-
args["conditions"] = field
578-
else:
579-
args["conditions"] = {}
580-
581582
field = data.get("status", None)
582583
if field is not None:
583584
args["status"] = field
@@ -605,6 +606,35 @@ def unmarshal_Node(data: Any) -> Node:
605606
return Node(**args)
606607

607608

609+
def unmarshal_CoreV1Taint(data: Any) -> CoreV1Taint:
610+
if not isinstance(data, dict):
611+
raise TypeError(
612+
"Unmarshalling the type 'CoreV1Taint' failed as data isn't a dictionary."
613+
)
614+
615+
args: dict[str, Any] = {}
616+
617+
field = data.get("key", None)
618+
if field is not None:
619+
args["key"] = field
620+
else:
621+
args["key"] = None
622+
623+
field = data.get("value", None)
624+
if field is not None:
625+
args["value"] = field
626+
else:
627+
args["value"] = None
628+
629+
field = data.get("effect", None)
630+
if field is not None:
631+
args["effect"] = field
632+
else:
633+
args["effect"] = CoreV1TaintEffect.NO_SCHEDULE
634+
635+
return CoreV1Taint(**args)
636+
637+
608638
def unmarshal_PoolUpgradePolicy(data: Any) -> PoolUpgradePolicy:
609639
if not isinstance(data, dict):
610640
raise TypeError(
@@ -738,6 +768,18 @@ def unmarshal_Pool(data: Any) -> Pool:
738768
else:
739769
args["zone"] = None
740770

771+
field = data.get("placement_group_id", None)
772+
if field is not None:
773+
args["placement_group_id"] = field
774+
else:
775+
args["placement_group_id"] = None
776+
777+
field = data.get("upgrade_policy", None)
778+
if field is not None:
779+
args["upgrade_policy"] = unmarshal_PoolUpgradePolicy(field)
780+
else:
781+
args["upgrade_policy"] = None
782+
741783
field = data.get("root_volume_type", None)
742784
if field is not None:
743785
args["root_volume_type"] = field
@@ -756,23 +798,33 @@ def unmarshal_Pool(data: Any) -> Pool:
756798
else:
757799
args["security_group_id"] = None
758800

759-
field = data.get("region", None)
801+
field = data.get("labels", None)
760802
if field is not None:
761-
args["region"] = field
803+
args["labels"] = field
762804
else:
763-
args["region"] = None
805+
args["labels"] = {}
764806

765-
field = data.get("placement_group_id", None)
807+
field = data.get("taints", None)
766808
if field is not None:
767-
args["placement_group_id"] = field
809+
args["taints"] = (
810+
[unmarshal_CoreV1Taint(v) for v in field] if field is not None else None
811+
)
768812
else:
769-
args["placement_group_id"] = None
813+
args["taints"] = []
770814

771-
field = data.get("upgrade_policy", None)
815+
field = data.get("startup_taints", None)
772816
if field is not None:
773-
args["upgrade_policy"] = unmarshal_PoolUpgradePolicy(field)
817+
args["startup_taints"] = (
818+
[unmarshal_CoreV1Taint(v) for v in field] if field is not None else None
819+
)
774820
else:
775-
args["upgrade_policy"] = None
821+
args["startup_taints"] = []
822+
823+
field = data.get("region", None)
824+
if field is not None:
825+
args["region"] = field
826+
else:
827+
args["region"] = None
776828

777829
field = data.get("root_volume_size", None)
778830
if field is not None:
@@ -1481,6 +1533,24 @@ def marshal_MaintenanceWindow(
14811533
return output
14821534

14831535

1536+
def marshal_CoreV1Taint(
1537+
request: CoreV1Taint,
1538+
defaults: ProfileDefaults,
1539+
) -> dict[str, Any]:
1540+
output: dict[str, Any] = {}
1541+
1542+
if request.key is not None:
1543+
output["key"] = request.key
1544+
1545+
if request.value is not None:
1546+
output["value"] = request.value
1547+
1548+
if request.effect is not None:
1549+
output["effect"] = request.effect
1550+
1551+
return output
1552+
1553+
14841554
def marshal_CreateClusterRequestPoolConfigUpgradePolicy(
14851555
request: CreateClusterRequestPoolConfigUpgradePolicy,
14861556
defaults: ProfileDefaults,
@@ -1646,6 +1716,19 @@ def marshal_CreateClusterRequestPoolConfig(
16461716
if request.public_ip_disabled is not None:
16471717
output["public_ip_disabled"] = request.public_ip_disabled
16481718

1719+
if request.labels is not None:
1720+
output["labels"] = {key: value for key, value in request.labels.items()}
1721+
1722+
if request.taints is not None:
1723+
output["taints"] = [
1724+
marshal_CoreV1Taint(item, defaults) for item in request.taints
1725+
]
1726+
1727+
if request.startup_taints is not None:
1728+
output["startup_taints"] = [
1729+
marshal_CoreV1Taint(item, defaults) for item in request.startup_taints
1730+
]
1731+
16491732
if request.security_group_id is not None:
16501733
output["security_group_id"] = request.security_group_id
16511734

@@ -1819,6 +1902,19 @@ def marshal_CreatePoolRequest(
18191902
if request.security_group_id is not None:
18201903
output["security_group_id"] = request.security_group_id
18211904

1905+
if request.labels is not None:
1906+
output["labels"] = {key: value for key, value in request.labels.items()}
1907+
1908+
if request.taints is not None:
1909+
output["taints"] = [
1910+
marshal_CoreV1Taint(item, defaults) for item in request.taints
1911+
]
1912+
1913+
if request.startup_taints is not None:
1914+
output["startup_taints"] = [
1915+
marshal_CoreV1Taint(item, defaults) for item in request.startup_taints
1916+
]
1917+
18221918
return output
18231919

18241920

@@ -1860,24 +1956,6 @@ def marshal_SetPoolLabelsRequest(
18601956
return output
18611957

18621958

1863-
def marshal_CoreV1Taint(
1864-
request: CoreV1Taint,
1865-
defaults: ProfileDefaults,
1866-
) -> dict[str, Any]:
1867-
output: dict[str, Any] = {}
1868-
1869-
if request.key is not None:
1870-
output["key"] = request.key
1871-
1872-
if request.value is not None:
1873-
output["value"] = request.value
1874-
1875-
if request.effect is not None:
1876-
output["effect"] = request.effect
1877-
1878-
return output
1879-
1880-
18811959
def marshal_SetPoolStartupTaintsRequest(
18821960
request: SetPoolStartupTaintsRequest,
18831961
defaults: ProfileDefaults,

0 commit comments

Comments
 (0)