Skip to content

Commit

Permalink
create symlink for podman in ~/.crc/bin/podman dir
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anjannath committed Feb 8, 2024
1 parent 76e7517 commit de15c3d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/crc/cmd/podman_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions pkg/crc/machine/bundle/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]: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"
Expand Down

0 comments on commit de15c3d

Please sign in to comment.