Commit e6f7337e9512

Vincent Demeester <vincent@sbr.pm>
2020-05-13 13:04:02
crc: make it smoother
No need to manually create the link, updated the patch for this. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent a889cad
pkgs/crc/0001-checkLibvirtEnabled-support-linked-too.patch
@@ -1,15 +1,79 @@
-From a78eaed094106e5acb5f1d872f8b12212a845d5b Mon Sep 17 00:00:00 2001
+From e6b235bf7c196eee68647dffb0d03b9197c6139b Mon Sep 17 00:00:00 2001
 From: Vincent Demeester <vincent@sbr.pm>
-Date: Tue, 12 May 2020 20:52:53 +0200
+Date: Wed, 13 May 2020 13:02:24 +0200
 Subject: [PATCH] checkLibvirtEnabled: support linked too
 
 Signed-off-by: Vincent Demeester <vincent@sbr.pm>
 ---
- pkg/crc/preflight/preflight_checks_linux.go | 74 ++++++++++-----------
- 1 file changed, 37 insertions(+), 37 deletions(-)
+ pkg/crc/constants/constants_linux.go        |  2 +-
+ pkg/crc/machine/libvirt/constants.go        |  2 +-
+ pkg/crc/oc/oc.go                            |  6 +-
+ pkg/crc/oc/oc_cache.go                      |  3 +
+ pkg/crc/preflight/preflight_checks_linux.go | 82 +++++++++++----------
+ 5 files changed, 55 insertions(+), 40 deletions(-)
 
