diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index cd084d78310..17a89c53d05 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -63,7 +63,7 @@ func main() { SyncFrequency: 5 * time.Second, HTTPCheckFrequency: 5 * time.Second, } - go myKubelet.RunKubelet("", manifestUrl, servers[0], "localhost", 0) + go myKubelet.RunKubelet("", manifestUrl, servers[0], "localhost", "", 0) // Create a second kublet so that the guestbook example's two redis slaves both // have a place they can schedule. @@ -76,7 +76,7 @@ func main() { SyncFrequency: 5 * time.Second, HTTPCheckFrequency: 5 * time.Second, } - go otherKubelet.RunKubelet("", "", servers[0], "localhost", 0) + go otherKubelet.RunKubelet("", "", servers[0], "localhost", "", 0) // Ok. we're good to go. glog.Infof("API Server started on %s", apiserver.URL) diff --git a/cmd/kubelet/kubelet.go b/cmd/kubelet/kubelet.go index 9838d0b07c1..55e880a3d39 100644 --- a/cmd/kubelet/kubelet.go +++ b/cmd/kubelet/kubelet.go @@ -23,6 +23,7 @@ package main import ( "flag" "math/rand" + "os" "os/exec" "time" @@ -43,6 +44,7 @@ var ( address = flag.String("address", "127.0.0.1", "The address for the info server to serve on") port = flag.Uint("port", 10250, "The port for the info server to serve on") hostnameOverride = flag.String("hostname_override", "", "If non-empty, will use this string as identification instead of the actual hostname.") + dockerEndpoint = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with") ) const dockerBinary = "/usr/bin/docker" @@ -56,7 +58,15 @@ func main() { // Set up logger for etcd client etcd.SetLogger(util.NewLogger("etcd ")) - endpoint := "unix:///var/run/docker.sock" + var endpoint string + if len(*dockerEndpoint) > 0 { + endpoint = *dockerEndpoint + } else if len(os.Getenv("DOCKER_HOST")) > 0 { + endpoint = os.Getenv("DOCKER_HOST") + } else { + endpoint = "unix:///var/run/docker.sock" + } + glog.Infof("Connecting to docker on %s", endpoint) dockerClient, err := docker.NewClient(endpoint) if err != nil { glog.Fatal("Couldn't connnect to docker.") @@ -79,5 +89,5 @@ func main() { SyncFrequency: *syncFrequency, HTTPCheckFrequency: *httpCheckFrequency, } - my_kubelet.RunKubelet(*config, *manifestUrl, *etcdServers, *address, *port) + my_kubelet.RunKubelet(*config, *manifestUrl, *etcdServers, *address, *dockerEndpoint, *port) } diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 8467f333ee0..f6d39e0879a 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -98,9 +98,9 @@ const ( // Starts background goroutines. If config_path, manifest_url, or address are empty, // they are not watched. Never returns. -func (kl *Kubelet) RunKubelet(config_path, manifest_url, etcd_servers, address string, port uint) { +func (kl *Kubelet) RunKubelet(config_path, manifest_url, etcd_servers, address, endpoint string, port uint) { if kl.DockerPuller == nil { - kl.DockerPuller = MakeDockerPuller() + kl.DockerPuller = MakeDockerPuller(endpoint) } updateChannel := make(chan manifestUpdate) if config_path != "" { @@ -229,14 +229,23 @@ func (kl *Kubelet) ListContainers() ([]string, error) { return result, err } -type dockerPuller struct{} - -func MakeDockerPuller() DockerPuller { - return dockerPuller{} +type dockerPuller struct { + endpoint string } -func (dockerPuller) Pull(image string) error { - cmd := exec.Command("docker", "pull", image) +func MakeDockerPuller(endpoint string) DockerPuller { + return dockerPuller{ + endpoint: endpoint, + } +} + +func (p dockerPuller) Pull(image string) error { + var cmd *exec.Cmd + if len(p.endpoint) == 0 { + cmd = exec.Command("docker", "pull", image) + } else { + cmd = exec.Command("docker", "-H", p.endpoint, "pull", image) + } err := cmd.Start() if err != nil { return err