@@ -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