diff --git a/src/codeflare_sdk/cluster/cluster.py b/src/codeflare_sdk/cluster/cluster.py index 365048967..d0768b519 100644 --- a/src/codeflare_sdk/cluster/cluster.py +++ b/src/codeflare_sdk/cluster/cluster.py @@ -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]: diff --git a/src/codeflare_sdk/templates/base-template.yaml b/src/codeflare_sdk/templates/base-template.yaml index 0efbf55e0..85a990288 100644 --- a/src/codeflare_sdk/templates/base-template.yaml +++ b/src/codeflare_sdk/templates/base-template.yaml @@ -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 diff --git a/src/codeflare_sdk/utils/generate_yaml.py b/src/codeflare_sdk/utils/generate_yaml.py index 5465ec954..a4cce0de2 100755 --- a/src/codeflare_sdk/utils/generate_yaml.py +++ b/src/codeflare_sdk/utils/generate_yaml.py @@ -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()) @@ -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): @@ -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) diff --git a/tests/unit_test.py b/tests/unit_test.py index 66d87d961..f65644477 100644 --- a/tests/unit_test.py +++ b/tests/unit_test.py @@ -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(), @@ -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",