mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Make the docker endpoint a flag.
This commit is contained in:
parent
affaf173bf
commit
f8060c5b3d
@ -63,7 +63,7 @@ func main() {
|
|||||||
SyncFrequency: 5 * time.Second,
|
SyncFrequency: 5 * time.Second,
|
||||||
HTTPCheckFrequency: 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
|
// Create a second kublet so that the guestbook example's two redis slaves both
|
||||||
// have a place they can schedule.
|
// have a place they can schedule.
|
||||||
@ -76,7 +76,7 @@ func main() {
|
|||||||
SyncFrequency: 5 * time.Second,
|
SyncFrequency: 5 * time.Second,
|
||||||
HTTPCheckFrequency: 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.
|
// Ok. we're good to go.
|
||||||
glog.Infof("API Server started on %s", apiserver.URL)
|
glog.Infof("API Server started on %s", apiserver.URL)
|
||||||
|
@ -23,6 +23,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ var (
|
|||||||
address = flag.String("address", "127.0.0.1", "The address for the info server to serve on")
|
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")
|
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.")
|
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"
|
const dockerBinary = "/usr/bin/docker"
|
||||||
@ -56,7 +58,15 @@ func main() {
|
|||||||
// Set up logger for etcd client
|
// Set up logger for etcd client
|
||||||
etcd.SetLogger(util.NewLogger("etcd "))
|
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)
|
dockerClient, err := docker.NewClient(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal("Couldn't connnect to docker.")
|
glog.Fatal("Couldn't connnect to docker.")
|
||||||
@ -79,5 +89,5 @@ func main() {
|
|||||||
SyncFrequency: *syncFrequency,
|
SyncFrequency: *syncFrequency,
|
||||||
HTTPCheckFrequency: *httpCheckFrequency,
|
HTTPCheckFrequency: *httpCheckFrequency,
|
||||||
}
|
}
|
||||||
my_kubelet.RunKubelet(*config, *manifestUrl, *etcdServers, *address, *port)
|
my_kubelet.RunKubelet(*config, *manifestUrl, *etcdServers, *address, *dockerEndpoint, *port)
|
||||||
}
|
}
|
||||||
|
@ -98,9 +98,9 @@ const (
|
|||||||
|
|
||||||
// Starts background goroutines. If config_path, manifest_url, or address are empty,
|
// Starts background goroutines. If config_path, manifest_url, or address are empty,
|
||||||
// they are not watched. Never returns.
|
// 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 {
|
if kl.DockerPuller == nil {
|
||||||
kl.DockerPuller = MakeDockerPuller()
|
kl.DockerPuller = MakeDockerPuller(endpoint)
|
||||||
}
|
}
|
||||||
updateChannel := make(chan manifestUpdate)
|
updateChannel := make(chan manifestUpdate)
|
||||||
if config_path != "" {
|
if config_path != "" {
|
||||||
@ -229,14 +229,23 @@ func (kl *Kubelet) ListContainers() ([]string, error) {
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type dockerPuller struct{}
|
type dockerPuller struct {
|
||||||
|
endpoint string
|
||||||
func MakeDockerPuller() DockerPuller {
|
|
||||||
return dockerPuller{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dockerPuller) Pull(image string) error {
|
func MakeDockerPuller(endpoint string) DockerPuller {
|
||||||
cmd := exec.Command("docker", "pull", image)
|
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()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user