Skip to content

Commit 0d4de48

Browse files
authored
Merge pull request #11 from appsignal/fix/inject-resolv-conf
Inject /etc/resolv.conf into VM rootfs to fix DNS failure cycling
2 parents a03c5b3 + 380b566 commit 0d4de48

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

manager/src/inject.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ MACAddress={guest_mac}
3333
[Network]
3434
Address={client_ip}/30
3535
Gateway={host_ip}
36+
DNS=1.1.1.1
3637
"#;
3738

39+
const RESOLV_CONF: &str = "nameserver 1.1.1.1\noptions use-vc\n";
40+
3841
/// Inject runner.service, eth.network, and service symlink into a mounted rootfs.
3942
#[instrument(skip(network), fields(mount_point = %mount_point, runner_name, role))]
4043
pub fn inject_config(
@@ -47,6 +50,7 @@ pub fn inject_config(
4750
) -> Result<()> {
4851
inject_runner_service(mount_point, github_org, github_token, runner_name, labels)?;
4952
inject_network_config(mount_point, network)?;
53+
inject_resolv_conf(mount_point)?;
5054
enable_runner_service(mount_point)?;
5155
Ok(())
5256
}
@@ -94,6 +98,14 @@ fn inject_network_config(mount_point: &Utf8Path, network: &NetworkAllocation) ->
9498
Ok(())
9599
}
96100

101+
fn inject_resolv_conf(mount_point: &Utf8Path) -> Result<()> {
102+
let resolv_path = mount_point.join("etc/resolv.conf");
103+
fs::write(&resolv_path, RESOLV_CONF)
104+
.with_context(|| format!("failed to write {}", resolv_path))?;
105+
info!(path = %resolv_path, "injected resolv.conf");
106+
Ok(())
107+
}
108+
97109
fn enable_runner_service(mount_point: &Utf8Path) -> Result<()> {
98110
let wants_dir = mount_point.join("etc/systemd/system/multi-user.target.wants");
99111
fs::create_dir_all(&wants_dir).with_context(|| format!("failed to create {}", wants_dir))?;

0 commit comments

Comments
 (0)