Add a PointToHost function for podman as well
And add an active variable, similiar to dockerpull/8062/head
parent
7e3da0f8b0
commit
c578a7aa1e
|
@ -38,12 +38,13 @@ import (
|
||||||
"k8s.io/minikube/pkg/minikube/shell"
|
"k8s.io/minikube/pkg/minikube/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
var podmanEnvTmpl = fmt.Sprintf("{{ .Prefix }}%s{{ .Delimiter }}{{ .VarlinkBridge }}{{ .Suffix }}{{ .UsageHint }}", constants.PodmanVarlinkBridgeEnv)
|
var podmanEnvTmpl = fmt.Sprintf("{{ .Prefix }}%s{{ .Delimiter }}{{ .VarlinkBridge }}{{ .Suffix }}{{ .Prefix }}%s{{ .Delimiter }}{{ .MinikubePodmanProfile }}{{ .Suffix }}{{ .UsageHint }}", constants.PodmanVarlinkBridgeEnv, constants.MinikubeActivePodmanEnv)
|
||||||
|
|
||||||
// PodmanShellConfig represents the shell config for Podman
|
// PodmanShellConfig represents the shell config for Podman
|
||||||
type PodmanShellConfig struct {
|
type PodmanShellConfig struct {
|
||||||
shell.Config
|
shell.Config
|
||||||
VarlinkBridge string
|
VarlinkBridge string
|
||||||
|
MinikubePodmanProfile string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -59,6 +60,7 @@ func podmanShellCfgSet(ec PodmanEnvConfig, envMap map[string]string) *PodmanShel
|
||||||
Config: *shell.CfgSet(ec.EnvConfig, usgPlz, usgCmd),
|
Config: *shell.CfgSet(ec.EnvConfig, usgPlz, usgCmd),
|
||||||
}
|
}
|
||||||
s.VarlinkBridge = envMap[constants.PodmanVarlinkBridgeEnv]
|
s.VarlinkBridge = envMap[constants.PodmanVarlinkBridgeEnv]
|
||||||
|
s.MinikubePodmanProfile = envMap[constants.MinikubeActivePodmanEnv]
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -103,7 +105,7 @@ func createExternalSSHClient(d drivers.Driver) (*ssh.ExternalClient, error) {
|
||||||
// podmanEnvCmd represents the podman-env command
|
// podmanEnvCmd represents the podman-env command
|
||||||
var podmanEnvCmd = &cobra.Command{
|
var podmanEnvCmd = &cobra.Command{
|
||||||
Use: "podman-env",
|
Use: "podman-env",
|
||||||
Short: "Configure environment to use minikube's Podman daemon",
|
Short: "Configure environment to use minikube's Podman service",
|
||||||
Long: `Sets up podman env variables; similar to '$(podman-machine env)'.`,
|
Long: `Sets up podman env variables; similar to '$(podman-machine env)'.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cname := ClusterFlagValue()
|
cname := ClusterFlagValue()
|
||||||
|
@ -163,10 +165,7 @@ type PodmanEnvConfig struct {
|
||||||
|
|
||||||
// podmanSetScript writes out a shell-compatible 'podman-env' script
|
// podmanSetScript writes out a shell-compatible 'podman-env' script
|
||||||
func podmanSetScript(ec PodmanEnvConfig, w io.Writer) error {
|
func podmanSetScript(ec PodmanEnvConfig, w io.Writer) error {
|
||||||
envVars, err := podmanEnvVars(ec)
|
envVars := podmanEnvVars(ec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return shell.SetScript(ec.EnvConfig, w, podmanEnvTmpl, podmanShellCfgSet(ec, envVars))
|
return shell.SetScript(ec.EnvConfig, w, podmanEnvTmpl, podmanShellCfgSet(ec, envVars))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +173,7 @@ func podmanSetScript(ec PodmanEnvConfig, w io.Writer) error {
|
||||||
func podmanUnsetScript(ec PodmanEnvConfig, w io.Writer) error {
|
func podmanUnsetScript(ec PodmanEnvConfig, w io.Writer) error {
|
||||||
vars := []string{
|
vars := []string{
|
||||||
constants.PodmanVarlinkBridgeEnv,
|
constants.PodmanVarlinkBridgeEnv,
|
||||||
|
constants.MinikubeActivePodmanEnv,
|
||||||
}
|
}
|
||||||
return shell.UnsetScript(ec.EnvConfig, w, vars)
|
return shell.UnsetScript(ec.EnvConfig, w, vars)
|
||||||
}
|
}
|
||||||
|
@ -187,11 +187,12 @@ func podmanBridge(client *ssh.ExternalClient) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// podmanEnvVars gets the necessary podman env variables to allow the use of minikube's podman service
|
// podmanEnvVars gets the necessary podman env variables to allow the use of minikube's podman service
|
||||||
func podmanEnvVars(ec PodmanEnvConfig) (map[string]string, error) { // nolint result 1 (error) is always nil
|
func podmanEnvVars(ec PodmanEnvConfig) map[string]string {
|
||||||
env := map[string]string{
|
env := map[string]string{
|
||||||
constants.PodmanVarlinkBridgeEnv: podmanBridge(ec.client),
|
constants.PodmanVarlinkBridgeEnv: podmanBridge(ec.client),
|
||||||
|
constants.MinikubeActivePodmanEnv: ec.profile,
|
||||||
}
|
}
|
||||||
return env, nil
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -44,11 +44,12 @@ func TestGeneratePodmanScripts(t *testing.T) {
|
||||||
PodmanEnvConfig{profile: "bash", driver: "kvm2", client: newFakeClient()},
|
PodmanEnvConfig{profile: "bash", driver: "kvm2", client: newFakeClient()},
|
||||||
nil,
|
nil,
|
||||||
`export PODMAN_VARLINK_BRIDGE="/usr/bin/ssh root@host -- sudo varlink -A \'podman varlink \\\$VARLINK_ADDRESS\' bridge"
|
`export PODMAN_VARLINK_BRIDGE="/usr/bin/ssh root@host -- sudo varlink -A \'podman varlink \\\$VARLINK_ADDRESS\' bridge"
|
||||||
|
export MINIKUBE_ACTIVE_PODMAN="bash"
|
||||||
|
|
||||||
# To point your shell to minikube's podman service, run:
|
# To point your shell to minikube's podman service, run:
|
||||||
# eval $(minikube -p bash podman-env)
|
# eval $(minikube -p bash podman-env)
|
||||||
`,
|
`,
|
||||||
`unset PODMAN_VARLINK_BRIDGE
|
`unset PODMAN_VARLINK_BRIDGE MINIKUBE_ACTIVE_PODMAN
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,10 @@ func Execute() {
|
||||||
glog.Errorf("oci env: %v", err)
|
glog.Errorf("oci env: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := oci.PointToHostPodman(); err != nil {
|
||||||
|
glog.Errorf("oci env: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := RootCmd.Execute(); err != nil {
|
if err := RootCmd.Execute(); err != nil {
|
||||||
// Cobra already outputs the error, typically because the user provided an unknown command.
|
// Cobra already outputs the error, typically because the user provided an unknown command.
|
||||||
os.Exit(exit.BadUsage)
|
os.Exit(exit.BadUsage)
|
||||||
|
|
|
@ -465,6 +465,24 @@ func PointToHostDockerDaemon() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PointToHostPodman will unset env variables that point to podman inside minikube
|
||||||
|
func PointToHostPodman() error {
|
||||||
|
p := os.Getenv(constants.MinikubeActivePodmanEnv)
|
||||||
|
if p != "" {
|
||||||
|
glog.Infof("shell is pointing to podman inside minikube. will unset to use host")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range constants.PodmanRemoteEnvs {
|
||||||
|
e := constants.PodmanRemoteEnvs[i]
|
||||||
|
err := os.Setenv(e, "")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "resetting %s env", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ContainerRunning returns running state of a container
|
// ContainerRunning returns running state of a container
|
||||||
func ContainerRunning(ociBin string, name string, warnSlow ...bool) (bool, error) {
|
func ContainerRunning(ociBin string, name string, warnSlow ...bool) (bool, error) {
|
||||||
rr, err := runCmd(exec.Command(ociBin, "inspect", name, "--format={{.State.Running}}"), warnSlow...)
|
rr, err := runCmd(exec.Command(ociBin, "inspect", name, "--format={{.State.Running}}"), warnSlow...)
|
||||||
|
|
|
@ -65,6 +65,9 @@ const (
|
||||||
MinikubeActiveDockerdEnv = "MINIKUBE_ACTIVE_DOCKERD"
|
MinikubeActiveDockerdEnv = "MINIKUBE_ACTIVE_DOCKERD"
|
||||||
// PodmanVarlinkBridgeEnv is used for podman settings
|
// PodmanVarlinkBridgeEnv is used for podman settings
|
||||||
PodmanVarlinkBridgeEnv = "PODMAN_VARLINK_BRIDGE"
|
PodmanVarlinkBridgeEnv = "PODMAN_VARLINK_BRIDGE"
|
||||||
|
// MinikubeActivePodmanEnv holds the podman service that the user's shell is pointing at
|
||||||
|
// value would be profile or empty if pointing to the user's host.
|
||||||
|
MinikubeActivePodmanEnv = "MINIKUBE_ACTIVE_PODMAN"
|
||||||
// MinikubeForceSystemdEnv is used to force systemd as cgroup manager for the container runtime
|
// MinikubeForceSystemdEnv is used to force systemd as cgroup manager for the container runtime
|
||||||
MinikubeForceSystemdEnv = "MINIKUBE_FORCE_SYSTEMD"
|
MinikubeForceSystemdEnv = "MINIKUBE_FORCE_SYSTEMD"
|
||||||
)
|
)
|
||||||
|
@ -82,6 +85,8 @@ var (
|
||||||
|
|
||||||
// DockerDaemonEnvs is list of docker-daemon related environment variables.
|
// DockerDaemonEnvs is list of docker-daemon related environment variables.
|
||||||
DockerDaemonEnvs = [3]string{DockerHostEnv, DockerTLSVerifyEnv, DockerCertPathEnv}
|
DockerDaemonEnvs = [3]string{DockerHostEnv, DockerTLSVerifyEnv, DockerCertPathEnv}
|
||||||
|
// PodmanRemoteEnvs is list of podman-remote related environment variables.
|
||||||
|
PodmanRemoteEnvs = [1]string{PodmanVarlinkBridgeEnv}
|
||||||
|
|
||||||
// DefaultMinipath is the default minikube path (under the home directory)
|
// DefaultMinipath is the default minikube path (under the home directory)
|
||||||
DefaultMinipath = filepath.Join(homedir.HomeDir(), ".minikube")
|
DefaultMinipath = filepath.Join(homedir.HomeDir(), ".minikube")
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
---
|
---
|
||||||
title: "podman-env"
|
title: "podman-env"
|
||||||
description: >
|
description: >
|
||||||
Configure environment to use minikube's Podman daemon
|
Configure environment to use minikube's Podman service
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## minikube podman-env
|
## minikube podman-env
|
||||||
|
|
||||||
Configure environment to use minikube's Podman daemon
|
Configure environment to use minikube's Podman service
|
||||||
|
|
||||||
### Synopsis
|
### Synopsis
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue