Skip to content

Conversation

@frhuelsz
Copy link
Contributor

🔍 Description

Fix #272

Check if directory exists before attempting to create file.

@frhuelsz frhuelsz requested a review from a team as a code owner October 16, 2025 20:30
Copilot AI review requested due to automatic review settings October 16, 2025 20:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Purpose: Fix bug where cloud-init networking disable file creation fails if the target directory is absent by adding a directory existence check and adjusting path handling.

  • Add explicit CLOUD_INIT_CONFIG_DIR constant and split full path into dir + filename.
  • Check for existence of the config directory before attempting to write, and build the file path with Path::join.
  • Update logging around skip and disable actions.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


fn disable_cloud_init_networking() -> Result<(), TridentError> {
fs::write(CLOUD_INIT_DISABLE_FILE, CLOUD_INIT_DISABLE_CONTENT)
let cloud_init_disable_path = Path::new(CLOUD_INIT_CONFIG_DIR).join(CLOUD_INIT_DISABLE_FILE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You could move this further down post the check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

fn disable_cloud_init_networking() -> Result<(), TridentError> {
fs::write(CLOUD_INIT_DISABLE_FILE, CLOUD_INIT_DISABLE_CONTENT)
let cloud_init_disable_path = Path::new(CLOUD_INIT_CONFIG_DIR).join(CLOUD_INIT_DISABLE_FILE);
if !Path::new(CLOUD_INIT_CONFIG_DIR).exists() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is sufficient to address this bug, but should we have a better handling re package presence detection in general? We could use the cosi manifest now, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supposedly yes, but i think i want to add some cleaner interfaces for that before we cross that bridge

}
}

fn disable_cloud_init_networking() -> Result<(), TridentError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add a few UTs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copilot AI review requested due to automatic review settings October 17, 2025 21:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +45 to +54
if !config_dir.as_ref().exists() {
debug!(
"Cloud-init config dir {} does not exist, skipping disabling cloud-init networking",
config_dir.as_ref().display()
);
return Ok(());
}

debug!("Disabling cloud-init networking");
let cloud_init_disable_path = config_dir.as_ref().join(CLOUD_INIT_DISABLE_FILE);
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] config_dir.as_ref() is called multiple times; storing it in a local variable (e.g., let config_dir = config_dir.as_ref();) would improve readability and avoid repetition.

Suggested change
if !config_dir.as_ref().exists() {
debug!(
"Cloud-init config dir {} does not exist, skipping disabling cloud-init networking",
config_dir.as_ref().display()
);
return Ok(());
}
debug!("Disabling cloud-init networking");
let cloud_init_disable_path = config_dir.as_ref().join(CLOUD_INIT_DISABLE_FILE);
let config_dir = config_dir.as_ref();
if !config_dir.exists() {
debug!(
"Cloud-init config dir {} does not exist, skipping disabling cloud-init networking",
config_dir.display()
);
return Ok(());
}
debug!("Disabling cloud-init networking");
let cloud_init_disable_path = config_dir.join(CLOUD_INIT_DISABLE_FILE);

Copilot uses AI. Check for mistakes.
@frhuelsz frhuelsz merged commit 5111573 into main Oct 20, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trident fails to disable cloud-init networking with cloud-init package is missing

4 participants