Skip to content

Commit

Permalink
Change crc podman-env to use the root Podman socket
Browse files Browse the repository at this point in the history
Add a flag to choose rootless Podman.
  • Loading branch information
guillaumerose committed Jun 9, 2021
1 parent 1a81fb2 commit ebb0e28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/crc/cmd/podman_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/spf13/cobra"
)

var (
rootless bool
)

var podmanEnvCmd = &cobra.Command{
Use: "podman-env",
Short: "Setup podman environment",
Expand All @@ -33,18 +37,24 @@ func runPodmanEnv() error {
return err
}

socket := "/run/podman/podman.sock"
if rootless {
socket = "/run/user/1000/podman/podman.sock"
}
fmt.Println(shell.GetPathEnvString(userShell, constants.CrcOcBinDir))
fmt.Println(shell.GetEnvString(userShell, "CONTAINER_SSHKEY", connectionDetails.SSHKeys[0]))
fmt.Println(shell.GetEnvString(userShell, "CONTAINER_HOST",
fmt.Sprintf("ssh://%s@%s:%d/run/user/1000/podman/podman.sock",
fmt.Sprintf("ssh://%s@%s:%d%s",
connectionDetails.SSHUsername,
connectionDetails.IP,
connectionDetails.SSHPort)))
connectionDetails.SSHPort,
socket)))
fmt.Println(shell.GenerateUsageHintWithComment(userShell, "crc podman-env"))
return nil
}

func init() {
rootCmd.AddCommand(podmanEnvCmd)
podmanEnvCmd.Flags().BoolVar(&rootless, "rootless", false, "Use rootless podman in the virtual machine")
podmanEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Set the environment for the specified shell: [fish, cmd, powershell, tcsh, bash, zsh]. Default is auto-detect.")
rootCmd.AddCommand(podmanEnvCmd)
}
4 changes: 4 additions & 0 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
}
}

if _, _, err := sshRunner.RunPrivileged("make root Podman socket accessible", "chmod 777 /run/podman/ /run/podman/podman.sock"); err != nil {
return nil, errors.Wrap(err, "Failed to change permissions to root podman socket")
}

proxyConfig, err := getProxyConfig(crcBundleMetadata.ClusterInfo.BaseDomain)
if err != nil {
return nil, errors.Wrap(err, "Error getting proxy configuration")
Expand Down

0 comments on commit ebb0e28

Please sign in to comment.