Skip to content

Commit

Permalink
Merge pull request #25 from dataiku/fix/dss12-sc-134558-clusters-in-d…
Browse files Browse the repository at this point in the history
…ifferent-zones

Fix creating clusters in a different region/zone than instance
  • Loading branch information
marchelleboid authored May 4, 2023
2 parents 0cba168 + 518616a commit 5ab7e60
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.3.0
- 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)
- Fix issue when creating a cluster in a different region/zone

## Version 1.2.0
- Fix the cluster configuration's merging mechanism for string parameters
Expand Down
3 changes: 2 additions & 1 deletion python-clusters/attach-gke-cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def start(self):

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

# add the admin role so that we can do the managed kubernetes stuff for spark
create_admin_binding(self.config.get("userName", None), kube_config_path)
Expand Down
3 changes: 2 additions & 1 deletion python-clusters/create-gke-cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def start(self):

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

# add the admin role so that we can do the managed kubernetes stuff for spark
create_admin_binding(self.config.get("userName", None), kube_config_path)
Expand Down
10 changes: 4 additions & 6 deletions python-lib/dku_google/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_instance_service_account():
return instance_active_sa


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

instance_info = get_instance_info()

# Build the command
cmd = ["gcloud", "container", "clusters", "get-credentials", cluster_id]
if is_cluster_regional:
cmd.append("--region")
cmd.append(instance_info["region"])
cmd.append(region_or_zone)
else:
cmd.append("--zone")
cmd.append(instance_info["zone"])
cmd.append(region_or_zone)

# Run the command
output = _run_cmd(cmd, env=gcloud_env)
_run_cmd(cmd, env=gcloud_env)

0 comments on commit 5ab7e60

Please sign in to comment.