Exemplo n.º 1
0
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.")
	}

	hostname := []byte(*hostnameOverride)
	if string(hostname) == "" {
		hostname, err = exec.Command("hostname", "-f").Output()
		if err != nil {
			log.Fatalf("Couldn't determine hostname: %v", err)
		}
	}

	my_kubelet := kubelet.Kubelet{
		Hostname:           string(hostname),
		DockerClient:       dockerClient,
		FileCheckFrequency: *fileCheckFrequency,
		SyncFrequency:      *syncFrequency,
		HTTPCheckFrequency: *httpCheckFrequency,
	}
	my_kubelet.RunKubelet(*file, *manifestUrl, *etcdServers, *address, *port)
}
Exemplo n.º 2
0
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 "))

	endpoint := "unix:///var/run/docker.sock"
	dockerClient, err := docker.NewClient(endpoint)
	if err != nil {
		glog.Fatal("Couldn't connnect to docker.")
	}

	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()
		if err != nil {
			glog.Fatalf("Couldn't determine hostname: %v", err)
		}
	}

	my_kubelet := kubelet.Kubelet{
		Hostname:           string(hostname),
		DockerClient:       dockerClient,
		FileCheckFrequency: *fileCheckFrequency,
		SyncFrequency:      *syncFrequency,
		HTTPCheckFrequency: *httpCheckFrequency,
	}
	my_kubelet.RunKubelet(*config, *manifestUrl, *etcdServers, *address, *port)
}
Exemplo n.º 3
0
func startKubelet(k *kubelet.Kubelet, cfg *config.PodConfig, kc *KubeletConfig) {
	// start the kubelet
	go util.Forever(func() { k.Run(cfg.Updates()) }, 0)

	// start the kubelet server
	if kc.EnableServer {
		go util.Forever(func() {
			kubelet.ListenAndServeKubeletServer(k, net.IP(kc.Address), kc.Port, kc.EnableDebuggingHandlers)
		}, 0)
	}
}
Exemplo n.º 4
0
// Starts kubelet services. Never returns.
func fake_kubelet() {
	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{
		Hostname:           *kubelet_address,
		DockerClient:       dockerClient,
		FileCheckFrequency: *fileCheckFrequency,
		SyncFrequency:      *syncFrequency,
		HTTPCheckFrequency: *httpCheckFrequency,
	}
	my_kubelet.RunKubelet(*file, *manifest_url, *etcd_server, *kubelet_address, *kubelet_port)
}
Exemplo n.º 5
0
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)
}
Exemplo n.º 6
0
func startComponents(manifestURL string) (apiServerURL string) {
	// Setup
	servers := []string{"http://localhost:4001"}
	glog.Infof("Creating etcd client pointing to %v", servers)
	machineList := []string{"localhost", "machine"}

	// Master
	m := master.New(servers, machineList, fakePodInfoGetter{}, nil, "")
	apiserver := httptest.NewServer(m.ConstructHandler("/api/v1beta1"))

	cl := client.New(apiserver.URL, nil)
	cl.PollPeriod = time.Second * 1
	cl.Sync = true
	controllerManager := controller.MakeReplicationManager(etcd.NewClient(servers), cl)

	controllerManager.Run(1 * time.Second)

	// Kubelet
	myKubelet := kubelet.Kubelet{
		Hostname:           machineList[0],
		DockerClient:       &fakeDocker1,
		DockerPuller:       &kubelet.FakeDockerPuller{},
		FileCheckFrequency: 5 * time.Second,
		SyncFrequency:      5 * time.Second,
		HTTPCheckFrequency: 5 * time.Second,
	}
	go myKubelet.RunKubelet("", "", manifestURL, servers[0], "localhost", 10250)

	// Create a second kubelet so that the guestbook example's two redis slaves both
	// have a place they can schedule.
	otherKubelet := kubelet.Kubelet{
		Hostname:           machineList[1],
		DockerClient:       &fakeDocker2,
		DockerPuller:       &kubelet.FakeDockerPuller{},
		FileCheckFrequency: 5 * time.Second,
		SyncFrequency:      5 * time.Second,
		HTTPCheckFrequency: 5 * time.Second,
	}
	go otherKubelet.RunKubelet("", "", "", servers[0], "localhost", 10251)

	return apiserver.URL
}
Exemplo n.º 7
0
func main() {
	util.InitLogs()
	defer util.FlushLogs()

	manifestUrl := ServeCachedManifestFile()
	// Setup
	servers := []string{"http://localhost:4001"}
	glog.Infof("Creating etcd client pointing to %v", servers)
	machineList := []string{"localhost", "machine"}

	// Master
	m := master.New(servers, machineList, nil)
	apiserver := httptest.NewServer(m.ConstructHandler("/api/v1beta1"))

	controllerManager := controller.MakeReplicationManager(etcd.NewClient(servers), client.New(apiserver.URL, nil))

	controllerManager.Run(10 * time.Second)

	// Kublet
	fakeDocker1 := &kubelet.FakeDockerClient{}
	myKubelet := kubelet.Kubelet{
		Hostname:           machineList[0],
		DockerClient:       fakeDocker1,
		DockerPuller:       &kubelet.FakeDockerPuller{},
		FileCheckFrequency: 5 * time.Second,
		SyncFrequency:      5 * time.Second,
		HTTPCheckFrequency: 5 * time.Second,
	}
	go myKubelet.RunKubelet("", manifestUrl, servers[0], "localhost", 0)

	// Create a second kublet so that the guestbook example's two redis slaves both
	// have a place they can schedule.
	fakeDocker2 := &kubelet.FakeDockerClient{}
	otherKubelet := kubelet.Kubelet{
		Hostname:           machineList[1],
		DockerClient:       fakeDocker2,
		DockerPuller:       &kubelet.FakeDockerPuller{},
		FileCheckFrequency: 5 * time.Second,
		SyncFrequency:      5 * time.Second,
		HTTPCheckFrequency: 5 * time.Second,
	}
	go otherKubelet.RunKubelet("", "", servers[0], "localhost", 0)

	// Ok. we're good to go.
	glog.Infof("API Server started on %s", apiserver.URL)
	// Wait for the synchronization threads to come up.
	time.Sleep(time.Second * 10)

	kubeClient := client.New(apiserver.URL, nil)
	data, err := ioutil.ReadFile("api/examples/controller.json")
	if err != nil {
		glog.Fatalf("Unexpected error: %#v", err)
	}
	var controllerRequest api.ReplicationController
	if err = json.Unmarshal(data, &controllerRequest); err != nil {
		glog.Fatalf("Unexpected error: %#v", err)
	}

	if _, err = kubeClient.CreateReplicationController(controllerRequest); err != nil {
		glog.Fatalf("Unexpected error: %#v", err)
	}
	// Give the controllers some time to actually create the pods
	time.Sleep(time.Second * 10)

	// Validate that they're truly up.
	pods, err := kubeClient.ListPods(nil)
	if err != nil || len(pods.Items) != 2 {
		glog.Fatal("FAILED")
	}

	// Check that kubelet tried to make the pods.
	// Using a set to list unique creation attempts. Our fake is
	// really stupid, so kubelet tries to create these multiple times.
	createdPods := map[string]struct{}{}
	for _, p := range fakeDocker1.Created {
		// The last 8 characters are random, so slice them off.
		if n := len(p); n > 8 {
			createdPods[p[:n-8]] = struct{}{}
		}
	}
	for _, p := range fakeDocker2.Created {
		// The last 8 characters are random, so slice them off.
		if n := len(p); n > 8 {
			createdPods[p[:n-8]] = struct{}{}
		}
	}
	// We expect 5: 2 net containers + 2 pods from the replication controller +
	//              1 net container + 2 pods from the URL.
	if len(createdPods) != 7 {
		glog.Fatalf("Unexpected list of created pods: %#v\n", createdPods)
	}
	glog.Infof("OK")
}