Skip to content

Commit 3dc5186

Browse files
Check if the default-address symlink needs to be updated
1 parent 2747cde commit 3dc5186

File tree

1 file changed

+19
-13
lines changed
  • rust/operator-binary/src/csi_server

1 file changed

+19
-13
lines changed

rust/operator-binary/src/csi_server/node.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -592,19 +592,25 @@ mod pod_dir {
592592
default_addr_dir.get_or_insert(addr_dir);
593593
}
594594

595-
let default_addr_link = target_path.join("default-address");
596-
// Remove any existing symlink because `tokio::fs::symlink` fails if it already exists.
597-
// This happens if the node was restarted. The pod then restarts with the same UID and
598-
// the pre-populated volume.
599-
let _ = tokio::fs::remove_file(&default_addr_link).await;
600-
tokio::fs::symlink(
601-
default_addr_dir
602-
.context(NoDefaultAddressSnafu)?
603-
.strip_prefix(target_path)
604-
.context(DefaultAddrIsOutsideRootSnafu)?,
605-
&default_addr_link,
606-
)
607-
.await?;
595+
let relative_default_addr_dir = default_addr_dir
596+
.context(NoDefaultAddressSnafu)?
597+
.strip_prefix(target_path)
598+
.context(DefaultAddrIsOutsideRootSnafu)?
599+
.to_owned();
600+
let default_addr_dir_link = target_path.join("default-address");
601+
// Check if the symlink needs to be updated
602+
if tokio::fs::read_link(&default_addr_dir_link)
603+
.await
604+
.ok()
605+
.as_ref()
606+
!= Some(&relative_default_addr_dir)
607+
{
608+
// Remove any existing symlink because `tokio::fs::symlink` fails if it already exists.
609+
// This happens if the node was restarted. The pod then restarts with the same UID and
610+
// the pre-populated volume.
611+
let _ = tokio::fs::remove_file(&default_addr_dir_link).await;
612+
tokio::fs::symlink(relative_default_addr_dir, &default_addr_dir_link).await?;
613+
}
608614
Ok(())
609615
}
610616
}

0 commit comments

Comments
 (0)