Skip to content

Commit

Permalink
Merge pull request kubernetes#273 from brendandburns/kubelet
Browse files Browse the repository at this point in the history
Make the docker endpoint a flag.
  • Loading branch information
lavalamp committed Jun 28, 2014
2 parents a5c3889 + f8060c5 commit b21faca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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.
Expand All @@ -84,7 +84,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)
Expand Down
14 changes: 12 additions & 2 deletions cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package main
import (
"flag"
"math/rand"
"os"
"os/exec"
"time"

Expand All @@ -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"
Expand All @@ -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.")
Expand All @@ -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)
}
23 changes: 16 additions & 7 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,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 != "" {
Expand Down Expand Up @@ -205,14 +205,23 @@ func (kl *Kubelet) getContainerId(manifest *api.ContainerManifest, container *ap
return "", nil
}

type dockerPuller struct{}
type dockerPuller struct {
endpoint string
}

func MakeDockerPuller() DockerPuller {
return dockerPuller{}
func MakeDockerPuller(endpoint string) DockerPuller {
return dockerPuller{
endpoint: endpoint,
}
}

func (dockerPuller) Pull(image string) error {
cmd := exec.Command("docker", "pull", image)
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
Expand Down

0 comments on commit b21faca

Please sign in to comment.