@@ -9,6 +9,9 @@ use std::{
9
9
time:: Duration ,
10
10
} ;
11
11
12
+ #[ cfg( test) ]
13
+ mod tests;
14
+
12
15
#[ cfg( not( test) ) ]
13
16
use anyhow:: bail;
14
17
use aws_config:: { BehaviorVersion , Region } ;
@@ -191,7 +194,7 @@ struct ConfigPath {
191
194
#[ serde( rename_all = "kebab-case" , deny_unknown_fields) ]
192
195
struct DaftConfig {
193
196
setup : DaftSetup ,
194
- #[ serde( rename = "job" , deserialize_with = "parse_jobs" ) ]
197
+ #[ serde( default , rename = "job" , deserialize_with = "parse_jobs" ) ]
195
198
jobs : HashMap < StrRef , DaftJob > ,
196
199
}
197
200
@@ -243,7 +246,8 @@ struct AwsConfig {
243
246
#[ derive( Debug , Deserialize , Clone , PartialEq , Eq ) ]
244
247
#[ serde( rename_all = "kebab-case" , deny_unknown_fields) ]
245
248
struct K8sConfig {
246
- namespace : Option < StrRef > ,
249
+ #[ serde( default = "default_k8s_namespace" ) ]
250
+ namespace : StrRef ,
247
251
}
248
252
249
253
fn parse_jobs < ' de , D > ( deserializer : D ) -> Result < HashMap < StrRef , DaftJob > , D :: Error >
@@ -323,6 +327,10 @@ fn default_image_id() -> StrRef {
323
327
"ami-04dd23e62ed049936" . into ( )
324
328
}
325
329
330
+ fn default_k8s_namespace ( ) -> StrRef {
331
+ "default" . into ( )
332
+ }
333
+
326
334
fn parse_version_req < ' de , D > ( deserializer : D ) -> Result < VersionReq , D :: Error >
327
335
where
328
336
D : serde:: Deserializer < ' de > ,
@@ -344,9 +352,7 @@ where
344
352
#[ derive( Debug , Deserialize , Clone , PartialEq , Eq ) ]
345
353
#[ serde( rename_all = "kebab-case" , deny_unknown_fields) ]
346
354
enum DaftProvider {
347
- #[ serde( rename = "provisioned" ) ]
348
355
Provisioned ,
349
- #[ serde( rename = "byoc" ) ]
350
356
Byoc ,
351
357
}
352
358
@@ -862,8 +868,39 @@ impl Drop for PortForward {
862
868
}
863
869
}
864
870
865
- async fn establish_kubernetes_port_forward ( namespace : Option < & str > ) -> anyhow:: Result < PortForward > {
866
- let namespace = namespace. unwrap_or ( "default" ) ;
871
+ async fn submit_k8s (
872
+ working_dir : & Path ,
873
+ command_segments : impl AsRef < [ & str ] > ,
874
+ namespace : & str ,
875
+ ) -> anyhow:: Result < ( ) > {
876
+ let command_segments = command_segments. as_ref ( ) ;
877
+
878
+ // Start port forwarding - it will be automatically killed when _port_forward is dropped
879
+ let _port_forward = establish_kubernetes_port_forward ( namespace) . await ?;
880
+
881
+ // Give the port-forward a moment to fully establish
882
+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
883
+
884
+ // Submit the job
885
+ let exit_status = Command :: new ( "ray" )
886
+ . env ( "PYTHONUNBUFFERED" , "1" )
887
+ . args ( [ "job" , "submit" , "--address" , "http://localhost:8265" ] )
888
+ . arg ( "--working-dir" )
889
+ . arg ( working_dir)
890
+ . arg ( "--" )
891
+ . args ( command_segments)
892
+ . spawn ( ) ?
893
+ . wait ( )
894
+ . await ?;
895
+
896
+ if exit_status. success ( ) {
897
+ Ok ( ( ) )
898
+ } else {
899
+ Err ( anyhow:: anyhow!( "Failed to submit job to the ray cluster" ) )
900
+ }
901
+ }
902
+
903
+ async fn establish_kubernetes_port_forward ( namespace : & str ) -> anyhow:: Result < PortForward > {
867
904
let output = Command :: new ( "kubectl" )
868
905
. arg ( "get" )
869
906
. arg ( "svc" )
@@ -923,38 +960,6 @@ async fn establish_kubernetes_port_forward(namespace: Option<&str>) -> anyhow::R
923
960
}
924
961
}
925
962
926
- async fn submit_k8s (
927
- working_dir : & Path ,
928
- command_segments : impl AsRef < [ & str ] > ,
929
- namespace : Option < & str > ,
930
- ) -> anyhow:: Result < ( ) > {
931
- let command_segments = command_segments. as_ref ( ) ;
932
-
933
- // Start port forwarding - it will be automatically killed when _port_forward is dropped
934
- let _port_forward = establish_kubernetes_port_forward ( namespace) . await ?;
935
-
936
- // Give the port-forward a moment to fully establish
937
- tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
938
-
939
- // Submit the job
940
- let exit_status = Command :: new ( "ray" )
941
- . env ( "PYTHONUNBUFFERED" , "1" )
942
- . args ( [ "job" , "submit" , "--address" , "http://localhost:8265" ] )
943
- . arg ( "--working-dir" )
944
- . arg ( working_dir)
945
- . arg ( "--" )
946
- . args ( command_segments)
947
- . spawn ( ) ?
948
- . wait ( )
949
- . await ?;
950
-
951
- if exit_status. success ( ) {
952
- Ok ( ( ) )
953
- } else {
954
- Err ( anyhow:: anyhow!( "Failed to submit job to the ray cluster" ) )
955
- }
956
- }
957
-
958
963
async fn run ( daft_launcher : DaftLauncher ) -> anyhow:: Result < ( ) > {
959
964
match daft_launcher. sub_command {
960
965
SubCommand :: Config ( config_cmd) => {
@@ -1063,7 +1068,7 @@ impl JobCommand {
1063
1068
submit_k8s (
1064
1069
daft_job. working_dir . as_ref ( ) ,
1065
1070
daft_job. command . as_ref ( ) . split ( ' ' ) . collect :: < Vec < _ > > ( ) ,
1066
- k8s_config. namespace . as_deref ( ) ,
1071
+ k8s_config. namespace . as_ref ( ) ,
1067
1072
)
1068
1073
. await ?;
1069
1074
}
@@ -1081,7 +1086,7 @@ impl JobCommand {
1081
1086
submit_k8s (
1082
1087
temp_sql_dir. path ( ) ,
1083
1088
vec ! [ "python" , "sql.py" , sql. as_ref( ) ] ,
1084
- k8s_config. namespace . as_deref ( ) ,
1089
+ k8s_config. namespace . as_ref ( ) ,
1085
1090
)
1086
1091
. await ?;
1087
1092
}
0 commit comments