home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

1_11.patch (7375B)


      1 From 8250d730f31f2ff995b06b7c404d2682dea62402 Mon Sep 17 00:00:00 2001
      2 From: Vincent Demeester <vincent@sbr.pm>
      3 Date: Fri, 5 Jun 2020 12:09:52 +0200
      4 Subject: [PATCH] crc: adapt for nixos
      5 
      6 Signed-off-by: Vincent Demeester <vincent@sbr.pm>
      7 ---
      8  pkg/crc/cache/cache.go                      |  3 +
      9  pkg/crc/constants/constants_linux.go        |  2 +-
     10  pkg/crc/machine/libvirt/constants.go        |  2 +-
     11  pkg/crc/oc/oc.go                            |  6 +-
     12  pkg/crc/preflight/preflight_checks_linux.go | 84 ++++++++++++---------
     13  5 files changed, 57 insertions(+), 40 deletions(-)
     14 
     15 diff --git a/pkg/crc/cache/cache.go b/pkg/crc/cache/cache.go
     16 index 72a5bab..e60aa05 100644
     17 --- a/pkg/crc/cache/cache.go
     18 +++ b/pkg/crc/cache/cache.go
     19 @@ -37,6 +37,9 @@ func NewGoodhostsCache(destDir string) *Cache {
     20  }
     21  
     22  func (c *Cache) IsCached() bool {
     23 +	if filepath.IsAbs(c.binaryName) {
     24 +		return true
     25 +	}
     26  	if _, err := os.Stat(filepath.Join(c.destDir, c.binaryName)); os.IsNotExist(err) {
     27  		return false
     28  	}
     29 diff --git a/pkg/crc/constants/constants_linux.go b/pkg/crc/constants/constants_linux.go
     30 index 0323d5e..0184239 100644
     31 --- a/pkg/crc/constants/constants_linux.go
     32 +++ b/pkg/crc/constants/constants_linux.go
     33 @@ -1,6 +1,6 @@
     34  package constants
     35  
     36 -const (
     37 +var (
     38  	OcBinaryName        = "oc"
     39  	PodmanBinaryName    = "podman"
     40  	GoodhostsBinaryName = "goodhosts"
     41 diff --git a/pkg/crc/machine/libvirt/constants.go b/pkg/crc/machine/libvirt/constants.go
     42 index a3b5807..a95a020 100644
     43 --- a/pkg/crc/machine/libvirt/constants.go
     44 +++ b/pkg/crc/machine/libvirt/constants.go
     45 @@ -16,10 +16,10 @@ const (
     46  )
     47  
     48  const (
     49 -	MachineDriverCommand = "crc-driver-libvirt"
     50  	MachineDriverVersion = "0.12.8"
     51  )
     52  
     53  var (
     54 +	MachineDriverCommand     = "crc-driver-libvirt"
     55  	MachineDriverDownloadUrl = fmt.Sprintf("https://github.com/code-ready/machine-driver-libvirt/releases/download/%s/crc-driver-libvirt", MachineDriverVersion)
     56  )
     57 diff --git a/pkg/crc/oc/oc.go b/pkg/crc/oc/oc.go
     58 index 9b688e9..cdfaf6f 100644
     59 --- a/pkg/crc/oc/oc.go
     60 +++ b/pkg/crc/oc/oc.go
     61 @@ -43,8 +43,12 @@ func (oc OcLocalRunner) GetKubeconfigPath() string {
     62  
     63  // UseOcWithConfig return the oc binary along with valid kubeconfig
     64  func UseOCWithConfig(machineName string) OcConfig {
     65 +	ocBinaryPath := filepath.Join(constants.CrcBinDir, constants.OcBinaryName)
     66 +	if filepath.IsAbs(constants.OcBinaryName) {
     67 +		ocBinaryPath = constants.OcBinaryName
     68 +	}
     69  	localRunner := OcLocalRunner{
     70 -		OcBinaryPath:   filepath.Join(constants.CrcOcBinDir, constants.OcBinaryName),
     71 +		OcBinaryPath:   ocBinaryPath,
     72  		KubeconfigPath: filepath.Join(constants.MachineInstanceDir, machineName, "kubeconfig"),
     73  	}
     74  	return NewOcConfig(localRunner, constants.DefaultContext, constants.DefaultName)
     75 diff --git a/pkg/crc/preflight/preflight_checks_linux.go b/pkg/crc/preflight/preflight_checks_linux.go
     76 index 14c987b..93bf418 100644
     77 --- a/pkg/crc/preflight/preflight_checks_linux.go
     78 +++ b/pkg/crc/preflight/preflight_checks_linux.go
     79 @@ -116,18 +116,18 @@ func fixLibvirtInstalled() error {
     80  func checkLibvirtEnabled() error {
     81  	logging.Debug("Checking if libvirtd.service is enabled")
     82  	// check if libvirt service is enabled
     83 -	path, err := exec.LookPath("systemctl")
     84 -	if err != nil {
     85 -		return fmt.Errorf("systemctl not found on path: %s", err.Error())
     86 -	}
     87 -	stdOut, _, err := crcos.RunWithDefaultLocale(path, "is-enabled", "libvirtd")
     88 -	if err != nil {
     89 -		return fmt.Errorf("Error checking if libvirtd service is enabled")
     90 -	}
     91 -	if strings.TrimSpace(stdOut) != "enabled" {
     92 -		return fmt.Errorf("libvirtd.service is not enabled")
     93 -	}
     94 -	logging.Debug("libvirtd.service is already enabled")
     95 +	// path, err := exec.LookPath("systemctl")
     96 +	// if err != nil {
     97 +	// 	return fmt.Errorf("systemctl not found on path: %s", err.Error())
     98 +	// }
     99 +	// stdOut, _, err := crcos.RunWithDefaultLocale(path, "is-enabled", "libvirtd")
    100 +	// if err != nil {
    101 +	// 	return fmt.Errorf("Error checking if libvirtd service is enabled: %s", err)
    102 +	// }
    103 +	// if strings.TrimSpace(stdOut) != "enabled" && strings.TrimSpace(stdOut) != "linked" {
    104 +	// 	return fmt.Errorf("libvirtd.service is not enabled")
    105 +	// }
    106 +	// logging.Debug("libvirtd.service is already enabled")
    107  	return nil
    108  }
    109  
    110 @@ -212,17 +212,17 @@ func fixUserPartOfLibvirtGroup() error {
    111  
    112  func checkLibvirtServiceRunning() error {
    113  	logging.Debug("Checking if libvirtd.service is running")
    114 -	path, err := exec.LookPath("systemctl")
    115 -	if err != nil {
    116 -		return err
    117 -	}
    118 -	stdOut, _, err := crcos.RunWithDefaultLocale(path, "is-active", "libvirtd")
    119 -	if err != nil {
    120 -		return fmt.Errorf("Failed to check if libvirtd service is active")
    121 -	}
    122 -	if strings.TrimSpace(stdOut) != "active" {
    123 -		return fmt.Errorf("libvirtd.service is not running")
    124 -	}
    125 +	// path, err := exec.LookPath("systemctl")
    126 +	// if err != nil {
    127 +	// 	return err
    128 +	// }
    129 +	// stdOut, _, err := crcos.RunWithDefaultLocale(path, "is-active", "libvirtd")
    130 +	// if err != nil {
    131 +	// 	return fmt.Errorf("Failed to check if libvirtd service is active")
    132 +	// }
    133 +	// if strings.TrimSpace(stdOut) != "active" {
    134 +	// 	return fmt.Errorf("libvirtd.service is not running")
    135 +	// }
    136  	logging.Debug("libvirtd.service is already running")
    137  	return nil
    138  }
    139 @@ -246,6 +246,16 @@ func checkMachineDriverLibvirtInstalled() error {
    140  
    141  	// Check if crc-driver-libvirt is available
    142  	libvirtDriverPath := filepath.Join(constants.CrcBinDir, libvirt.MachineDriverCommand)
    143 +	if filepath.IsAbs(libvirt.MachineDriverCommand) {
    144 +		libvirtDriverPath = filepath.Join(constants.CrcBinDir, "crc-driver-libvirt")
    145 +
    146 +		err := unix.Access(libvirtDriverPath, unix.X_OK)
    147 +		if err != nil {
    148 +			if _, _, err := crcos.RunWithDefaultLocale("ln", "-s", libvirt.MachineDriverCommand, libvirtDriverPath); err != nil {
    149 +				return fmt.Errorf("%s symbolic link to %s failed", libvirt.MachineDriverCommand, libvirtDriverPath)
    150 +			}
    151 +		}
    152 +	}
    153  	err := unix.Access(libvirtDriverPath, unix.X_OK)
    154  	if err != nil {
    155  		return fmt.Errorf("%s is not executable", libvirtDriverPath)
    156 @@ -552,20 +562,20 @@ func removeCrcDnsmasqConfigFile() error {
    157  }
    158  
    159  func checkCrcNetworkManagerConfig() error {
    160 -	logging.Debug("Checking NetworkManager configuration")
    161 -	c := []byte(crcNetworkManagerConfig)
    162 -	_, err := os.Stat(crcNetworkManagerConfigPath)
    163 -	if err != nil {
    164 -		return fmt.Errorf("File not found: %s: %s", crcNetworkManagerConfigPath, err.Error())
    165 -	}
    166 -	config, err := ioutil.ReadFile(filepath.Clean(crcNetworkManagerConfigPath))
    167 -	if err != nil {
    168 -		return fmt.Errorf("Error opening file: %s: %s", crcNetworkManagerConfigPath, err.Error())
    169 -	}
    170 -	if !bytes.Equal(config, c) {
    171 -		return fmt.Errorf("Config file contains changes: %s", crcNetworkManagerConfigPath)
    172 -	}
    173 -	logging.Debug("NetworkManager configuration is good")
    174 +	// logging.Debug("Checking NetworkManager configuration")
    175 +	// c := []byte(crcNetworkManagerConfig)
    176 +	// _, err := os.Stat(crcNetworkManagerConfigPath)
    177 +	// if err != nil {
    178 +	// 	return fmt.Errorf("File not found: %s: %s", crcNetworkManagerConfigPath, err.Error())
    179 +	// }
    180 +	// config, err := ioutil.ReadFile(filepath.Clean(crcNetworkManagerConfigPath))
    181 +	// if err != nil {
    182 +	// 	return fmt.Errorf("Error opening file: %s: %s", crcNetworkManagerConfigPath, err.Error())
    183 +	// }
    184 +	// if !bytes.Equal(config, c) {
    185 +	// 	return fmt.Errorf("Config file contains changes: %s", crcNetworkManagerConfigPath)
    186 +	// }
    187 +	// logging.Debug("NetworkManager configuration is good")
    188  	return nil
    189  }
    190  
    191 -- 
    192 2.26.2
    193