@@ -73,15 +73,18 @@ async fn fix_dir_resources(original_ip: &str, ip: &str, dir: &Path) -> Result<()
7373}
7474
7575async fn fix_dir_resources_dual_stack ( original_ips : & [ String ] , ips : & [ String ] , dir : & Path ) -> Result < ( ) > {
76- // Apply IPv4 replacement (original IPv4 → new IPv4)
77- filesystem_rename:: fix_filesystem_ip ( & original_ips[ 0 ] , & ips[ 0 ] , dir)
78- . await
79- . context ( format ! ( "fix filesystem IPv4 in {:?}" , dir) ) ?;
76+ ensure ! (
77+ original_ips. len( ) == ips. len( ) ,
78+ "original IPs count ({}) must equal new IPs count ({})" ,
79+ original_ips. len( ) ,
80+ ips. len( )
81+ ) ;
8082
81- // Apply IPv6 replacement (original IPv6 → new IPv6) - both are guaranteed to be present
82- filesystem_rename:: fix_filesystem_ip ( & original_ips[ 1 ] , & ips[ 1 ] , dir)
83- . await
84- . context ( format ! ( "fix filesystem IPv6 in {:?}" , dir) ) ?;
83+ for ( idx, ( original_ip, new_ip) ) in original_ips. iter ( ) . zip ( ips. iter ( ) ) . enumerate ( ) {
84+ filesystem_rename:: fix_filesystem_ip ( original_ip, new_ip, dir)
85+ . await
86+ . context ( format ! ( "fix filesystem IP replacement pair {} in {:?}" , idx, dir) ) ?;
87+ }
8588
8689 Ok ( ( ) )
8790}
@@ -181,31 +184,22 @@ async fn extract_original_dual_stack_ips(etcd_client: &Arc<InMemoryK8sEtcd>) ->
181184}
182185
183186async fn fix_etcd_resources_dual_stack ( etcd_client : & Arc < InMemoryK8sEtcd > , original_ips : & [ String ] , new_ips : & [ String ] ) -> Result < ( ) > {
184- let original_ipv4 = & original_ips[ 0 ] ;
185- let original_ipv6 = & original_ips[ 1 ] ;
186-
187- let new_ipv4 = & new_ips[ 0 ] ;
188- let new_ipv6 = new_ips. get ( 1 ) . context ( "Second IP (IPv6) is required for dual-stack processing" ) ?;
189-
190- log:: info!(
191- "Applying dual-stack IP changes - IPv4: {} → {}, IPv6: {} → {}" ,
192- original_ipv4,
193- new_ipv4,
194- original_ipv6,
195- new_ipv6
187+ ensure ! ( !original_ips. is_empty( ) , "at least one original IP is required" ) ;
188+ ensure ! (
189+ original_ips. len( ) == new_ips. len( ) ,
190+ "original IPs count ({}) must equal new IPs count ({})" ,
191+ original_ips. len( ) ,
192+ new_ips. len( )
196193 ) ;
197194
198- log:: info!( "Applying IPv4 replacements: {} → {}" , original_ipv4 , new_ipv4 ) ;
195+ log:: info!( "Applying dual-stack IP changes" ) ;
199196
200- fix_etcd_resources_for_ip_pair ( etcd_client, original_ipv4, new_ipv4)
201- . await
202- . context ( "applying IPv4 etcd resource fixes" ) ?;
203-
204- log:: info!( "Applying IPv6 replacements: {} → {}" , original_ipv6, new_ipv6) ;
205-
206- fix_etcd_resources_for_ip_pair ( etcd_client, original_ipv6, new_ipv6)
207- . await
208- . context ( "applying IPv6 etcd resource fixes" ) ?;
197+ for ( idx, ( original_ip, new_ip) ) in original_ips. iter ( ) . zip ( new_ips. iter ( ) ) . enumerate ( ) {
198+ log:: info!( "Applying replacements pair {}: {} → {}" , idx, original_ip, new_ip) ;
199+ fix_etcd_resources_for_ip_pair ( etcd_client, original_ip, new_ip)
200+ . await
201+ . context ( format ! ( "applying etcd resource fixes for pair {}" , idx) ) ?;
202+ }
209203
210204 Ok ( ( ) )
211205}
0 commit comments