Skip to content

Commit

Permalink
preflight: Move network related var/const to appropriate file
Browse files Browse the repository at this point in the history
This uses this code movement as an opportunity to rework how the
paths/filenames are generated, `/etc/NetworkManager/` can be shared
between the dnsmasq and NM configuration paths, and the name of the
files is only used once, so it does not need to be a separate constant.
  • Loading branch information
cfergeau authored and praveenkumar committed Dec 3, 2020
1 parent 04e57eb commit a410165
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 0 additions & 13 deletions pkg/crc/preflight/preflight_checks_linux.go
Expand Up @@ -24,23 +24,10 @@ import (
)

const (
crcDnsmasqConfigFile = "crc.conf"
crcNetworkManagerConfigFile = "crc-nm-dnsmasq.conf"
// This is defined in https://github.com/code-ready/machine-driver-libvirt/blob/master/go.mod#L5
minSupportedLibvirtVersion = "3.4.0"
)

var (
crcDnsmasqConfigPath = filepath.Join(string(filepath.Separator), "etc", "NetworkManager", "dnsmasq.d", crcDnsmasqConfigFile)
crcDnsmasqConfig = `server=/apps-crc.testing/192.168.130.11
server=/crc.testing/192.168.130.11
`
crcNetworkManagerConfigPath = filepath.Join(string(filepath.Separator), "etc", "NetworkManager", "conf.d", crcNetworkManagerConfigFile)
crcNetworkManagerConfig = `[main]
dns=dnsmasq
`
)

func checkVirtualizationEnabled() error {
logging.Debug("Checking if the vmx/svm flags are present in /proc/cpuinfo")
// Check if the cpu flags vmx or svm is present
Expand Down
15 changes: 15 additions & 0 deletions pkg/crc/preflight/preflight_checks_network_linux.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/pkg/crc/systemd"
Expand Down Expand Up @@ -51,6 +52,20 @@ var dnsmasqPreflightChecks = [...]Check{
},
}

var (
crcNetworkManagerRootPath = filepath.Join(string(filepath.Separator), "etc", "NetworkManager")

crcDnsmasqConfigPath = filepath.Join(crcNetworkManagerRootPath, "dnsmasq.d", "crc.conf")
crcDnsmasqConfig = `server=/apps-crc.testing/192.168.130.11
server=/crc.testing/192.168.130.11
`

crcNetworkManagerConfigPath = filepath.Join(crcNetworkManagerRootPath, "conf.d", "crc-nm-dnsmasq.conf")
crcNetworkManagerConfig = `[main]
dns=dnsmasq
`
)

func fixNetworkManagerConfigFile(path string, content string, perms os.FileMode) error {
err := crcos.WriteToFileAsRoot(
fmt.Sprintf("write NetworkManager configuration to %s", path),
Expand Down

0 comments on commit a410165

Please sign in to comment.