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 using podman with docker-env #20260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 36 additions & 3 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,27 @@ func mustRestartDockerd(name string, runner command.Runner) {
}
}

// ensurePodman ensures podman inside minikube is running before a docker-env command
func ensurePodman(name string, r command.Runner) {
if ok := isPodmanActive(r); ok {
return
}
startPodman(name, r)
}

// isPodmanActive checks if Podman is active
func isPodmanActive(r command.Runner) bool {
return sysinit.New(r).Active("podman.socket")
}

// startPodman will attempt to start podman
func startPodman(name string, r command.Runner) {
if err := sysinit.New(r).Start("podman.socket"); err != nil {
klog.Warningf("Couldn't start podman inside minikube within '%v' because: %v", name, err)
return
}
}

func waitForAPIServerProcess(cr command.Runner, start time.Time, timeout time.Duration) error {
klog.Infof("waiting for apiserver process to appear ...")
err := apiWait.PollUntilContextTimeout(context.Background(), time.Millisecond*500, timeout, true, func(_ context.Context) (bool, error) {
Expand Down Expand Up @@ -312,14 +333,26 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
exit.Message(reason.Usage, err.Error())
}

forceSSH := false

// for the sake of docker-env command, start nerdctl and nerdctld
if cr == constants.Containerd {
out.WarningT("Using the docker-env command with the containerd runtime is a highly experimental feature, please provide feedback or contribute to make it better")

startNerdctld()
forceSSH = true
}
if cr == constants.CRIO {
if _, err := co.CP.Runner.RunCmd(exec.Command("sudo", "ln", "-sf", "/run/podman/podman.sock", "/var/run/docker.sock")); err != nil {
exit.Message(reason.SSHAgentStart, err.Error())
}
forceSSH = true
}

if forceSSH {
// docker-env on containerd depends on nerdctld (https://github.com/afbjorklund/nerdctld) as "docker" daeomn
// and nerdctld daemon must be used with ssh connection (it is set in kicbase image's Dockerfile)
// the podman service must be used with ssh connection (it does not support tcp connection)
// so directly set --ssh-host --ssh-add to true, even user didn't specify them
sshAdd = true
sshHost = true
Expand All @@ -342,6 +375,9 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
if cr == constants.Docker {
ensureDockerd(cname, r)
}
if cr == constants.CRIO {
ensurePodman(cname, r)
}

d := co.CP.Host.Driver
port := constants.DockerDaemonPort
Expand Down Expand Up @@ -672,9 +708,6 @@ func tryDockerConnectivity(bin string, ec DockerEnvConfig) ([]byte, error) {
}

func dockerEnvSupported(containerRuntime, driverName string) error {
if containerRuntime != constants.Docker && containerRuntime != constants.Containerd {
return fmt.Errorf("the docker-env command only supports the docker and containerd runtimes")
}
// we only support containerd-env on the Docker driver
if containerRuntime == constants.Containerd && driverName != driver.Docker {
return fmt.Errorf("the docker-env command only supports the containerd runtime with the docker driver")
Expand Down
Loading