Skip to content

Commit be566d4

Browse files
authored
feat(k8s): support setting PodCidr, ServiceCidr, and ServiceDNSIP during cluster creation (#1122)
1 parent fb338d1 commit be566d4

File tree

6 files changed

+190
-54
lines changed

6 files changed

+190
-54
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ async def create_cluster(
226226
type_: str,
227227
description: str,
228228
version: str,
229+
cni: CNI,
229230
region: Optional[ScwRegion] = None,
230231
organization_id: Optional[str] = None,
231232
project_id: Optional[str] = None,
232233
name: Optional[str] = None,
233234
tags: Optional[List[str]] = None,
234-
cni: CNI,
235235
pools: Optional[List[CreateClusterRequestPoolConfig]] = None,
236236
autoscaler_config: Optional[CreateClusterRequestAutoscalerConfig] = None,
237237
auto_upgrade: Optional[CreateClusterRequestAutoUpgrade] = None,
@@ -242,21 +242,24 @@ async def create_cluster(
242242
] = None,
243243
apiserver_cert_sans: Optional[List[str]] = None,
244244
private_network_id: Optional[str] = None,
245+
pod_cidr: Optional[str] = None,
246+
service_cidr: Optional[str] = None,
247+
service_dns_ip: Optional[str] = None,
245248
) -> Cluster:
246249
"""
247250
Create a new Cluster.
248251
Create a new Kubernetes cluster in a Scaleway region.
249252
:param type_: Type of the cluster. See [list available cluster types](#list-available-cluster-types-for-a-cluster) for a list of valid types.
250253
:param description: Cluster description.
251254
:param version: Kubernetes version of the cluster.
255+
:param cni: Container Network Interface (CNI) plugin running in the cluster.
252256
:param region: Region to target. If none is passed will use default region from the config.
253257
:param organization_id: Organization ID in which the cluster will be created.
254258
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
255259
:param project_id: Project ID in which the cluster will be created.
256260
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
257261
:param name: Cluster name.
258262
:param tags: Tags associated with the cluster.
259-
:param cni: Container Network Interface (CNI) plugin running in the cluster.
260263
:param pools: Pools created along with the cluster.
261264
:param autoscaler_config: Autoscaler configuration for the cluster. It allows you to set (to an extent) your preferred autoscaler configuration, which is an implementation of the cluster-autoscaler (https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/).
262265
:param auto_upgrade: Auto upgrade configuration of the cluster. This configuration enables to set a specific 2-hour time window in which the cluster can be automatically updated to the latest patch version.
@@ -265,6 +268,9 @@ async def create_cluster(
265268
:param open_id_connect_config: OpenID Connect configuration of the cluster. This configuration enables to update the OpenID Connect configuration of the Kubernetes API server.
266269
:param apiserver_cert_sans: Additional Subject Alternative Names for the Kubernetes API server certificate.
267270
:param private_network_id: Private network ID for internal cluster communication (cannot be changed later).
271+
:param pod_cidr: Subnet used for the Pod CIDR (cannot be changed later).
272+
:param service_cidr: Subnet used for the Service CIDR (cannot be changed later).
273+
:param service_dns_ip: IP used for the DNS Service (cannot be changes later). If unset, default to Service CIDR's network + 10.
268274
:return: :class:`Cluster <Cluster>`
269275
270276
Usage:
@@ -290,10 +296,10 @@ async def create_cluster(
290296
type_=type_,
291297
description=description,
292298
version=version,
299+
cni=cni,
293300
region=region,
294301
name=name or random_name(prefix="k8s"),
295302
tags=tags,
296-
cni=cni,
297303
pools=pools,
298304
autoscaler_config=autoscaler_config,
299305
auto_upgrade=auto_upgrade,
@@ -302,6 +308,9 @@ async def create_cluster(
302308
open_id_connect_config=open_id_connect_config,
303309
apiserver_cert_sans=apiserver_cert_sans,
304310
private_network_id=private_network_id,
311+
pod_cidr=pod_cidr,
312+
service_cidr=service_cidr,
313+
service_dns_ip=service_dns_ip,
305314
project_id=project_id,
306315
organization_id=organization_id,
307316
),

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

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ def unmarshal_Cluster(data: Any) -> Cluster:
447447
if field is not None:
448448
args["feature_gates"] = field
449449

450+
field = data.get("admission_plugins", None)
451+
if field is not None:
452+
args["admission_plugins"] = field
453+
450454
field = data.get("created_at", None)
451455
if field is not None:
452456
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
@@ -471,9 +475,11 @@ def unmarshal_Cluster(data: Any) -> Cluster:
471475
else:
472476
args["auto_upgrade"] = None
473477

474-
field = data.get("admission_plugins", None)
478+
field = data.get("open_id_connect_config", None)
475479
if field is not None:
476-
args["admission_plugins"] = field
480+
args["open_id_connect_config"] = unmarshal_ClusterOpenIDConnectConfig(field)
481+
else:
482+
args["open_id_connect_config"] = None
477483

478484
field = data.get("apiserver_cert_sans", None)
479485
if field is not None:
@@ -483,11 +489,17 @@ def unmarshal_Cluster(data: Any) -> Cluster:
483489
if field is not None:
484490
args["iam_nodes_group_id"] = field
485491

486-
field = data.get("open_id_connect_config", None)
492+
field = data.get("pod_cidr", None)
487493
if field is not None:
488-
args["open_id_connect_config"] = unmarshal_ClusterOpenIDConnectConfig(field)
489-
else:
490-
args["open_id_connect_config"] = None
494+
args["pod_cidr"] = field
495+
496+
field = data.get("service_cidr", None)
497+
if field is not None:
498+
args["service_cidr"] = field
499+
500+
field = data.get("service_dns_ip", None)
501+
if field is not None:
502+
args["service_dns_ip"] = field
491503

492504
field = data.get("private_network_id", None)
493505
if field is not None:
@@ -1106,8 +1118,12 @@ def marshal_ACLRuleRequest(
11061118
output.update(
11071119
resolve_one_of(
11081120
[
1109-
OneOfPossibility("ip", request.ip),
1110-
OneOfPossibility("scaleway_ranges", request.scaleway_ranges),
1121+
OneOfPossibility(param="ip", value=request.ip, marshal_func=None),
1122+
OneOfPossibility(
1123+
param="scaleway_ranges",
1124+
value=request.scaleway_ranges,
1125+
marshal_func=None,
1126+
),
11111127
]
11121128
),
11131129
)
@@ -1325,12 +1341,16 @@ def marshal_CreateClusterRequest(
13251341
resolve_one_of(
13261342
[
13271343
OneOfPossibility(
1328-
"project_id", request.project_id, defaults.default_project_id
1344+
param="project_id",
1345+
value=request.project_id,
1346+
default=defaults.default_project_id,
1347+
marshal_func=None,
13291348
),
13301349
OneOfPossibility(
1331-
"organization_id",
1332-
request.organization_id,
1333-
defaults.default_organization_id,
1350+
param="organization_id",
1351+
value=request.organization_id,
1352+
default=defaults.default_organization_id,
1353+
marshal_func=None,
13341354
),
13351355
]
13361356
),
@@ -1345,15 +1365,15 @@ def marshal_CreateClusterRequest(
13451365
if request.version is not None:
13461366
output["version"] = request.version
13471367

1368+
if request.cni is not None:
1369+
output["cni"] = str(request.cni)
1370+
13481371
if request.name is not None:
13491372
output["name"] = request.name
13501373

13511374
if request.tags is not None:
13521375
output["tags"] = request.tags
13531376

1354-
if request.cni is not None:
1355-
output["cni"] = str(request.cni)
1356-
13571377
if request.pools is not None:
13581378
output["pools"] = [
13591379
marshal_CreateClusterRequestPoolConfig(item, defaults)
@@ -1389,6 +1409,15 @@ def marshal_CreateClusterRequest(
13891409
if request.private_network_id is not None:
13901410
output["private_network_id"] = request.private_network_id
13911411

1412+
if request.pod_cidr is not None:
1413+
output["pod_cidr"] = request.pod_cidr
1414+
1415+
if request.service_cidr is not None:
1416+
output["service_cidr"] = request.service_cidr
1417+
1418+
if request.service_dns_ip is not None:
1419+
output["service_dns_ip"] = request.service_dns_ip
1420+
13921421
return output
13931422

13941423

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,11 @@ class Cluster:
877877
List of enabled feature gates.
878878
"""
879879

880+
admission_plugins: List[str]
881+
"""
882+
List of enabled admission plugins.
883+
"""
884+
880885
created_at: Optional[datetime]
881886
"""
882887
Date on which the cluster was created.
@@ -897,9 +902,9 @@ class Cluster:
897902
Auto upgrade Kubernetes version of the cluster.
898903
"""
899904

900-
admission_plugins: List[str]
905+
open_id_connect_config: Optional[ClusterOpenIDConnectConfig]
901906
"""
902-
List of enabled admission plugins.
907+
This configuration enables to update the OpenID Connect configuration of the Kubernetes API server.
903908
"""
904909

905910
apiserver_cert_sans: List[str]
@@ -912,9 +917,19 @@ class Cluster:
912917
IAM group that nodes are members of (this field might be empty during early stage of cluster creation).
913918
"""
914919

915-
open_id_connect_config: Optional[ClusterOpenIDConnectConfig]
920+
pod_cidr: str
916921
"""
917-
This configuration enables to update the OpenID Connect configuration of the Kubernetes API server.
922+
Subnet used for the Pod CIDR.
923+
"""
924+
925+
service_cidr: str
926+
"""
927+
Subnet used for the Service CIDR.
928+
"""
929+
930+
service_dns_ip: str
931+
"""
932+
IP used for the DNS Service.
918933
"""
919934

920935
private_network_id: Optional[str]
@@ -1182,6 +1197,11 @@ class CreateClusterRequest:
11821197
Kubernetes version of the cluster.
11831198
"""
11841199

1200+
cni: CNI
1201+
"""
1202+
Container Network Interface (CNI) plugin running in the cluster.
1203+
"""
1204+
11851205
region: Optional[ScwRegion]
11861206
"""
11871207
Region to target. If none is passed will use default region from the config.
@@ -1197,11 +1217,6 @@ class CreateClusterRequest:
11971217
Tags associated with the cluster.
11981218
"""
11991219

1200-
cni: CNI
1201-
"""
1202-
Container Network Interface (CNI) plugin running in the cluster.
1203-
"""
1204-
12051220
pools: Optional[List[CreateClusterRequestPoolConfig]]
12061221
"""
12071222
Pools created along with the cluster.
@@ -1242,6 +1257,21 @@ class CreateClusterRequest:
12421257
Private network ID for internal cluster communication (cannot be changed later).
12431258
"""
12441259

1260+
pod_cidr: Optional[str]
1261+
"""
1262+
Subnet used for the Pod CIDR (cannot be changed later).
1263+
"""
1264+
1265+
service_cidr: Optional[str]
1266+
"""
1267+
Subnet used for the Service CIDR (cannot be changed later).
1268+
"""
1269+
1270+
service_dns_ip: Optional[str]
1271+
"""
1272+
IP used for the DNS Service (cannot be changes later). If unset, default to Service CIDR's network + 10.
1273+
"""
1274+
12451275
project_id: Optional[str]
12461276

12471277
organization_id: Optional[str]

scaleway/scaleway/k8s/v1/api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ def create_cluster(
226226
type_: str,
227227
description: str,
228228
version: str,
229+
cni: CNI,
229230
region: Optional[ScwRegion] = None,
230231
organization_id: Optional[str] = None,
231232
project_id: Optional[str] = None,
232233
name: Optional[str] = None,
233234
tags: Optional[List[str]] = None,
234-
cni: CNI,
235235
pools: Optional[List[CreateClusterRequestPoolConfig]] = None,
236236
autoscaler_config: Optional[CreateClusterRequestAutoscalerConfig] = None,
237237
auto_upgrade: Optional[CreateClusterRequestAutoUpgrade] = None,
@@ -242,21 +242,24 @@ def create_cluster(
242242
] = None,
243243
apiserver_cert_sans: Optional[List[str]] = None,
244244
private_network_id: Optional[str] = None,
245+
pod_cidr: Optional[str] = None,
246+
service_cidr: Optional[str] = None,
247+
service_dns_ip: Optional[str] = None,
245248
) -> Cluster:
246249
"""
247250
Create a new Cluster.
248251
Create a new Kubernetes cluster in a Scaleway region.
249252
:param type_: Type of the cluster. See [list available cluster types](#list-available-cluster-types-for-a-cluster) for a list of valid types.
250253
:param description: Cluster description.
251254
:param version: Kubernetes version of the cluster.
255+
:param cni: Container Network Interface (CNI) plugin running in the cluster.
252256
:param region: Region to target. If none is passed will use default region from the config.
253257
:param organization_id: Organization ID in which the cluster will be created.
254258
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
255259
:param project_id: Project ID in which the cluster will be created.
256260
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
257261
:param name: Cluster name.
258262
:param tags: Tags associated with the cluster.
259-
:param cni: Container Network Interface (CNI) plugin running in the cluster.
260263
:param pools: Pools created along with the cluster.
261264
:param autoscaler_config: Autoscaler configuration for the cluster. It allows you to set (to an extent) your preferred autoscaler configuration, which is an implementation of the cluster-autoscaler (https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/).
262265
:param auto_upgrade: Auto upgrade configuration of the cluster. This configuration enables to set a specific 2-hour time window in which the cluster can be automatically updated to the latest patch version.
@@ -265,6 +268,9 @@ def create_cluster(
265268
:param open_id_connect_config: OpenID Connect configuration of the cluster. This configuration enables to update the OpenID Connect configuration of the Kubernetes API server.
266269
:param apiserver_cert_sans: Additional Subject Alternative Names for the Kubernetes API server certificate.
267270
:param private_network_id: Private network ID for internal cluster communication (cannot be changed later).
271+
:param pod_cidr: Subnet used for the Pod CIDR (cannot be changed later).
272+
:param service_cidr: Subnet used for the Service CIDR (cannot be changed later).
273+
:param service_dns_ip: IP used for the DNS Service (cannot be changes later). If unset, default to Service CIDR's network + 10.
268274
:return: :class:`Cluster <Cluster>`
269275
270276
Usage:
@@ -290,10 +296,10 @@ def create_cluster(
290296
type_=type_,
291297
description=description,
292298
version=version,
299+
cni=cni,
293300
region=region,
294301
name=name or random_name(prefix="k8s"),
295302
tags=tags,
296-
cni=cni,
297303
pools=pools,
298304
autoscaler_config=autoscaler_config,
299305
auto_upgrade=auto_upgrade,
@@ -302,6 +308,9 @@ def create_cluster(
302308
open_id_connect_config=open_id_connect_config,
303309
apiserver_cert_sans=apiserver_cert_sans,
304310
private_network_id=private_network_id,
311+
pod_cidr=pod_cidr,
312+
service_cidr=service_cidr,
313+
service_dns_ip=service_dns_ip,
305314
project_id=project_id,
306315
organization_id=organization_id,
307316
),

0 commit comments

Comments
 (0)