Skip to content

Commit

Permalink
Added local_interactive ingress support & fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbins228 committed Aug 17, 2023
1 parent 3addeb5 commit 1d77bed
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
9 changes: 4 additions & 5 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,12 @@ def get_cluster(cluster_name: str, namespace: str = "default"):
def _get_ingress_domain():
try:
config.load_kube_config()
api_client = client.CustomObjectsApi(api_config_handler())
ingress = api_client.get_cluster_custom_object(
"networking.k8s.io", "v1", "ingresses", "cluster"
)
api_client = client.NetworkingV1Api(api_config_handler())
ingress = api_client.list_namespaced_ingress(get_current_namespace())
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e)
return ingress["spec"]["domain"]
domain = ingress.items[1].spec.rules[0].host
return domain


def _app_wrapper_status(name, namespace="default") -> Optional[AppWrapper]:
Expand Down
33 changes: 28 additions & 5 deletions src/codeflare_sdk/templates/base-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,42 @@ spec:
kind: Ingress
metadata:
name: ray-dashboard-raytest
namespace: opendatahub
namespace: default
spec:
rules:
- host: placeholder # Replace with your desired hostname or domain
- host: placeholder
http:
paths:
- path: / # Replace with the path you want to route to the service
- path: /
pathType: Prefix
backend:
service:
name: raytest-head-svc # Replace with your service name
name: raytest-head-svc
port:
number: 8265 # Replace with the service port
number: 8265
- replicas: 1
generictemplate:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rayclient-deployment-name
namespace: default
labels:
odh-ray-cluster-service: deployment-name-head-svc
spec:
rules:
- host: "localhost"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: raycluster-tls-head-svc
port:
number: 10001
tls:
termination: passthrough
- replicas: 1
generictemplate:
apiVersion: v1
Expand Down
8 changes: 4 additions & 4 deletions src/codeflare_sdk/utils/generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ def update_dashboard_route(route_item, cluster_name, namespace):
metadata["name"] = f"ray-dashboard-{cluster_name}"
metadata["namespace"] = namespace
spec = route_item.get("generictemplate", {}).get("spec")
print(spec["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"])
spec["rules"][0]["http"]["paths"][0]["backend"]["service"][
"name"
] = f"{cluster_name}-head-svc"
print(spec["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"])
try:
config_check()
api_client = client.CustomObjectsApi(api_config_handler())
Expand All @@ -73,7 +71,9 @@ def update_rayclient_route(route_item, cluster_name, namespace):
metadata["namespace"] = namespace
metadata["labels"]["odh-ray-cluster-service"] = f"{cluster_name}-head-svc"
spec = route_item.get("generictemplate", {}).get("spec")
spec["to"]["name"] = f"{cluster_name}-head-svc"
spec["rules"][0]["http"]["paths"][0]["backend"]["service"][
"name"
] = f"{cluster_name}-head-svc"


def update_names(yaml, item, appwrapper_name, cluster_name, namespace):
Expand Down Expand Up @@ -267,7 +267,7 @@ def enable_local_interactive(resources, cluster_name, namespace):
config.load_kube_config()
api_client = client.CustomObjectsApi(api_config_handler())
ingress = api_client.get_cluster_custom_object(
"config.openshift.io", "v1", "ingresses", "cluster"
"networking.k8s.io", "v1", "ingresses", "cluster"
)
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e)
Expand Down
37 changes: 17 additions & 20 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ def test_cluster_uris(mocker):
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
return_value={"spec": {"domain": ""}},
)
mocker.patch(
"codeflare_sdk.cluster.cluster._get_ingress_domain",
return_value="apps.cluster.awsroute.org",
)
mocker.patch(
"kubernetes.client.NetworkingV1Api.list_namespaced_ingress",
return_value=ingress_retrieval(),
Expand Down Expand Up @@ -382,37 +386,30 @@ def ray_addr(self, *args):

def ingress_retrieval():
mock_ingress = client.V1Ingress(
metadata={"name": "mock-ingress-1"},
spec={
"rules": [
{
"host": "ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org",
"http": {
"paths": [
{
"path": "/",
"backend": {
"service_name": "unit-test-cluster-head-svc"
},
}
]
},
}
]
},
metadata=client.V1ObjectMeta(name="ray-dashboard-unit-test-cluster"),
spec=client.V1IngressSpec(
rules=[
client.V1IngressRule(
host="ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org"
)
],
),
)
mock_ingress_list = client.V1IngressList(items=[mock_ingress])
return mock_ingress_list


def test_ray_job_wrapping(mocker):
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
mocker.patch(
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
return_value={"spec": {"domain": ""}},
)
cluster = test_cluster_creation(mocker)

mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
mocker.patch(
"kubernetes.client.NetworkingV1Api.list_namespaced_ingress",
return_value=ingress_retrieval(),
)
mocker.patch(
"ray.job_submission.JobSubmissionClient._check_connection_and_version_with_url",
return_value="None",
Expand Down

0 comments on commit 1d77bed

Please sign in to comment.