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.
|
|
|
|
*/
|
|
|
|
// The kubelet binary is responsible for maintaining a set of containers on a particular host VM.
|
|
|
|
// It sync's data from both configuration file as well as from a quorum of etcd servers.
|
|
|
|
// 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"
|
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
|
|
|
"github.com/coreos/go-etcd/etcd"
|
|
|
|
"github.com/fsouza/go-dockerclient"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
file = flag.String("config", "", "Path to the config file")
|
|
|
|
etcd_servers = 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")
|
|
|
|
fileCheckFrequency = flag.Duration("file_check_frequency", 20*time.Second, "Duration between checking file for new data")
|
|
|
|
httpCheckFrequency = flag.Duration("http_check_frequency", 20*time.Second, "Duration between checking http for new data")
|
2014-06-06 23:40:48 +00:00
|
|
|
manifest_url = flag.String("manifest_url", "", "URL for accessing the container manifest")
|
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
|
|
|
const dockerBinary = "/usr/bin/docker"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
|
|
|
|
// Set up logger for etcd client
|
|
|
|
etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags))
|
|
|
|
|
|
|
|
endpoint := "unix:///var/run/docker.sock"
|
|
|
|
dockerClient, err := docker.NewClient(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Couldn't connnect to docker.")
|
|
|
|
}
|
|
|
|
|
|
|
|
my_kubelet := kubelet.Kubelet{
|
|
|
|
DockerClient: dockerClient,
|
|
|
|
FileCheckFrequency: *fileCheckFrequency,
|
|
|
|
SyncFrequency: *syncFrequency,
|
|
|
|
HTTPCheckFrequency: *httpCheckFrequency,
|
|
|
|
}
|
|
|
|
my_kubelet.RunKubelet(*file, *manifest_url, *etcd_servers, *address, *port)
|
|
|
|
}
|