Skip to content

Commit

Permalink
Merge pull request kubernetes#531 from thockin/cleanups
Browse files Browse the repository at this point in the history
Break out small functions in cmd/kubelet
  • Loading branch information
thockin committed Jul 20, 2014
2 parents e41a0e5 + 4aa1f04 commit e4055c2
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ var (
dockerEndpoint = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with")
)

func main() {
flag.Parse()
util.InitLogs()
defer util.FlushLogs()
rand.Seed(time.Now().UTC().UnixNano())

// Set up logger for etcd client
etcd.SetLogger(util.NewLogger("etcd "))

func getDockerEndpoint() string {
var endpoint string
if len(*dockerEndpoint) > 0 {
endpoint = *dockerEndpoint
Expand All @@ -66,23 +58,39 @@ func main() {
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.")
}

return endpoint
}

func getHostname() string {
hostname := []byte(*hostnameOverride)
if string(hostname) == "" {
// Note: We use exec here instead of os.Hostname() because we
// 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 {
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{
Hostname: string(hostname),
Hostname: getHostname(),
DockerClient: dockerClient,
FileCheckFrequency: *fileCheckFrequency,
SyncFrequency: *syncFrequency,
Expand Down

0 comments on commit e4055c2

Please sign in to comment.