Skip to content

Commit d3bd8da

Browse files
authored
Merge pull request #11 from dataiku/task/named-secondary-ranges
add ability to use named secondary ranges
2 parents 17bfff8 + 4e73d28 commit d3bd8da

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

python-clusters/create-gke-cluster/cluster.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@
6464
{
6565
"name": "podIpRange",
6666
"label": "Pod IP range",
67-
"description": "Use CIDR block/mask notation, e.g. 10.0.0.0/21 or /21",
67+
"description": "Range name or CIDR block/mask notation, e.g. 10.0.0.0/21 or /21. If using a named range, ensure it is larger than /21.",
6868
"type": "STRING",
6969
"mandatory": false,
7070
"visibilityCondition": "model.isVpcNative"
7171
},
7272
{
7373
"name": "svcIpRange",
7474
"label": "Service IP range",
75-
"description": "Use CIDR block/mask notation, e.g. 10.0.0.0/24 or /24. MUST be different from pod IP range.",
75+
"description": "Range name or CIDR block/mask notation, e.g. 10.0.0.0/24 or /24. MUST be different from pod IP range.",
7676
"type": "STRING",
7777
"mandatory": false,
7878
"visibilityCondition": "model.isVpcNative"

python-lib/dku_google/clusters.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def with_labels(self, labels={}):
220220
def with_vpc_native_settings(self, is_vpc_native, pod_ip_range, svc_ip_range):
221221
if is_vpc_native:
222222
self.is_vpc_native = is_vpc_native
223+
if pod_ip_range is not None and len(pod_ip_range) > 0 and pod_ip_range == svc_ip_range:
224+
raise Exception("Service IP range must be different from pod IP range")
223225
self.pod_ip_range = pod_ip_range
224226
self.svc_ip_range = svc_ip_range
225227
return self
@@ -269,10 +271,18 @@ def build(self):
269271
if self.is_vpc_native:
270272
ip_allocation_policy = {
271273
"createSubnetwork": False,
272-
"useIpAliases": True,
273-
"servicesIpv4CidrBlock": cluster_svc_ip_range,
274-
"clusterIpv4CidrBlock": cluster_pod_ip_range,
274+
"useIpAliases": True
275275
}
276+
if re.match('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+', cluster_svc_ip_range):
277+
ip_allocation_policy["servicesIpv4CidrBlock"] = cluster_svc_ip_range
278+
elif cluster_svc_ip_range is not None and len(cluster_svc_ip_range) > 0:
279+
# assume it's an existing range name (shared VPC case)
280+
ip_allocation_policy["servicesSecondaryRangeName"] = cluster_svc_ip_range
281+
if re.match('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+', cluster_pod_ip_range):
282+
ip_allocation_policy["clusterIpv4CidrBlock"] = cluster_pod_ip_range
283+
elif cluster_pod_ip_range is not None and len(cluster_pod_ip_range) > 0:
284+
# assume it's an existing range name (shared VPC case)
285+
ip_allocation_policy["clusterSecondaryRangeName"] = cluster_pod_ip_range
276286
create_cluster_request_body["cluster"]["ipAllocationPolicy"] = ip_allocation_policy
277287

278288
if self.legacy_auth:

0 commit comments

Comments
 (0)