+diff --git a/pkg/crc/constants/constants_linux.go b/pkg/crc/constants/constants_linux.go
+index 2598e34..26cf87a 100644
+--- a/pkg/crc/constants/constants_linux.go
++++ b/pkg/crc/constants/constants_linux.go
+@@ -1,6 +1,6 @@
+ package constants
+ 
+-const (
++var (
+ 	OcBinaryName     = "oc"
+ 	PodmanBinaryName = "podman"
+ )
+diff --git a/pkg/crc/machine/libvirt/constants.go b/pkg/crc/machine/libvirt/constants.go
+index 13b557a..dc3b3f3 100644
+--- a/pkg/crc/machine/libvirt/constants.go
++++ b/pkg/crc/machine/libvirt/constants.go
+@@ -16,10 +16,10 @@ const (
+ )
+ 
+ const (
+-	MachineDriverCommand = "crc-driver-libvirt"
+ 	MachineDriverVersion = "0.12.7"
+ )
+ 
+ var (
++	MachineDriverCommand     = "crc-driver-libvirt"
+ 	MachineDriverDownloadUrl = fmt.Sprintf("https://github.com/code-ready/machine-driver-libvirt/releases/download/%s/crc-driver-libvirt", MachineDriverVersion)
+ )
+diff --git a/pkg/crc/oc/oc.go b/pkg/crc/oc/oc.go
+index 5b7a552..cdfaf6f 100644
+--- a/pkg/crc/oc/oc.go
++++ b/pkg/crc/oc/oc.go
+@@ -43,8 +43,12 @@ func (oc OcLocalRunner) GetKubeconfigPath() string {
+ 
+ // UseOcWithConfig return the oc binary along with valid kubeconfig
+ func UseOCWithConfig(machineName string) OcConfig {
++	ocBinaryPath := filepath.Join(constants.CrcBinDir, constants.OcBinaryName)
++	if filepath.IsAbs(constants.OcBinaryName) {
++		ocBinaryPath = constants.OcBinaryName
++	}
+ 	localRunner := OcLocalRunner{
+-		OcBinaryPath:   filepath.Join(constants.CrcBinDir, constants.OcBinaryName),
++		OcBinaryPath:   ocBinaryPath,
+ 		KubeconfigPath: filepath.Join(constants.MachineInstanceDir, machineName, "kubeconfig"),
+ 	}
+ 	return NewOcConfig(localRunner, constants.DefaultContext, constants.DefaultName)
+diff --git a/pkg/crc/oc/oc_cache.go b/pkg/crc/oc/oc_cache.go
+index ecf6f63..4d0e6c9 100644
+--- a/pkg/crc/oc/oc_cache.go
++++ b/pkg/crc/oc/oc_cache.go
+@@ -29,6 +29,9 @@ func (oc *OcCached) EnsureIsCached() error {
+ }
+ 
+ func (oc *OcCached) IsCached() bool {
++	if filepath.IsAbs(constants.OcBinaryName) {
++		return true
++	}
+ 	if _, err := os.Stat(filepath.Join(constants.CrcBinDir, constants.OcBinaryName)); os.IsNotExist(err) {
+ 		return false
+ 	}
 diff --git a/pkg/crc/preflight/preflight_checks_linux.go b/pkg/crc/preflight/preflight_checks_linux.go
-index ecb699a..ae346c3 100644
+index ecb699a..d9529a4 100644
 --- a/pkg/crc/preflight/preflight_checks_linux.go
 +++ b/pkg/crc/preflight/preflight_checks_linux.go
 @@ -116,18 +116,18 @@ func fixLibvirtInstalled() error {
@@ -72,7 +136,22 @@ index ecb699a..ae346c3 100644
  	logging.Debug("libvirtd.service is already running")
  	return nil
  }
-@@ -550,20 +550,20 @@ func removeCrcDnsmasqConfigFile() error {
+@@ -246,6 +246,14 @@ func checkMachineDriverLibvirtInstalled() error {
+ 
+ 	// Check if crc-driver-libvirt is available
+ 	libvirtDriverPath := filepath.Join(constants.CrcBinDir, libvirt.MachineDriverCommand)
++	if filepath.IsAbs(libvirt.MachineDriverCommand) {
++		libvirtDriverPath = filepath.Join(constants.CrcBinDir, "crc-driver-libvirt")
++		if stdOut, stdErr, err := crcos.RunWithDefaultLocale("ln", "-s", libvirt.MachineDriverCommand, libvirtDriverPath); err != nil {
++			fmt.Println("stdout", stdOut)
++			fmt.Println("stderr", stdErr)
++			return fmt.Errorf("%s symbolic link to %s failed", libvirt.MachineDriverCommand, libvirtDriverPath)
++		}
++	}
+ 	err := unix.Access(libvirtDriverPath, unix.X_OK)
+ 	if err != nil {
+ 		return fmt.Errorf("%s is not executable", libvirtDriverPath)
+@@ -550,20 +558,20 @@ func removeCrcDnsmasqConfigFile() error {
  }
  
  func checkCrcNetworkManagerConfig() error {
pkgs/crc/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, buildGoPackage, buildGoModule, fetchFromGitHub, pkg-config, libvirt }:
+{ stdenv, lib, buildGoPackage, buildGoModule, fetchFromGitHub, pkg-config, libvirt, podman, my }:
 
 with lib;
 rec {
@@ -23,11 +23,14 @@ rec {
 
       goPackagePath = "github.com/code-ready/crc";
       subPackages = [ "cmd/crc" ];
-      buildFlagsArray = let t = "${goPackagePath}/pkg/crc/version"; in
+      buildFlagsArray = let t = "${goPackagePath}/pkg/crc"; in
         ''
           -ldflags=
-            -X ${t}.crcVersion=${version}
-            -X ${t}.bundleVersion=${bundle}
+            -X ${t}/version.crcVersion=${version}
+            -X ${t}/version.bundleVersion=${bundle}
+            -X ${t}/constants.OcBinaryName=${my.oc}/bin/oc
+            -X ${t}/constants.PodmanBinaryName=${podman}/bin/podman
+            -X ${t}/machine/libvirt.MachineDriverCommand=${crc_driver_libvirt}/bin/machine-driver-libvirt
         '';
 
       meta = with stdenv.lib; {
@@ -50,7 +53,7 @@ rec {
     bundle = "4.4.3";
   };
   crc_driver_libvirt = buildGoModule rec {
-    pname = "tkn";
+    pname = "crc_driver_libvirt";
     name = "${pname}-${version}";
 
     nativeBuildInputs = [ pkg-config ];