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

Support non-default docker endpoints #9510

Merged
merged 19 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package kic
import (
"fmt"
"net"
"os"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -95,10 +94,13 @@ func (d *Driver) Create() error {
klog.Infof("calculated static IP %q for the %q container", ip.String(), d.NodeConfig.MachineName)
params.IP = ip.String()
}
drv := d.DriverName()
listAddr := oci.DefaultBindIPV4
if d.DriverName() == oci.Docker && os.Getenv(constants.DockerHostEnv) != "" {
if oci.IsExternalRuntimeHost(drv) {
klog.Infof("Listening 0.0.0.0 on external docker host %v", oci.RuntimeHost(drv))
medyagh marked this conversation as resolved.
Show resolved Hide resolved
listAddr = "0.0.0.0"
}

// control plane specific options
params.PortMappings = append(params.PortMappings,
oci.PortMapping{
Expand Down Expand Up @@ -230,12 +232,12 @@ func (d *Driver) GetIP() (string, error) {

// GetExternalIP returns an IP which is accessible from outside
func (d *Driver) GetExternalIP() (string, error) {
return oci.DockerHost(d.DriverName()), nil
return oci.RuntimeHost(d.DriverName()), nil
}

// GetSSHHostname returns hostname for use with ssh
func (d *Driver) GetSSHHostname() (string, error) {
return oci.DockerHost(d.DriverName()), nil
return oci.RuntimeHost(d.DriverName()), nil
}

// GetSSHPort returns port for use with ssh
Expand Down
29 changes: 18 additions & 11 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,28 +640,35 @@ func iptablesFileExists(ociBin string, nameOrID string) bool {
return true
}

// TODO: comment
func DockerHost(driver string) string {
// RuntimeHost returns the ip/hostname where OCI daemon service for driver is running
// For Podman it's always DefaultBindIPV4
// For Docker return the host part of DOCKER_HOST environment variable if set
// or DefaultBindIPV4 otherwise
func RuntimeHost(driver string) string {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if driver != Docker {
return DefaultBindIPV4
}
if v := DockerMachineHost(driver); v != "" {
return v
if dh := os.Getenv(constants.DockerHostEnv); dh != "" {
if u, err := url.Parse(dh); err == nil {
if u.Host != "" {
return u.Hostname()
}
}
}
return DefaultBindIPV4
}

// TODO: comment
func DockerMachineHost(driver string) string {
// IsExternalRuntimeHost returns whether or not the OCI runtime is running on an external/virtual host
// For Podman driver it's always false for now
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rules for podman should be the same as for docker, when it comes to external vs. local
only the default transport differs, if it is tcp: or ssh: (as opposed to unix: for the local socket)

eventually it is going to end up looking very similar, once we get rid of the legacy protocols
then it will always be the same unix socket, possibly tunneled over a ssh connection first...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I just want to reduce the scope of this PR and implement support of external docker endpoints here, and later do the same for Podman.

Copy link
Member

@medyagh medyagh Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with adding that in a following up PR, once we add support for non default podman

// For Docker driver return true if DOCKER_HOST is set to a URI, and the URI contains a host item
func IsExternalRuntimeHost(driver string) bool {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if driver != Docker {
return ""
return false
}
if dh := os.Getenv(constants.DockerHostEnv); dh != "" {
if u, err := url.Parse(dh); err == nil {
if u.Host != "" {
return u.Hostname()
}
return u.Host != ""
}
}
return ""
return false
}
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func generateProfileCerts(k8s config.KubernetesConfig, n config.Node, ccs CACert

apiServerIPs := append(
k8s.APIServerIPs,
[]net.IP{net.ParseIP(n.IP), serviceIP, net.ParseIP(oci.DockerHost(k8s.ContainerRuntime)), net.ParseIP("10.0.0.1")}...)
[]net.IP{net.ParseIP(n.IP), serviceIP, net.ParseIP(oci.RuntimeHost(k8s.ContainerRuntime)), net.ParseIP("10.0.0.1")}...)
medyagh marked this conversation as resolved.
Show resolved Hide resolved
apiServerNames := append(k8s.APIServerNames, k8s.APIServerName, constants.ControlPlaneAlias)
apiServerAlternateNames := append(
apiServerNames,
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ func NeedsPortForward(name string) bool {
if !IsKIC(name) {
return false
}
if oci.DockerMachineHost(name) != "" {
if oci.IsExternalRuntimeHost(name) {
ilya-zuyev marked this conversation as resolved.
Show resolved Hide resolved
return true
}
// Docker for Desktop
return (runtime.GOOS == "darwin" || runtime.GOOS == "windows" || IsMicrosoftWSL())
return runtime.GOOS == "darwin" || runtime.GOOS == "windows" || IsMicrosoftWSL()
}

// IsMicrosoftWSL will return true if process is running in WSL in windows
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/driver/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func ControlPlaneEndpoint(cc *config.ClusterConfig, cp *config.Node, driverName string) (string, net.IP, int, error) {
if NeedsPortForward(driverName) {
port, err := oci.ForwardedPort(cc.Driver, cc.Name, cp.Port)
hostname := oci.DockerHost(driverName)
hostname := oci.RuntimeHost(driverName)

ip := net.ParseIP(hostname)
if ip == nil {
Expand Down