Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for restoring existing podman env #9801

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions cmd/minikube/cmd/podman-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/ssh"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
Expand All @@ -39,9 +40,27 @@ import (
"k8s.io/minikube/pkg/minikube/shell"
)

var podmanEnv1Tmpl = fmt.Sprintf("{{ .Prefix }}%s{{ .Delimiter }}{{ .VarlinkBridge }}{{ .Suffix }}{{ .Prefix }}%s{{ .Delimiter }}{{ .MinikubePodmanProfile }}{{ .Suffix }}{{ .UsageHint }}", constants.PodmanVarlinkBridgeEnv, constants.MinikubeActivePodmanEnv)

var podmanEnv2Tmpl = fmt.Sprintf("{{ .Prefix }}%s{{ .Delimiter }}{{ .ContainerHost }}{{ .Suffix }}{{ if .ContainerSSHKey }}{{ .Prefix }}%s{{ .Delimiter }}{{ .ContainerSSHKey}}{{ .Suffix }}{{ end }}{{ .Prefix }}%s{{ .Delimiter }}{{ .MinikubePodmanProfile }}{{ .Suffix }}{{ .UsageHint }}", constants.PodmanContainerHostEnv, constants.PodmanContainerSSHKeyEnv, constants.MinikubeActivePodmanEnv)
var podmanEnv1Tmpl = fmt.Sprintf(
"{{ .Prefix }}%s{{ .Delimiter }}{{ .VarlinkBridge }}{{ .Suffix }}"+
"{{ .Prefix }}%s{{ .Delimiter }}{{ .MinikubePodmanProfile }}{{ .Suffix }}"+
"{{ .UsageHint }}",
constants.PodmanVarlinkBridgeEnv,
constants.MinikubeActivePodmanEnv)

var podmanEnv2Tmpl = fmt.Sprintf(
"{{ .Prefix }}%s{{ .Delimiter }}{{ .ContainerHost }}{{ .Suffix }}"+
"{{ if .ContainerSSHKey }}"+
"{{ .Prefix }}%s{{ .Delimiter }}{{ .ContainerSSHKey}}{{ .Suffix }}"+
"{{ end }}"+
"{{ if .ExistingContainerHost }}"+
"{{ .Prefix }}%s{{ .Delimiter }}{{ .ExistingContainerHost }}{{ .Suffix }}"+
"{{ end }}"+
"{{ .Prefix }}%s{{ .Delimiter }}{{ .MinikubePodmanProfile }}{{ .Suffix }}"+
"{{ .UsageHint }}",
constants.PodmanContainerHostEnv,
constants.PodmanContainerSSHKeyEnv,
constants.ExistingContainerHostEnv,
constants.MinikubeActivePodmanEnv)

// PodmanShellConfig represents the shell config for Podman
type PodmanShellConfig struct {
Expand All @@ -50,6 +69,8 @@ type PodmanShellConfig struct {
ContainerHost string
ContainerSSHKey string
MinikubePodmanProfile string

ExistingContainerHost string
}

var podmanUnset bool
Expand All @@ -65,6 +86,9 @@ func podmanShellCfgSet(ec PodmanEnvConfig, envMap map[string]string) *PodmanShel
s.VarlinkBridge = envMap[constants.PodmanVarlinkBridgeEnv]
s.ContainerHost = envMap[constants.PodmanContainerHostEnv]
s.ContainerSSHKey = envMap[constants.PodmanContainerSSHKeyEnv]

s.ExistingContainerHost = envMap[constants.ExistingContainerHostEnv]

s.MinikubePodmanProfile = envMap[constants.MinikubeActivePodmanEnv]

return s
Expand Down Expand Up @@ -259,6 +283,13 @@ func podmanEnvVars(ec PodmanEnvConfig) map[string]string {
for k, v := range env0 {
env[k] = v
}
if os.Getenv(constants.MinikubeActivePodmanEnv) == "" {
e := constants.PodmanContainerHostEnv
if v := oci.InitialEnv(e); v != "" {
key := constants.ExistingContainerHostEnv
env[key] = v
}
}
return env
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/drivers/kic/oci/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
var initialEnvs = make(map[string]string)

func init() {
// docker
for _, env := range constants.DockerDaemonEnvs {
if v, set := os.LookupEnv(env); set {
initialEnvs[env] = v
Expand All @@ -34,6 +35,15 @@ func init() {
initialEnvs[exEnv] = v
}
}
// podman
env := constants.PodmanContainerHostEnv
if v, set := os.LookupEnv(env); set {
initialEnvs[env] = v
}
exEnv := constants.ExistingContainerHostEnv
if v, set := os.LookupEnv(exEnv); set {
initialEnvs[exEnv] = v
}
}

// InitialEnv returns the value of the environment variable env before any environment changes made by minikube
Expand Down
3 changes: 3 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ const (
ExistingDockerCertPathEnv = MinikubeExistingPrefix + "DOCKER_CERT_PATH"
// ExistingDockerTLSVerifyEnv is used to save original docker environment
ExistingDockerTLSVerifyEnv = MinikubeExistingPrefix + "DOCKER_TLS_VERIFY"

// ExistingContainerHostEnv is used to save original podman environment
ExistingContainerHostEnv = MinikubeExistingPrefix + "CONTAINER_HOST"
)

var (
Expand Down