Skip to content

Commit cff93af

Browse files
committed
Altered ingress creation code
1 parent 3ff21ba commit cff93af

File tree

4 files changed

+45
-98
lines changed

4 files changed

+45
-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

@@ -367,54 +360,6 @@ def local_client_url(self):
367360
return "None"
368361

369362

370-
def create_ingress(self):
371-
"""
372-
Create a Kubernetes Ingress resource to expose the Ray dashboard service externally.
373-
"""
374-
ingress_domain = _get_ingress_domain()
375-
try:
376-
config_check()
377-
api_instance = client.NetworkingV1Api(api_config_handler())
378-
379-
ingress_manifest = {
380-
"apiVersion": "networking.k8s.io/v1",
381-
"kind": "Ingress",
382-
"metadata": {
383-
"name": f"ray-dashboard-{self.config.name}",
384-
"namespace": self.config.namespace,
385-
},
386-
"spec": {
387-
"rules": [
388-
{
389-
"host": f"ray-dashboard-{self.config.name}.{self.config.namespace}.{ingress_domain}",
390-
"http": {
391-
"paths": [
392-
{
393-
"path": "/",
394-
"pathType": "Prefix",
395-
"backend": {
396-
"service": {
397-
"name": f"{self.config.name}-head-svc",
398-
"port": {
399-
"number": 8265,
400-
},
401-
}
402-
},
403-
}
404-
]
405-
},
406-
}
407-
],
408-
},
409-
}
410-
411-
api_instance.create_namespaced_ingress(
412-
namespace=self.config.namespace, body=ingress_manifest
413-
)
414-
except Exception as e:
415-
return _kube_api_error_handling(e)
416-
417-
418363
def list_all_clusters(namespace: str, print_to_console: bool = True):
419364
"""
420365
Returns (and prints by default) a list of all clusters in a given namespace.
@@ -491,7 +436,7 @@ def _get_ingress_domain():
491436
config.load_kube_config()
492437
api_client = client.CustomObjectsApi(api_config_handler())
493438
ingress = api_client.get_cluster_custom_object(
494-
"config.openshift.io", "v1", "ingresses", "cluster"
439+
"networking.k8s.io", "v1", "ingresses", "cluster"
495440
)
496441
except Exception as e: # pragma: no cover
497442
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
@@ -289,38 +289,23 @@ spec:
289289
emptyDir: {}
290290
- replicas: 1
291291
generictemplate:
292-
kind: Route
293-
apiVersion: route.openshift.io/v1
292+
apiVersion: networking.k8s.io/v1
293+
kind: Ingress
294294
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
306-
- replicas: 1
307-
generictemplate:
308-
apiVersion: route.openshift.io/v1
309-
kind: Route
310-
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +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
26+
from ..cluster.auth import api_config_handler, config_check
2727

2828

2929
def read_template(template):
@@ -48,9 +48,22 @@ def update_dashboard_route(route_item, cluster_name, namespace):
4848
metadata = route_item.get("generictemplate", {}).get("metadata")
4949
metadata["name"] = f"ray-dashboard-{cluster_name}"
5050
metadata["namespace"] = namespace
51-
metadata["labels"]["odh-ray-cluster-service"] = f"{cluster_name}-head-svc"
5251
spec = route_item.get("generictemplate", {}).get("spec")
53-
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}"
5467

5568

5669
# ToDo: refactor the update_x_route() functions

tests/test-case.yaml

Lines changed: 13 additions & 9 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
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
194198
replicas: 1
195199
Items: []

0 commit comments

Comments
 (0)