Skip to content

Commit 5ab7e60

Browse files
Merge pull request #25 from dataiku/fix/dss12-sc-134558-clusters-in-different-zones
Fix creating clusters in a different region/zone than instance
2 parents 0cba168 + 518616a commit 5ab7e60

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Version 1.3.0
44
- Add more supported Python versions. This plugin can now use 2.7 (deprecated), 3.6, 3.7, 3.8, 3.9, 3.10 (experimental), 3.11 (experimental)
5+
- Fix issue when creating a cluster in a different region/zone
56

67
## Version 1.2.0
78
- Fix the cluster configuration's merging mechanism for string parameters

python-clusters/attach-gke-cluster/cluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def start(self):
2929

3030
# delegate the creation of the kube config file to gcloud to use the client go auth plugin
3131
kube_config_path = os.path.join(os.getcwd(), 'kube_config')
32-
create_kube_config_file(cluster.name, is_regional, kube_config_path)
32+
region_or_zone = clusters.region if is_regional else clusters.zone
33+
create_kube_config_file(cluster.name, is_regional, region_or_zone, kube_config_path)
3334

3435
# add the admin role so that we can do the managed kubernetes stuff for spark
3536
create_admin_binding(self.config.get("userName", None), kube_config_path)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def start(self):
7878

7979
# delegate the creation of the kube config file to gcloud to use the client go auth plugin
8080
kube_config_path = os.path.join(os.getcwd(), 'kube_config')
81-
create_kube_config_file(self.cluster_id, is_regional, kube_config_path)
81+
region_or_zone = clusters.region if is_regional else clusters.zone
82+
create_kube_config_file(self.cluster_id, is_regional, region_or_zone, kube_config_path)
8283

8384
# add the admin role so that we can do the managed kubernetes stuff for spark
8485
create_admin_binding(self.config.get("userName", None), kube_config_path)

python-lib/dku_google/gcloud.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get_instance_service_account():
120120
return instance_active_sa
121121

122122

123-
def create_kube_config_file(cluster_id, is_cluster_regional, kube_config_path):
123+
def create_kube_config_file(cluster_id, is_cluster_regional, region_or_zone, kube_config_path):
124124
"""
125125
Delegate the creation of the kube config file to gke-gcloud-auth-plugin
126126
Starting with Kubernetes 1.26, the authentication to execute kubectl commands on Google clusters
@@ -145,16 +145,14 @@ def create_kube_config_file(cluster_id, is_cluster_regional, kube_config_path):
145145
# Provide the desired location for the kube config to override the default value used by the auth plugin
146146
gcloud_env["KUBECONFIG"] = kube_config_path
147147

148-
instance_info = get_instance_info()
149-
150148
# Build the command
151149
cmd = ["gcloud", "container", "clusters", "get-credentials", cluster_id]
152150
if is_cluster_regional:
153151
cmd.append("--region")
154-
cmd.append(instance_info["region"])
152+
cmd.append(region_or_zone)
155153
else:
156154
cmd.append("--zone")
157-
cmd.append(instance_info["zone"])
155+
cmd.append(region_or_zone)
158156

159157
# Run the command
160-
output = _run_cmd(cmd, env=gcloud_env)
158+
_run_cmd(cmd, env=gcloud_env)

0 commit comments

Comments
 (0)