From de15c3da8f5e9766cdb1b9c44307226cae31d7e8 Mon Sep 17 00:00:00 2001 From: Anjan Nath Date: Thu, 8 Feb 2024 12:31:46 +0530 Subject: [PATCH] create symlink for podman in ~/.crc/bin/podman dir earlier both oc and podman binaries were present in the ~/.crc/bin/oc dir and added to PATH by the `crc oc-env` command, which resulted in adding both the binaries to path when the user might want only the `oc` binary to be added to path by the `crc oc-env` command this adds the `podman` binary in a separate directory ~/.crc/bin/podman and is added to PATH by running the `crc podman-env` command fixes #4022 --- cmd/crc/cmd/podman_env.go | 2 +- pkg/crc/constants/constants.go | 1 + pkg/crc/machine/bundle/repository.go | 12 +++++++----- pkg/crc/podman/podman.go | 2 +- test/integration/podman_test.go | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/crc/cmd/podman_env.go b/cmd/crc/cmd/podman_env.go index 40a821dfc9..6a471ae668 100644 --- a/cmd/crc/cmd/podman_env.go +++ b/cmd/crc/cmd/podman_env.go @@ -42,7 +42,7 @@ func runPodmanEnv() error { if root { socket = constants.RootfulPodmanSocket } - fmt.Println(shell.GetPathEnvString(userShell, constants.CrcOcBinDir)) + fmt.Println(shell.GetPathEnvString(userShell, constants.CrcPodmanBinDir)) fmt.Println(shell.GetEnvString(userShell, "CONTAINER_SSHKEY", connectionDetails.SSHKeys[0])) fmt.Println(shell.GetEnvString(userShell, "CONTAINER_HOST", fmt.Sprintf("ssh://%s@%s:%d%s", diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go index 486d9e3d63..cd50014537 100644 --- a/pkg/crc/constants/constants.go +++ b/pkg/crc/constants/constants.go @@ -105,6 +105,7 @@ var ( CrcBaseDir = filepath.Join(GetHomeDir(), ".crc") CrcBinDir = filepath.Join(CrcBaseDir, "bin") CrcOcBinDir = filepath.Join(CrcBinDir, "oc") + CrcPodmanBinDir = filepath.Join(CrcBinDir, "podman") CrcSymlinkPath = filepath.Join(CrcBinDir, "crc") ConfigPath = filepath.Join(CrcBaseDir, ConfigFile) LogFilePath = filepath.Join(CrcBaseDir, LogFile) diff --git a/pkg/crc/machine/bundle/repository.go b/pkg/crc/machine/bundle/repository.go index 20d73be2ca..66bec7e217 100644 --- a/pkg/crc/machine/bundle/repository.go +++ b/pkg/crc/machine/bundle/repository.go @@ -27,8 +27,9 @@ const ( ) type Repository struct { - CacheDir string - OcBinDir string + CacheDir string + OcBinDir string + PodmanBinDir string } func (repo *Repository) Get(bundleName string) (*CrcBundleInfo, error) { @@ -91,7 +92,7 @@ func (repo *Repository) Use(bundleName string) (*CrcBundleInfo, error) { if err := bundleInfo.createSymlinkOrCopyOpenShiftClient(repo.OcBinDir); err != nil { return nil, err } - if err := bundleInfo.createSymlinkOrCopyPodmanRemote(repo.OcBinDir); err != nil { + if err := bundleInfo.createSymlinkOrCopyPodmanRemote(repo.PodmanBinDir); err != nil { return nil, err } return bundleInfo, nil @@ -181,8 +182,9 @@ func (repo *Repository) CalculateBundleSha256Sum(bundlePath string) (string, err } var defaultRepo = &Repository{ - CacheDir: constants.MachineCacheDir, - OcBinDir: constants.CrcOcBinDir, + CacheDir: constants.MachineCacheDir, + OcBinDir: constants.CrcOcBinDir, + PodmanBinDir: constants.CrcPodmanBinDir, } func Get(bundleName string) (*CrcBundleInfo, error) { diff --git a/pkg/crc/podman/podman.go b/pkg/crc/podman/podman.go index f460bf2e66..7bf2c2ae06 100644 --- a/pkg/crc/podman/podman.go +++ b/pkg/crc/podman/podman.go @@ -13,7 +13,7 @@ const ( rootfulConn = "crc-root" ) -var podmanExecutablePath = filepath.Join(constants.CrcOcBinDir, constants.PodmanRemoteExecutableName) +var podmanExecutablePath = filepath.Join(constants.CrcPodmanBinDir, constants.PodmanRemoteExecutableName) func run(args ...string) (string, string, error) { return crcos.RunWithDefaultLocale(podmanExecutablePath, args...) diff --git a/test/integration/podman_test.go b/test/integration/podman_test.go index 206914eec5..dbb7d62b56 100644 --- a/test/integration/podman_test.go +++ b/test/integration/podman_test.go @@ -41,13 +41,13 @@ var _ = Describe("podman preset", Serial, Ordered, Label("podman-preset"), func( It("podman-env", func() { // Do what 'eval $(crc podman-env) would do - path := os.ExpandEnv("${HOME}/.crc/bin/oc:$PATH") + path := os.ExpandEnv("${HOME}/.crc/bin/podman:$PATH") csshk := os.ExpandEnv("${HOME}/.crc/machines/crc/id_ecdsa") dh := os.ExpandEnv("unix:///${HOME}/.crc/machines/crc/docker.sock") ch := "ssh://core@127.0.0.1:2222/run/user/1000/podman/podman.sock" if runtime.GOOS == "windows" { userHomeDir, _ := os.UserHomeDir() - unexpandedPath := filepath.Join(userHomeDir, ".crc/bin/oc;${PATH}") + unexpandedPath := filepath.Join(userHomeDir, ".crc/bin/podman;${PATH}") path = os.ExpandEnv(unexpandedPath) csshk = filepath.Join(userHomeDir, ".crc/machines/crc/id_ecdsa") dh = "npipe:////./pipe/crc-podman"