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 6, 2024
1 parent 3956e85 commit 279f144
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 @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.20)

package slices is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / build (windows-2019, 1.20)

package slices is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.14\x64\src\slices)

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / Run OKD bundle with crc (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / build (macOS-12, 1.20)

package slices is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.20)

package slices is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.14\x64\src\slices)

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in pkg/crc/preflight/preflight_checks_network_linux.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/crc-org/crc/v2/pkg/crc/systemd"
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`
systemdResolvedManageResolveFilePath := []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("resolve conf file path: %s", rFilePath)
if err != nil {
return err
}
if !slices.Contains(systemdResolvedManageResolveFilePath, rFilePath) {
return fmt.Errorf("%s not managed by systemd-resolved", resolvFilePath)
}
return checkSystemdServiceRunning("systemd-resolved.service")
}

Expand Down

0 comments on commit 279f144

Please sign in to comment.