mirror of https://github.com/k3s-io/k3s
Break out small functions in cmd/kubelet
parent
e41a0e5763
commit
4aa1f04b08
|
@ -48,15 +48,7 @@ var (
|
||||||
dockerEndpoint = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with")
|
dockerEndpoint = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func getDockerEndpoint() string {
|
||||||
flag.Parse()
|
|
||||||
util.InitLogs()
|
|
||||||
defer util.FlushLogs()
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
// Set up logger for etcd client
|
|
||||||
etcd.SetLogger(util.NewLogger("etcd "))
|
|
||||||
|
|
||||||
var endpoint string
|
var endpoint string
|
||||||
if len(*dockerEndpoint) > 0 {
|
if len(*dockerEndpoint) > 0 {
|
||||||
endpoint = *dockerEndpoint
|
endpoint = *dockerEndpoint
|
||||||
|
@ -66,23 +58,39 @@ func main() {
|
||||||
endpoint = "unix:///var/run/docker.sock"
|
endpoint = "unix:///var/run/docker.sock"
|
||||||
}
|
}
|
||||||
glog.Infof("Connecting to docker on %s", endpoint)
|
glog.Infof("Connecting to docker on %s", endpoint)
|
||||||
dockerClient, err := docker.NewClient(endpoint)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal("Couldn't connnect to docker.")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHostname() string {
|
||||||
hostname := []byte(*hostnameOverride)
|
hostname := []byte(*hostnameOverride)
|
||||||
if string(hostname) == "" {
|
if string(hostname) == "" {
|
||||||
// Note: We use exec here instead of os.Hostname() because we
|
// Note: We use exec here instead of os.Hostname() because we
|
||||||
// want the FQDN, and this is the easiest way to get it.
|
// want the FQDN, and this is the easiest way to get it.
|
||||||
hostname, err = exec.Command("hostname", "-f").Output()
|
fqdn, err := exec.Command("hostname", "-f").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Couldn't determine hostname: %v", err)
|
glog.Fatalf("Couldn't determine hostname: %v", err)
|
||||||
}
|
}
|
||||||
|
hostname = fqdn
|
||||||
|
}
|
||||||
|
return string(hostname)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
util.InitLogs()
|
||||||
|
defer util.FlushLogs()
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
|
||||||
|
etcd.SetLogger(util.NewLogger("etcd "))
|
||||||
|
|
||||||
|
dockerClient, err := docker.NewClient(getDockerEndpoint())
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal("Couldn't connect to docker.")
|
||||||
}
|
}
|
||||||
|
|
||||||
k := kubelet.Kubelet{
|
k := kubelet.Kubelet{
|
||||||
Hostname: string(hostname),
|
Hostname: getHostname(),
|
||||||
DockerClient: dockerClient,
|
DockerClient: dockerClient,
|
||||||
FileCheckFrequency: *fileCheckFrequency,
|
FileCheckFrequency: *fileCheckFrequency,
|
||||||
SyncFrequency: *syncFrequency,
|
SyncFrequency: *syncFrequency,
|
||||||
|
|
Loading…
Reference in New Issue