mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #273 from brendandburns/kubelet
Make the docker endpoint a flag.
This commit is contained in:
commit
b21facafb1
@ -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.
|
||||
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 != "" {
|
||||
@ -205,14 +205,23 @@ func (kl *Kubelet) getContainerId(manifest *api.ContainerManifest, container *ap
|
||||
return "", nil
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user