Skip to content

Commit

Permalink
preflight-linux: Add logic to check if /etc/resolv.conf managed by sy…
Browse files Browse the repository at this point in the history
…stemd-resolved

Current logic checks if systemd-resolved service is running and add the
dispatcher file to network manager config which uses `systemd-resolve`
to update the domain and dns for `crc` interface. But it is observed
that the dispatcher is called when the NM interface changes state,
but then the resolvectl call it contains has no effect on DNS
resolution as systemd-resolved does not manage /etc/resolv.conf.

This PR add logic to check if `/etc/resolv.conf` actually managed by
systemd-resolved and if not then use `dnsmasq` configuration which
works as expected.
  • Loading branch information
praveenkumar committed May 7, 2024
1 parent 3956e85 commit 75b9141
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/crc/preflight/preflight_checks_network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/crc-org/crc/v2/pkg/crc/systemd"
"github.com/crc-org/crc/v2/pkg/crc/systemd/states"
crcos "github.com/crc-org/crc/v2/pkg/os"
crcstring "github.com/crc-org/crc/v2/pkg/strings"
)

var nmPreflightChecks = []Check{
Expand Down Expand Up @@ -275,6 +276,20 @@ func checkNetworkManagerIsRunning() error {
}

func checkSystemdResolvedIsRunning() error {
resolvFilePath := "/etc/resolv.conf"
// Check /ETC/RESOLV.CONF section in `man systemd-resolved`
systemdResolvedManageResolvFilePath := []string{"/run/systemd/resolve/stub-resolv.conf",
"/usr/lib/systemd/resolv.conf",
"/run/systemd/resolve/resolv.conf"}
// Check if /etc/resolv.conf is managed by systemd-resolved
rFilePath, err := filepath.EvalSymlinks(resolvFilePath)
logging.Debugf("resolv.conf file path: %s", rFilePath)
if err != nil {
return err
}
if !crcstring.Contains(systemdResolvedManageResolvFilePath, rFilePath) {
return fmt.Errorf("%s is not managed by systemd-resolved", resolvFilePath)
}
return checkSystemdServiceRunning("systemd-resolved.service")
}

Expand Down

0 comments on commit 75b9141

Please sign in to comment.