-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subcommand to setup environment variables to use `podman-remote` with the CRC VM. Fixes #961.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/code-ready/crc/pkg/crc/constants" | ||
"github.com/code-ready/crc/pkg/crc/errors" | ||
"github.com/code-ready/crc/pkg/crc/machine" | ||
"github.com/code-ready/crc/pkg/crc/output" | ||
"github.com/code-ready/crc/pkg/os/shell" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var podmanEnvCmd = &cobra.Command{ | ||
Use: "podman-env", | ||
Short: "Setup podman environment", | ||
Long: `Setup environment for 'podman' binary to access podman on CRC VM`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
userShell, err := shell.GetShell(forceShell) | ||
if err != nil { | ||
errors.ExitWithMessage(1, "Error running the podman-env command: %s", err.Error()) | ||
} | ||
|
||
ipConfig := machine.IpConfig{ | ||
Name: constants.DefaultName, | ||
Debug: isDebugLog(), | ||
} | ||
|
||
exitIfMachineMissing(ipConfig.Name) | ||
|
||
result, err := machine.Ip(ipConfig) | ||
if err != nil { | ||
errors.Exit(1) | ||
} | ||
|
||
output.Outln(shell.GetPathEnvString(userShell, constants.CrcBinDir)) | ||
output.Outln(shell.GetEnvString(userShell, "PODMAN_USER", constants.DefaultSSHUser)) | ||
output.Outln(shell.GetEnvString(userShell, "PODMAN_HOST", result.IP)) | ||
output.Outln(shell.GetEnvString(userShell, "PODMAN_IDENTITY_FILE", constants.GetPrivateKeyPath())) | ||
output.Outln(shell.GetEnvString(userShell, "PODMAN_IGNORE_HOSTS", "1")) | ||
output.Outln(shell.GenerateUsageHint(userShell, "crc podman-env")) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(podmanEnvCmd) | ||
podmanEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Set the environment for the specified shell: [fish, cmd, powershell, tcsh, bash, zsh]. Default is auto-detect.") | ||
} |