@@ -25,6 +25,15 @@ pub(crate) async fn rename_all_dual_stack(
2525 . await
2626 . context ( "extracting original dual-stack IPs" ) ?;
2727
28+ ensure ! (
29+ original_ips. len( ) == ips. len( ) ,
30+ "original IPs count ({}) must equal new IPs count ({})" ,
31+ original_ips. len( ) ,
32+ ips. len( )
33+ ) ;
34+
35+ log:: info!( "Applying dual-stack IP changes" ) ;
36+
2837 fix_etcd_resources_dual_stack ( etcd_client, & original_ips, ips)
2938 . await
3039 . context ( "modifying etcd resources for dual stack" ) ?;
@@ -73,15 +82,11 @@ async fn fix_dir_resources(original_ip: &str, ip: &str, dir: &Path) -> Result<()
7382}
7483
7584async 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) ) ?;
80-
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) ) ?;
85+ for ( idx, ( original_ip, new_ip) ) in original_ips. iter ( ) . zip ( ips. iter ( ) ) . enumerate ( ) {
86+ filesystem_rename:: fix_filesystem_ip ( original_ip, new_ip, dir)
87+ . await
88+ . context ( format ! ( "fix filesystem IP replacement pair {} in {:?}" , idx, dir) ) ?;
89+ }
8590
8691 Ok ( ( ) )
8792}
@@ -181,31 +186,12 @@ async fn extract_original_dual_stack_ips(etcd_client: &Arc<InMemoryK8sEtcd>) ->
181186}
182187
183188async 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
196- ) ;
197-
198- log:: info!( "Applying IPv4 replacements: {} → {}" , original_ipv4, new_ipv4) ;
199-
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" ) ?;
189+ for ( idx, ( original_ip, new_ip) ) in original_ips. iter ( ) . zip ( new_ips. iter ( ) ) . enumerate ( ) {
190+ log:: info!( "Applying replacements pair {}: {} → {}" , idx, original_ip, new_ip) ;
191+ fix_etcd_resources_for_ip_pair ( etcd_client, original_ip, new_ip)
192+ . await
193+ . context ( format ! ( "applying etcd resource fixes for pair {}" , idx) ) ?;
194+ }
209195
210196 Ok ( ( ) )
211197}
0 commit comments