-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI Layout and Create RayCluster function (#227)
* Create: base and file layout for CLI * Add: Create raycluster command for CLI * Refactor: refactor CLI using pre-commit * Test: unit tests for create raycluster function in the CLI * Update: update egg-info with more paths * Change: change Framework Cluster to RayCluster * merge: rebase with main * Fix: unit tests * Change: create cluster to define cluster in unit tests * Add: error handling for invalid command * test: change tests so cli cluster definition has its own yaml file
- Loading branch information
1 parent
97bf513
commit 2f835e0
Showing
10 changed files
with
330 additions
and
0 deletions.
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
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
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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ast | ||
import click | ||
|
||
|
||
class PythonLiteralOption(click.Option): | ||
def type_cast_value(self, ctx, value): | ||
try: | ||
if not value: | ||
return None | ||
return ast.literal_eval(value) | ||
except: | ||
raise click.BadParameter(value) |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import click | ||
import sys | ||
import os | ||
|
||
cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "commands")) | ||
|
||
|
||
class CodeflareCLI(click.MultiCommand): | ||
def list_commands(self, ctx): | ||
rv = [] | ||
for filename in os.listdir(cmd_folder): | ||
if filename.endswith(".py") and filename != "__init__.py": | ||
rv.append(filename[:-3]) | ||
rv.sort() | ||
return rv | ||
|
||
def get_command(self, ctx, name): | ||
ns = {} | ||
fn = os.path.join(cmd_folder, name + ".py") | ||
try: | ||
with open(fn) as f: | ||
code = compile(f.read(), fn, "exec") | ||
eval(code, ns, ns) | ||
return ns["cli"] | ||
except FileNotFoundError: | ||
return | ||
|
||
|
||
@click.command(cls=CodeflareCLI) | ||
@click.pass_context | ||
def cli(ctx): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import click | ||
|
||
from codeflare_sdk.cluster.cluster import Cluster | ||
from codeflare_sdk.cluster.config import ClusterConfiguration | ||
from codeflare_sdk.cli.cli_utils import PythonLiteralOption | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""Define a resource with parameter specifications""" | ||
pass | ||
|
||
|
||
@cli.command() | ||
@click.option("--name", type=str, required=True) | ||
@click.option("--namespace", "-n", type=str) | ||
@click.option("--head_info", cls=PythonLiteralOption, type=list) | ||
@click.option("--machine_types", cls=PythonLiteralOption, type=list) | ||
@click.option("--min_cpus", type=int) | ||
@click.option("--max_cpus", type=int) | ||
@click.option("--min_worker", type=int) | ||
@click.option("--max_worker", type=int) | ||
@click.option("--min_memory", type=int) | ||
@click.option("--max_memory", type=int) | ||
@click.option("--gpu", type=int) | ||
@click.option("--template", type=str) | ||
@click.option("--instascale", type=bool) | ||
@click.option("--envs", cls=PythonLiteralOption, type=dict) | ||
@click.option("--image", type=str) | ||
@click.option("--local_interactive", type=bool) | ||
@click.option("--image_pull_secrets", cls=PythonLiteralOption, type=list) | ||
def raycluster(**kwargs): | ||
"""Define a RayCluster with parameter specifications""" | ||
filtered_kwargs = {k: v for k, v in kwargs.items() if v is not None} | ||
clusterConfig = ClusterConfiguration(**filtered_kwargs) | ||
Cluster(clusterConfig) # Creates yaml file |
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 |
---|---|---|
@@ -0,0 +1,195 @@ | ||
apiVersion: mcad.ibm.com/v1beta1 | ||
kind: AppWrapper | ||
metadata: | ||
labels: | ||
orderedinstance: cpu.small_gpu.large | ||
name: cli-test-cluster | ||
namespace: ns | ||
spec: | ||
priority: 9 | ||
resources: | ||
GenericItems: | ||
- custompodresources: | ||
- limits: | ||
cpu: 2 | ||
memory: 8G | ||
nvidia.com/gpu: 0 | ||
replicas: 1 | ||
requests: | ||
cpu: 2 | ||
memory: 8G | ||
nvidia.com/gpu: 0 | ||
- limits: | ||
cpu: 4 | ||
memory: 6G | ||
nvidia.com/gpu: 7 | ||
replicas: 2 | ||
requests: | ||
cpu: 3 | ||
memory: 5G | ||
nvidia.com/gpu: 7 | ||
generictemplate: | ||
apiVersion: ray.io/v1alpha1 | ||
kind: RayCluster | ||
metadata: | ||
labels: | ||
appwrapper.mcad.ibm.com: cli-test-cluster | ||
controller-tools.k8s.io: '1.0' | ||
name: cli-test-cluster | ||
namespace: ns | ||
spec: | ||
autoscalerOptions: | ||
idleTimeoutSeconds: 60 | ||
imagePullPolicy: Always | ||
resources: | ||
limits: | ||
cpu: 500m | ||
memory: 512Mi | ||
requests: | ||
cpu: 500m | ||
memory: 512Mi | ||
upscalingMode: Default | ||
enableInTreeAutoscaling: false | ||
headGroupSpec: | ||
rayStartParams: | ||
block: 'true' | ||
dashboard-host: 0.0.0.0 | ||
num-gpus: '0' | ||
serviceType: ClusterIP | ||
template: | ||
spec: | ||
affinity: | ||
nodeAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: cli-test-cluster | ||
operator: In | ||
values: | ||
- cli-test-cluster | ||
containers: | ||
- env: | ||
- name: MY_POD_IP | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: status.podIP | ||
- name: RAY_USE_TLS | ||
value: '0' | ||
- name: RAY_TLS_SERVER_CERT | ||
value: /home/ray/workspace/tls/server.crt | ||
- name: RAY_TLS_SERVER_KEY | ||
value: /home/ray/workspace/tls/server.key | ||
- name: RAY_TLS_CA_CERT | ||
value: /home/ray/workspace/tls/ca.crt | ||
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116 | ||
imagePullPolicy: Always | ||
lifecycle: | ||
preStop: | ||
exec: | ||
command: | ||
- /bin/sh | ||
- -c | ||
- ray stop | ||
name: ray-head | ||
ports: | ||
- containerPort: 6379 | ||
name: gcs | ||
- containerPort: 8265 | ||
name: dashboard | ||
- containerPort: 10001 | ||
name: client | ||
resources: | ||
limits: | ||
cpu: 2 | ||
memory: 8G | ||
nvidia.com/gpu: 0 | ||
requests: | ||
cpu: 2 | ||
memory: 8G | ||
nvidia.com/gpu: 0 | ||
imagePullSecrets: | ||
- name: cli-test-pull-secret | ||
rayVersion: 2.1.0 | ||
workerGroupSpecs: | ||
- groupName: small-group-cli-test-cluster | ||
maxReplicas: 2 | ||
minReplicas: 2 | ||
rayStartParams: | ||
block: 'true' | ||
num-gpus: '7' | ||
replicas: 2 | ||
template: | ||
metadata: | ||
annotations: | ||
key: value | ||
labels: | ||
key: value | ||
spec: | ||
affinity: | ||
nodeAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: cli-test-cluster | ||
operator: In | ||
values: | ||
- cli-test-cluster | ||
containers: | ||
- env: | ||
- name: MY_POD_IP | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: status.podIP | ||
- name: RAY_USE_TLS | ||
value: '0' | ||
- name: RAY_TLS_SERVER_CERT | ||
value: /home/ray/workspace/tls/server.crt | ||
- name: RAY_TLS_SERVER_KEY | ||
value: /home/ray/workspace/tls/server.key | ||
- name: RAY_TLS_CA_CERT | ||
value: /home/ray/workspace/tls/ca.crt | ||
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116 | ||
lifecycle: | ||
preStop: | ||
exec: | ||
command: | ||
- /bin/sh | ||
- -c | ||
- ray stop | ||
name: machine-learning | ||
resources: | ||
limits: | ||
cpu: 4 | ||
memory: 6G | ||
nvidia.com/gpu: 7 | ||
requests: | ||
cpu: 3 | ||
memory: 5G | ||
nvidia.com/gpu: 7 | ||
imagePullSecrets: | ||
- name: cli-test-pull-secret | ||
initContainers: | ||
- command: | ||
- sh | ||
- -c | ||
- until nslookup $RAY_IP.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; | ||
do echo waiting for myservice; sleep 2; done | ||
image: busybox:1.28 | ||
name: init-myservice | ||
replicas: 1 | ||
- generictemplate: | ||
apiVersion: route.openshift.io/v1 | ||
kind: Route | ||
metadata: | ||
labels: | ||
odh-ray-cluster-service: cli-test-cluster-head-svc | ||
name: ray-dashboard-cli-test-cluster | ||
namespace: ns | ||
spec: | ||
port: | ||
targetPort: dashboard | ||
to: | ||
kind: Service | ||
name: cli-test-cluster-head-svc | ||
replica: 1 | ||
Items: [] |
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