1_9.patch (7385B)
1 From d9d8c0666fd8feb3a606bf960c16b212eb7a1db7 Mon Sep 17 00:00:00 2001 2 From: Vincent Demeester <vincent@sbr.pm> 3 Date: Wed, 13 May 2020 13:06:13 +0200 4 Subject: [PATCH] checkLibvirtEnabled: support linked too 5 6 Signed-off-by: Vincent Demeester <vincent@sbr.pm> 7 --- 8 pkg/crc/constants/constants_linux.go | 2 +- 9 pkg/crc/machine/libvirt/constants.go | 2 +- 10 pkg/crc/oc/oc.go | 6 +- 11 pkg/crc/oc/oc_cache.go | 3 + 12 pkg/crc/preflight/preflight_checks_linux.go | 84 ++++++++++++--------- 13 5 files changed, 57 insertions(+), 40 deletions(-) 14 15 diff --git a/pkg/crc/constants/constants_linux.go b/pkg/crc/constants/constants_linux.go 16 index 2598e34..26cf87a 100644 17 --- a/pkg/crc/constants/constants_linux.go 18 +++ b/pkg/crc/constants/constants_linux.go 19 @@ -1,6 +1,6 @@ 20 package constants 21 22 -const ( 23 +var ( 24 OcBinaryName = "oc" 25 PodmanBinaryName = "podman" 26 ) 27 diff --git a/pkg/crc/machine/libvirt/constants.go b/pkg/crc/machine/libvirt/constants.go 28 index 13b557a..dc3b3f3 100644 29 --- a/pkg/crc/machine/libvirt/constants.go 30 +++ b/pkg/crc/machine/libvirt/constants.go 31 @@ -16,10 +16,10 @@ const ( 32 ) 33 34 const ( 35 - MachineDriverCommand = "crc-driver-libvirt" 36 MachineDriverVersion = "0.12.7" 37 ) 38 39 var ( 40 + MachineDriverCommand = "crc-driver-libvirt" 41 MachineDriverDownloadUrl = fmt.Sprintf("https://github.com/code-ready/machine-driver-libvirt/releases/download/%s/crc-driver-libvirt", MachineDriverVersion) 42 ) 43 diff --git a/pkg/crc/oc/oc.go b/pkg/crc/oc/oc.go 44 index 5b7a552..cdfaf6f 100644 45 --- a/pkg/crc/oc/oc.go 46 +++ b/pkg/crc/oc/oc.go 47 @@ -43,8 +43,12 @@ func (oc OcLocalRunner) GetKubeconfigPath() string { 48 49 // UseOcWithConfig return the oc binary along with valid kubeconfig 50 func UseOCWithConfig(machineName string) OcConfig { 51 + ocBinaryPath := filepath.Join(constants.CrcBinDir, constants.OcBinaryName) 52 + if filepath.IsAbs(constants.OcBinaryName) { 53 + ocBinaryPath = constants.OcBinaryName 54 + } 55 localRunner := OcLocalRunner{ 56 - OcBinaryPath: filepath.Join(constants.CrcBinDir, constants.OcBinaryName), 57 + OcBinaryPath: ocBinaryPath, 58 KubeconfigPath: filepath.Join(constants.MachineInstanceDir, machineName, "kubeconfig"), 59 } 60 return NewOcConfig(localRunner, constants.DefaultContext, constants.DefaultName) 61 diff --git a/pkg/crc/oc/oc_cache.go b/pkg/crc/oc/oc_cache.go 62 index ecf6f63..4d0e6c9 100644 63 --- a/pkg/crc/oc/oc_cache.go 64 +++ b/pkg/crc/oc/oc_cache.go 65 @@ -29,6 +29,9 @@ func (oc *OcCached) EnsureIsCached() error { 66 } 67 68 func (oc *OcCached) IsCached() bool { 69 + if filepath.IsAbs(constants.OcBinaryName) { 70 + return true 71 + } 72 if _, err := os.Stat(filepath.Join(constants.CrcBinDir, constants.OcBinaryName)); os.IsNotExist(err) { 73 return false 74 } 75 diff --git a/pkg/crc/preflight/preflight_checks_linux.go b/pkg/crc/preflight/preflight_checks_linux.go 76 index ecb699a..2f119d1 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 @@ -550,20 +560,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