Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions python-clusters/attach-aks-cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from dataiku.cluster import Cluster

from azure.mgmt.containerservice import ContainerServiceClient
from dku_utils.access import _is_none_or_blank
from dku_utils.access import _is_none_or_blank, _print_as_json
from dku_utils.cluster import make_overrides, get_subscription_id
from dku_azure.auth import get_credentials_from_connection_info, get_credentials_from_connection_infoV2
from dku_azure.utils import run_and_process_cloud_error
from dku_azure.utils import run_and_process_cloud_error, get_instance_metadata, get_subscription_id

class MyCluster(Cluster):
Expand Down Expand Up @@ -51,16 +50,19 @@ def start(self):
def do_fetch():
return clusters_client.managed_clusters.list_cluster_admin_credentials(resource_group, cluster_name)
get_credentials_result = run_and_process_cloud_error(do_fetch)
logging.info("Kubeconfig retrieved for cluster %s in %s: %s", cluster_name, resource_group, _print_as_json(get_credentials_result))
kube_config_content = get_credentials_result.kubeconfigs[0].value.decode('utf8')
kube_config_path = os.path.join(os.getcwd(), 'kube_config')
with open(kube_config_path, 'w') as f:
f.write(kube_config_content)
overrides = make_overrides(self.config, yaml.safe_load(kube_config_content), kube_config_path)

# Get other cluster infos
logging.info("Retrieving cluster information for cluster %s in %s", cluster_name, resource_group)
def do_inspect():
return clusters_client.managed_clusters.get(resource_group, cluster_name)
get_cluster_result = run_and_process_cloud_error(do_inspect)
logging.info("Information retrieved for cluster %s in %s: %s", cluster_name, resource_group, _print_as_json(get_cluster_result))

return [overrides, {'kube_config_path':kube_config_path, 'cluster':get_cluster_result.as_dict()}]

Expand Down
5 changes: 4 additions & 1 deletion python-clusters/create-aks-cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
from msrestazure.azure_exceptions import CloudError

from dku_utils.access import _is_none_or_blank, _has_not_blank_property
from dku_utils.access import _is_none_or_blank, _has_not_blank_property, _print_as_json
from dku_utils.cluster import make_overrides, get_cluster_from_connection_info
from dku_kube.nvidia_utils import add_gpu_driver_if_needed
from dku_azure.auth import get_credentials_from_connection_info, get_credentials_from_connection_infoV2
Expand Down Expand Up @@ -320,6 +320,7 @@ def start(self):
logging.info("Start creation of cluster")
def do_creation():
cluster_create_op = cluster_builder.build()
logging.info("Cluster creation results: %s", _print_as_json(cluster_create_op.__dict__))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : I only get an empty dict on success, maybe no print in that case ?

return cluster_create_op.result()
create_result = run_and_process_cloud_error(do_creation)
logging.info("Cluster creation finished")
Expand Down Expand Up @@ -380,6 +381,7 @@ def do_creation():
def do_fetch():
return clusters_client.managed_clusters.list_cluster_admin_credentials(resource_group, self.cluster_name)
get_credentials_result = run_and_process_cloud_error(do_fetch)
logging.info("Kubeconfig retrieved for cluster %s in %s: %s", self.cluster_name, resource_group, _print_as_json(get_credentials_result))
kube_config_content = get_credentials_result.kubeconfigs[0].value.decode("utf8")
logging.info("Writing kubeconfig file...")
kube_config_path = os.path.join(os.getcwd(), "kube_config")
Expand Down Expand Up @@ -440,6 +442,7 @@ def do_delete():
future = clusters_client.managed_clusters.begin_delete(resource_group, cluster_name)
return future.result()
delete_result = run_and_process_cloud_error(do_delete)
logging.info("Cluster deletion results")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no results a this point

Suggested change
logging.info("Cluster deletion results")
logging.info("Cluster deletion requested")


# delete returns void, so we poll until the cluster is really gone
gone = False
Expand Down
9 changes: 7 additions & 2 deletions python-lib/dku_utils/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ def _object_to_json(o):
r = o.__dict__
if isinstance(r, dku_basestring_type):
return r
if isinstance(r, bytearray):
return r.decode("utf-8")
if isinstance(r, Iterable):
if hasattr(r, 'keys'):
d = dict()
for field in r.keys():
r[field] = _object_to_json(r[field])
return r
if not field.startswith('_'):
d[field] = _object_to_json(r[field])

return d
else:
arr = []
for entry in r:
Expand Down
2 changes: 0 additions & 2 deletions python-runnables/inspect-node-pools/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import dataiku
import json, logging
from dku_utils.cluster import get_cluster_from_dss_cluster
from dku_utils.access import _is_none_or_blank
from dku_azure.utils import run_and_process_cloud_error

class MyRunnable(Runnable):
def __init__(self, project_key, config, plugin_config):
Expand Down
3 changes: 2 additions & 1 deletion python-runnables/resize-node-pool/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import dataiku
import json, logging
from dku_utils.cluster import get_cluster_from_dss_cluster
from dku_utils.access import _is_none_or_blank
from dku_utils.access import _is_none_or_blank, _print_as_json
from dku_azure.utils import run_and_process_cloud_error

class MyRunnable(Runnable):
Expand Down Expand Up @@ -50,6 +50,7 @@ def do_update():
cluster_update_op = clusters.managed_clusters.begin_create_or_update(resource_group, cluster_name, cluster)
return cluster_update_op.result()
update_result = run_and_process_cloud_error(do_update)
logging.info("Cluster update results: %s", _print_as_json(update_result))
logging.info("Cluster updated")
Comment on lines +53 to 54
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant

Suggested change
logging.info("Cluster update results: %s", _print_as_json(update_result))
logging.info("Cluster updated")
logging.info("Cluster updated with results: %s", _print_as_json(update_result))

return '<pre class="debug">%s</pre>' % json.dumps(update_result.as_dict(), indent=2)