24
24
from kubernetes import client , config
25
25
from .kube_api_helpers import _kube_api_error_handling
26
26
from ..cluster .auth import api_config_handler , config_check
27
- from jinja2 import Template
28
- import pathlib
29
27
30
28
31
29
def read_template (template ):
@@ -56,8 +54,8 @@ def is_openshift_cluster():
56
54
)
57
55
58
56
return True
59
- except client .ApiException as e :
60
- if e .status == 404 :
57
+ except client .ApiException as e : # pragma: no cover
58
+ if e .status == 404 or e . status == 403 :
61
59
return False
62
60
else :
63
61
print (f"Error detecting cluster type defaulting to Kubernetes: { e } " )
@@ -66,21 +64,21 @@ def is_openshift_cluster():
66
64
67
65
def update_dashboard_ingress (
68
66
ingress_item , cluster_name , namespace , ingress_options , ingress_domain
69
- ):
67
+ ): # pragma: no cover
70
68
metadata = ingress_item .get ("generictemplate" , {}).get ("metadata" )
71
69
spec = ingress_item .get ("generictemplate" , {}).get ("spec" )
72
70
if ingress_options != {}:
73
71
for index , ingress_option in enumerate (ingress_options ["ingresses" ]):
74
72
if "ingressName" not in ingress_option .keys ():
75
- return ValueError (
73
+ raise ValueError (
76
74
f"Error: 'ingressName' is missing or empty for ingress item at index { index } "
77
75
)
78
76
if "port" not in ingress_option .keys ():
79
- return ValueError (
77
+ raise ValueError (
80
78
f"Error: 'port' is missing or empty for ingress item at index { index } "
81
79
)
82
80
elif not isinstance (ingress_option ["port" ], int ):
83
- return ValueError (
81
+ raise ValueError (
84
82
f"Error: 'port' is not of type int for ingress item at index { index } "
85
83
)
86
84
if ingress_option ["port" ] == 8265 :
@@ -105,7 +103,7 @@ def update_dashboard_ingress(
105
103
else :
106
104
spec ["rules" ][0 ]["host" ] = ingress_option ["host" ]
107
105
if "ingressClassName" not in ingress_option .keys ():
108
- ingress_options ["ingressClassName" ] = None
106
+ del spec ["ingressClassName" ]
109
107
else :
110
108
spec ["ingressClassName" ] = ingress_option ["ingressClassName" ]
111
109
@@ -125,6 +123,7 @@ def update_dashboard_ingress(
125
123
ingress = api_client .get_cluster_custom_object (
126
124
"config.openshift.io" , "v1" , "ingresses" , "cluster"
127
125
)
126
+ del spec ["ingressClassName" ]
128
127
except Exception as e : # pragma: no cover
129
128
return _kube_api_error_handling (e )
130
129
domain = ingress ["spec" ]["domain" ]
@@ -140,21 +139,21 @@ def update_dashboard_ingress(
140
139
141
140
def update_rayclient_ingress (
142
141
ingress_item , cluster_name , namespace , ingress_options , ingress_domain
143
- ):
142
+ ): # pragma: no cover
144
143
metadata = ingress_item .get ("generictemplate" , {}).get ("metadata" )
145
144
spec = ingress_item .get ("generictemplate" , {}).get ("spec" )
146
145
if ingress_options != {}:
147
146
for index , ingress_option in enumerate (ingress_options ["ingresses" ]):
148
147
if "ingressName" not in ingress_option .keys ():
149
- return ValueError (
148
+ raise ValueError (
150
149
f"Error: 'ingressName' is missing or empty for ingress item at index { index } "
151
150
)
152
151
if "port" not in ingress_option .keys ():
153
- return ValueError (
152
+ raise ValueError (
154
153
f"Error: 'port' is missing or empty for ingress item at index { index } "
155
154
)
156
155
elif not isinstance (ingress_option ["port" ], int ):
157
- return ValueError (
156
+ raise ValueError (
158
157
f"Error: 'port' is not of type int for ingress item at index { index } "
159
158
)
160
159
if ingress_option ["port" ] == 10001 :
@@ -179,7 +178,7 @@ def update_rayclient_ingress(
179
178
else :
180
179
spec ["rules" ][0 ]["host" ] = ingress_option ["host" ]
181
180
if "ingressClassName" not in ingress_option .keys ():
182
- ingress_option ["ingressClassName" ] = None
181
+ del spec ["ingressClassName" ]
183
182
else :
184
183
spec ["ingressClassName" ] = ingress_option ["ingressClassName" ]
185
184
@@ -457,23 +456,41 @@ def enable_local_interactive(
457
456
458
457
command = command .replace ("deployment-name" , cluster_name )
459
458
460
- if is_openshift_cluster ():
461
- # We can try get the domain through checking ingresses.config.openshift.io
462
- try :
463
- config_check ()
464
- api_client = client .CustomObjectsApi (api_config_handler ())
465
- ingress = api_client .get_cluster_custom_object (
466
- "config.openshift.io" , "v1" , "ingresses" , "cluster"
467
- )
468
- except Exception as e : # pragma: no cover
469
- return _kube_api_error_handling (e )
470
- domain = ingress ["spec" ]["domain" ]
471
- elif ingress_domain is None :
472
- raise ValueError (
473
- "ingress_domain is invalid. For Kubernetes Clusters please specify an ingress domain"
474
- )
459
+ if ingress_options != {}:
460
+ for index , ingress_option in enumerate (ingress_options ["ingresses" ]):
461
+ if ingress_option ["port" ] == 10001 :
462
+ if "host" not in ingress_option .keys ():
463
+ raise ValueError (
464
+ f"Client host is not specified please include a host for the ingress item at index { index } "
465
+ )
466
+ else :
467
+ host = ingress_option ["host" ]
468
+ domain_split = host .split ("." , 1 )
469
+ if len (domain_split ) > 1 :
470
+ domain = domain_split [1 ]
471
+ else :
472
+ raise ValueError (
473
+ f"The client ingress host is configured incorrectly please specify a host with a correct domain for the ingress item at index { index } "
474
+ )
475
+
475
476
else :
476
- domain = ingress_domain
477
+ if is_openshift_cluster ():
478
+ # We can try get the domain through checking ingresses.config.openshift.io
479
+ try :
480
+ config_check ()
481
+ api_client = client .CustomObjectsApi (api_config_handler ())
482
+ ingress = api_client .get_cluster_custom_object (
483
+ "config.openshift.io" , "v1" , "ingresses" , "cluster"
484
+ )
485
+ except Exception as e : # pragma: no cover
486
+ return _kube_api_error_handling (e )
487
+ domain = ingress ["spec" ]["domain" ]
488
+ elif ingress_domain is None :
489
+ raise ValueError (
490
+ "ingress_domain is invalid. For Kubernetes Clusters please specify an ingress domain"
491
+ )
492
+ else :
493
+ domain = ingress_domain
477
494
478
495
command = command .replace ("server-name" , domain )
479
496
update_rayclient_ingress (
0 commit comments