-
Notifications
You must be signed in to change notification settings - Fork 51
Get cluster #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KPostOffice
merged 6 commits into
project-codeflare:k8s-support
from
carsonmh:get-cluster
Jul 6, 2023
Merged
Get cluster #189
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
687e31d
Add: get_cluster function to get cluster with specified name and name…
carsonmh a230814
Test: make unit tests for get_cluster function
carsonmh 7bc6fb3
refactor
carsonmh 40dba53
refactor tests
carsonmh 583f65f
Refactor: add from_k8_cluster_object(ray_cluster) to simplify get_clu…
carsonmh a929226
Fix: min_worker and max_worker were using default value
carsonmh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,6 +301,49 @@ def torchx_config( | |
to_return["requirements"] = requirements | ||
return to_return | ||
|
||
def from_k8_cluster_object(rc): | ||
machine_types = ( | ||
rc["metadata"]["labels"]["orderedinstance"].split("_") | ||
if "orderedinstance" in rc["metadata"]["labels"] | ||
else [] | ||
) | ||
local_interactive = ( | ||
"volumeMounts" | ||
in rc["spec"]["workerGroupSpecs"][0]["template"]["spec"]["containers"][0] | ||
) | ||
cluster_config = ClusterConfiguration( | ||
name=rc["metadata"]["name"], | ||
namespace=rc["metadata"]["namespace"], | ||
machine_types=machine_types, | ||
min_worker=rc["spec"]["workerGroupSpecs"][0]["minReplicas"], | ||
max_worker=rc["spec"]["workerGroupSpecs"][0]["maxReplicas"], | ||
min_cpus=rc["spec"]["workerGroupSpecs"][0]["template"]["spec"][ | ||
"containers" | ||
][0]["resources"]["requests"]["cpu"], | ||
max_cpus=rc["spec"]["workerGroupSpecs"][0]["template"]["spec"][ | ||
"containers" | ||
][0]["resources"]["limits"]["cpu"], | ||
min_memory=int( | ||
rc["spec"]["workerGroupSpecs"][0]["template"]["spec"]["containers"][0][ | ||
"resources" | ||
]["requests"]["memory"][:-1] | ||
), | ||
max_memory=int( | ||
rc["spec"]["workerGroupSpecs"][0]["template"]["spec"]["containers"][0][ | ||
"resources" | ||
]["limits"]["memory"][:-1] | ||
), | ||
gpu=rc["spec"]["workerGroupSpecs"][0]["template"]["spec"]["containers"][0][ | ||
"resources" | ||
]["limits"]["nvidia.com/gpu"], | ||
instascale=True if machine_types else False, | ||
image=rc["spec"]["workerGroupSpecs"][0]["template"]["spec"]["containers"][ | ||
0 | ||
]["image"], | ||
local_interactive=local_interactive, | ||
) | ||
return Cluster(cluster_config) | ||
|
||
|
||
def list_all_clusters(namespace: str, print_to_console: bool = True): | ||
""" | ||
|
@@ -337,6 +380,27 @@ def get_current_namespace(): # pragma: no cover | |
return "default" | ||
|
||
|
||
def get_cluster(cluster_name: str, namespace: str = "default"): | ||
try: | ||
config.load_kube_config() | ||
api_instance = client.CustomObjectsApi() | ||
rcs = api_instance.list_namespaced_custom_object( | ||
group="ray.io", | ||
version="v1alpha1", | ||
namespace=namespace, | ||
plural="rayclusters", | ||
) | ||
except Exception as e: | ||
return _kube_api_error_handling(e) | ||
|
||
for rc in rcs["items"]: | ||
if rc["metadata"]["name"] == cluster_name: | ||
return Cluster.from_k8_cluster_object(rc) | ||
raise FileNotFoundError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are able to use the function suggested above then the error handling can be removed here. |
||
f"Cluster {cluster_name} is not found in {namespace} namespace" | ||
) | ||
|
||
|
||
# private methods | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/kubernetes-client/python/blob/045b189a282f5165426b841e9e3b16b2739d3837/kubernetes/client/api/custom_objects_api.py#L1580
Can you use this directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KPostOffice I get
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /apis/ray.io/v1alpha1/namespaces/default/rayclusters/quicktest
when calling theget_namespaced_custom_object
so I think there is something wrong with this function