Skip to content

Commit 526e2d6

Browse files
committed
Altered ingress creation code
1 parent 3164d81 commit 526e2d6

File tree

4 files changed

+46
-98
lines changed

4 files changed

+46
-98
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ def up(self):
128128
plural="appwrappers",
129129
body=aw,
130130
)
131-
# Create the ingress
132-
create_ingress(self)
133131
except Exception as e: # pragma: no cover
134132
return _kube_api_error_handling(e)
135133

@@ -149,11 +147,6 @@ def down(self):
149147
plural="appwrappers",
150148
name=self.app_wrapper_name,
151149
)
152-
# Delete the ingress
153-
api_instance = client.NetworkingV1Api(api_config_handler())
154-
api_instance.delete_namespaced_ingress(
155-
name=f"ray-dashboard-{self.config.name}", namespace=namespace
156-
)
157150
except Exception as e: # pragma: no cover
158151
return _kube_api_error_handling(e)
159152

@@ -362,54 +355,6 @@ def local_client_url(self):
362355
return "None"
363356

364357

365-
def create_ingress(self):
366-
"""
367-
Create a Kubernetes Ingress resource to expose the Ray dashboard service externally.
368-
"""
369-
ingress_domain = _get_ingress_domain()
370-
try:
371-
config_check()
372-
api_instance = client.NetworkingV1Api(api_config_handler())
373-
374-
ingress_manifest = {
375-
"apiVersion": "networking.k8s.io/v1",
376-
"kind": "Ingress",
377-
"metadata": {
378-
"name": f"ray-dashboard-{self.config.name}",
379-
"namespace": self.config.namespace,
380-
},
381-
"spec": {
382-
"rules": [
383-
{
384-
"host": f"ray-dashboard-{self.config.name}.{self.config.namespace}.{ingress_domain}",
385-
"http": {
386-
"paths": [
387-
{
388-
"path": "/",
389-
"pathType": "Prefix",
390-
"backend": {
391-
"service": {
392-
"name": f"{self.config.name}-head-svc",
393-
"port": {
394-
"number": 8265,
395-
},
396-
}
397-
},
398-
}
399-
]
400-
},
401-
}
402-
],
403-
},
404-
}
405-
406-
api_instance.create_namespaced_ingress(
407-
namespace=self.config.namespace, body=ingress_manifest
408-
)
409-
except Exception as e:
410-
return _kube_api_error_handling(e)
411-
412-
413358
def list_all_clusters(namespace: str, print_to_console: bool = True):
414359
"""
415360
Returns (and prints by default) a list of all clusters in a given namespace.
@@ -486,7 +431,7 @@ def _get_ingress_domain():
486431
config.load_kube_config()
487432
api_client = client.CustomObjectsApi()
488433
ingress = api_client.get_cluster_custom_object(
489-
"config.openshift.io", "v1", "ingresses", "cluster"
434+
"networking.k8s.io", "v1", "ingresses", "cluster"
490435
)
491436
except Exception as e: # pragma: no cover
492437
return _kube_api_error_handling(e)

src/codeflare_sdk/templates/base-template.yaml

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -287,40 +287,25 @@ spec:
287287
optional: false
288288
- name: server-cert
289289
emptyDir: {}
290-
- replica: 1
291-
generictemplate:
292-
kind: Route
293-
apiVersion: route.openshift.io/v1
294-
metadata:
295-
name: ray-dashboard-deployment-name
296-
namespace: default
297-
labels:
298-
# allows me to return name of service that Ray operator creates
299-
odh-ray-cluster-service: deployment-name-head-svc
300-
spec:
301-
to:
302-
kind: Service
303-
name: deployment-name-head-svc
304-
port:
305-
targetPort: dashboard
306290
- replicas: 1
307291
generictemplate:
308-
apiVersion: route.openshift.io/v1
309-
kind: Route
292+
apiVersion: networking.k8s.io/v1
293+
kind: Ingress
310294
metadata:
311-
name: rayclient-deployment-name
312-
namespace: default
313-
labels:
314-
# allows me to return name of service that Ray operator creates
315-
odh-ray-cluster-service: deployment-name-head-svc
295+
name: ray-dashboard-raytest
296+
namespace: opendatahub
316297
spec:
317-
port:
318-
targetPort: client
319-
tls:
320-
termination: passthrough
321-
to:
322-
kind: Service
323-
name: deployment-name-head-svc
298+
rules:
299+
- host: placeholder # Replace with your desired hostname or domain
300+
http:
301+
paths:
302+
- path: / # Replace with the path you want to route to the service
303+
pathType: Prefix
304+
backend:
305+
service:
306+
name: raytest-head-svc # Replace with your service name
307+
port:
308+
number: 8265 # Replace with the service port
324309
- replicas: 1
325310
generictemplate:
326311
apiVersion: v1

src/codeflare_sdk/utils/generate_yaml.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import uuid
2424
from kubernetes import client, config
2525
from .kube_api_helpers import _kube_api_error_handling
26+
from ..cluster.auth import api_config_handler, config_check
2627

2728

2829
def read_template(template):
@@ -47,9 +48,22 @@ def update_dashboard_route(route_item, cluster_name, namespace):
4748
metadata = route_item.get("generictemplate", {}).get("metadata")
4849
metadata["name"] = f"ray-dashboard-{cluster_name}"
4950
metadata["namespace"] = namespace
50-
metadata["labels"]["odh-ray-cluster-service"] = f"{cluster_name}-head-svc"
5151
spec = route_item.get("generictemplate", {}).get("spec")
52-
spec["to"]["name"] = f"{cluster_name}-head-svc"
52+
print(spec["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"])
53+
spec["rules"][0]["http"]["paths"][0]["backend"]["service"][
54+
"name"
55+
] = f"{cluster_name}-head-svc"
56+
print(spec["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"])
57+
try:
58+
config_check()
59+
api_client = client.CustomObjectsApi(api_config_handler())
60+
ingress = api_client.get_cluster_custom_object(
61+
"config.openshift.io", "v1", "ingresses", "cluster"
62+
)
63+
except Exception as e: # pragma: no cover
64+
return _kube_api_error_handling(e)
65+
domain = ingress["spec"]["domain"]
66+
spec["rules"][0]["host"] = f"ray-dashboard-{cluster_name}-{namespace}.{domain}"
5367

5468

5569
# ToDo: refactor the update_x_route() functions

tests/test-case.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,22 @@ spec:
178178
name: init-myservice
179179
replicas: 1
180180
- generictemplate:
181-
apiVersion: route.openshift.io/v1
182-
kind: Route
181+
apiVersion: networking.k8s.io/v1
182+
kind: Ingress
183183
metadata:
184-
labels:
185-
odh-ray-cluster-service: unit-test-cluster-head-svc
186184
name: ray-dashboard-unit-test-cluster
187185
namespace: ns
188186
spec:
189-
port:
190-
targetPort: dashboard
191-
to:
192-
kind: Service
193-
name: unit-test-cluster-head-svc
194-
replica: 1
187+
rules:
188+
- host: ray-dashboard-unit-test-cluster-ns.
189+
http:
190+
paths:
191+
- backend:
192+
service:
193+
name: unit-test-cluster-head-svc
194+
port:
195+
number: 8265
196+
path: /
197+
pathType: Prefix
198+
replicas: 1
195199
Items: []

0 commit comments

Comments
 (0)