@@ -318,7 +318,7 @@ impl CNI for CNIConfig {
318
318
info ! ( "Successfully added network list: {}" , net. name) ;
319
319
320
320
// Return the final result
321
- Ok ( prev_result. unwrap_or_else ( || Box :: new ( result100:: Result :: default ( ) ) ) )
321
+ Ok ( prev_result. unwrap_or_else ( || Box :: < result100:: Result > :: default ( ) ) )
322
322
}
323
323
324
324
fn check_network_list ( & self , net : NetworkConfigList , rt : RuntimeConf ) -> ResultCNI < ( ) > {
@@ -336,7 +336,7 @@ impl CNI for CNIConfig {
336
336
Err ( e) => {
337
337
warn ! ( "No cached result found for network {}: {}" , net. name, e) ;
338
338
(
339
- Box :: new ( result100:: Result :: default ( ) ) as Box < dyn APIResult > ,
339
+ Box :: < result100:: Result > :: default ( ) as Box < dyn APIResult > ,
340
340
Vec :: new ( ) ,
341
341
rt. clone ( ) ,
342
342
)
@@ -485,64 +485,25 @@ impl CNI for CNIConfig {
485
485
self . exec
486
486
. exec_plugins ( plugin_path, & new_conf. bytes , environ. to_env ( ) ) ?;
487
487
488
- // Parse result
489
- let result_json: serde_json:: Value =
490
- serde_json:: from_slice ( & result_bytes) . map_err ( |e| {
491
- Box :: new ( CNIError :: VarDecode ( format ! (
492
- "Failed to parse result: {}" ,
488
+ // Directly deserialize the result JSON into the result structure
489
+ let mut result: result100:: Result = match serde_json:: from_slice ( & result_bytes) {
490
+ Ok ( r) => r,
491
+ Err ( e) => {
492
+ // If direct deserialization fails, create a default result with minimal information
493
+ debug ! (
494
+ "Failed to directly deserialize result: {}, creating minimal result" ,
493
495
e
494
- ) ) )
495
- } ) ?;
496
-
497
- // Create result object - this is the key modification point
498
- let mut result = result100:: Result :: default ( ) ;
499
- result. cni_version = Some ( cni_version) ;
500
-
501
- // Extract interface information from result
502
- if let Some ( interfaces) = result_json. get ( "interfaces" ) {
503
- if let Some ( interfaces_array) = interfaces. as_array ( ) {
504
- let interfaces_vec: Vec < result100:: Interface > = interfaces_array
505
- . iter ( )
506
- . filter_map ( |v| serde_json:: from_value ( v. clone ( ) ) . ok ( ) )
507
- . collect ( ) ;
508
- if !interfaces_vec. is_empty ( ) {
509
- result. interfaces = Some ( interfaces_vec) ;
510
- }
511
- }
512
- }
513
-
514
- // Extract IP information from result
515
- if let Some ( ips) = result_json. get ( "ips" ) {
516
- if let Some ( ips_array) = ips. as_array ( ) {
517
- let ips_vec: Vec < result100:: IPConfig > = ips_array
518
- . iter ( )
519
- . filter_map ( |v| serde_json:: from_value ( v. clone ( ) ) . ok ( ) )
520
- . collect ( ) ;
521
- if !ips_vec. is_empty ( ) {
522
- result. ips = Some ( ips_vec) ;
523
- debug ! ( "Network has IPs: {:?}" , ips) ;
524
- }
525
- }
526
- }
527
-
528
- // Extract route information from result
529
- if let Some ( routes) = result_json. get ( "routes" ) {
530
- if let Some ( routes_array) = routes. as_array ( ) {
531
- let routes_vec: Vec < super :: types:: Route > = routes_array
532
- . iter ( )
533
- . filter_map ( |v| serde_json:: from_value ( v. clone ( ) ) . ok ( ) )
534
- . collect ( ) ;
535
- if !routes_vec. is_empty ( ) {
536
- result. routes = Some ( routes_vec) ;
496
+ ) ;
497
+ result100:: Result {
498
+ cni_version : Some ( cni_version. clone ( ) ) ,
499
+ ..Default :: default ( )
537
500
}
538
501
}
539
- }
540
-
541
- // Extract DNS information from result
542
- if let Some ( dns) = result_json. get ( "dns" ) {
543
- if let Ok ( dns_config) = serde_json:: from_value :: < super :: types:: DNS > ( dns. clone ( ) ) {
544
- result. dns = Some ( dns_config) ;
545
- }
502
+ } ;
503
+
504
+ // Ensure CNI version is set
505
+ if result. cni_version . is_none ( ) {
506
+ result. cni_version = Some ( cni_version) ;
546
507
}
547
508
548
509
debug ! ( "Successfully added network {}" , name) ;
0 commit comments