2014-06-06 23:40:48 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2014-06-23 18:32:11 +00:00
|
|
|
|
2014-06-06 23:40:48 +00:00
|
|
|
// The kubelet binary is responsible for maintaining a set of containers on a particular host VM.
|
2014-06-24 04:14:15 +00:00
|
|
|
// It syncs data from both configuration file(s) as well as from a quorum of etcd servers.
|
2014-06-06 23:40:48 +00:00
|
|
|
// It then queries Docker to see what is currently running. It synchronizes the configuration data,
|
|
|
|
// with the running set of containers by starting or stopping Docker containers.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"math/rand"
|
2014-06-27 23:07:30 +00:00
|
|
|
"os"
|
2014-06-12 02:04:14 +00:00
|
|
|
"os/exec"
|
2014-06-06 23:40:48 +00:00
|
|
|
"time"
|
|
|
|
|
2014-07-15 13:54:23 +00:00
|
|
|
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
2014-06-06 23:40:48 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
2014-06-25 03:51:57 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
2014-06-06 23:40:48 +00:00
|
|
|
"github.com/coreos/go-etcd/etcd"
|
|
|
|
"github.com/fsouza/go-dockerclient"
|
2014-06-25 03:51:57 +00:00
|
|
|
"github.com/golang/glog"
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2014-06-24 04:14:15 +00:00
|
|
|
config = flag.String("config", "", "Path to the config file or directory of files")
|
2014-06-15 17:24:36 +00:00
|
|
|
etcdServers = flag.String("etcd_servers", "", "Url of etcd servers in the cluster")
|
2014-06-11 06:29:35 +00:00
|
|
|
syncFrequency = flag.Duration("sync_frequency", 10*time.Second, "Max period between synchronizing running containers and config")
|
2014-06-24 04:14:15 +00:00
|
|
|
fileCheckFrequency = flag.Duration("file_check_frequency", 20*time.Second, "Duration between checking config files for new data")
|
2014-06-11 06:29:35 +00:00
|
|
|
httpCheckFrequency = flag.Duration("http_check_frequency", 20*time.Second, "Duration between checking http for new data")
|
2014-07-08 06:30:18 +00:00
|
|
|
manifestURL = flag.String("manifest_url", "", "URL for accessing the container manifest")
|
2014-06-06 23:40:48 +00:00
|
|
|
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")
|
2014-06-15 17:24:36 +00:00
|
|
|
hostnameOverride = flag.String("hostname_override", "", "If non-empty, will use this string as identification instead of the actual hostname.")
|
2014-06-27 23:07:30 +00:00
|
|
|
dockerEndpoint = flag.String("docker_endpoint", "", "If non-empty, use this for the docker endpoint to communicate with")
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2014-06-25 03:51:57 +00:00
|
|
|
util.InitLogs()
|
|
|
|
defer util.FlushLogs()
|
2014-06-06 23:40:48 +00:00
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
|
|
|
|
// Set up logger for etcd client
|
2014-06-25 03:51:57 +00:00
|
|
|
etcd.SetLogger(util.NewLogger("etcd "))
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-06-27 23:07:30 +00:00
|
|
|
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)
|
2014-06-06 23:40:48 +00:00
|
|
|
dockerClient, err := docker.NewClient(endpoint)
|
|
|
|
if err != nil {
|
2014-06-25 03:51:57 +00:00
|
|
|
glog.Fatal("Couldn't connnect to docker.")
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 17:24:36 +00:00
|
|
|
hostname := []byte(*hostnameOverride)
|
|
|
|
if string(hostname) == "" {
|
2014-06-24 04:14:15 +00:00
|
|
|
// Note: We use exec here instead of os.Hostname() because we
|
|
|
|
// want the FQDN, and this is the easiest way to get it.
|
2014-06-15 17:24:36 +00:00
|
|
|
hostname, err = exec.Command("hostname", "-f").Output()
|
|
|
|
if err != nil {
|
2014-06-25 03:51:57 +00:00
|
|
|
glog.Fatalf("Couldn't determine hostname: %v", err)
|
2014-06-15 17:24:36 +00:00
|
|
|
}
|
2014-06-12 01:57:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 06:30:18 +00:00
|
|
|
k := kubelet.Kubelet{
|
2014-06-12 02:04:14 +00:00
|
|
|
Hostname: string(hostname),
|
2014-06-06 23:40:48 +00:00
|
|
|
DockerClient: dockerClient,
|
|
|
|
FileCheckFrequency: *fileCheckFrequency,
|
|
|
|
SyncFrequency: *syncFrequency,
|
|
|
|
HTTPCheckFrequency: *httpCheckFrequency,
|
|
|
|
}
|
2014-07-08 06:30:18 +00:00
|
|
|
k.RunKubelet(*dockerEndpoint, *config, *manifestURL, *etcdServers, *address, *port)
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|