Exemple #1
0
// Starts up a controller manager. Never returns.
func controller_manager() {
	controllerManager := controller.MakeReplicationManager(etcd.NewClient([]string{*etcd_server}),
		client.Client{
			Host: fmt.Sprintf("http://%s:%d", *master_address, *master_port),
		})

	controllerManager.Run(20 * time.Second)
	select {}
}
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"}

	handler := delegateHandler{}
	apiserver := httptest.NewServer(&handler)

	etcdClient := etcd.NewClient(servers)

	cl := client.New(apiserver.URL, nil)
	cl.PollPeriod = time.Second * 1
	cl.Sync = true

	// Master
	m := master.New(&master.Config{
		Client:        cl,
		EtcdServers:   servers,
		Minions:       machineList,
		PodInfoGetter: fakePodInfoGetter{},
	})
	handler.delegate = m.ConstructHandler("/api/v1beta1")

	controllerManager := controller.MakeReplicationManager(cl)

	// Prove that controllerManager's watch works by making it not sync until after this
	// test is over. (Hopefully we don't take 10 minutes!)
	controllerManager.Run(10 * time.Minute)

	// Kubelet (localhost)
	cfg1 := config.NewPodConfig(config.PodConfigNotificationSnapshotAndUpdates)
	config.NewSourceEtcd(config.EtcdKeyForHost(machineList[0]), etcdClient, 30*time.Second, cfg1.Channel("etcd"))
	config.NewSourceURL(manifestURL, 5*time.Second, cfg1.Channel("url"))
	myKubelet := kubelet.NewIntegrationTestKubelet(machineList[0], &fakeDocker1)
	go util.Forever(func() { myKubelet.Run(cfg1.Updates()) }, 0)
	go util.Forever(cfg1.Sync, 3*time.Second)
	go util.Forever(func() {
		kubelet.ListenAndServeKubeletServer(myKubelet, cfg1.Channel("http"), http.DefaultServeMux, "localhost", 10250)
	}, 0)

	// Kubelet (machine)
	// Create a second kubelet so that the guestbook example's two redis slaves both
	// have a place they can schedule.
	cfg2 := config.NewPodConfig(config.PodConfigNotificationSnapshotAndUpdates)
	config.NewSourceEtcd(config.EtcdKeyForHost(machineList[1]), etcdClient, 30*time.Second, cfg2.Channel("etcd"))
	otherKubelet := kubelet.NewIntegrationTestKubelet(machineList[1], &fakeDocker2)
	go util.Forever(func() { otherKubelet.Run(cfg2.Updates()) }, 0)
	go util.Forever(cfg2.Sync, 3*time.Second)
	go util.Forever(func() {
		kubelet.ListenAndServeKubeletServer(otherKubelet, cfg2.Channel("http"), http.DefaultServeMux, "localhost", 10251)
	}, 0)

	return apiserver.URL
}
Exemple #3
0
func main() {

	// Setup
	servers := []string{"http://localhost:4001"}
	log.Printf("Creating etcd client pointing to %v", servers)
	etcdClient := etcd.NewClient(servers)
	machineList := []string{"machine"}

	reg := registry.MakeEtcdRegistry(etcdClient, machineList)

	apiserver := apiserver.New(map[string]apiserver.RESTStorage{
		"pods": registry.MakePodRegistryStorage(reg, &client.FakeContainerInfo{}, registry.MakeRoundRobinScheduler(machineList), nil, nil),
		"replicationControllers": registry.MakeControllerRegistryStorage(reg),
	}, "/api/v1beta1")
	server := httptest.NewServer(apiserver)

	controllerManager := controller.MakeReplicationManager(etcd.NewClient(servers),
		client.Client{
			Host: server.URL,
		})

	controllerManager.Run(10 * time.Second)

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

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

	if _, err = kubeClient.CreateReplicationController(controllerRequest); err != nil {
		log.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 {
		log.Fatal("FAILED")
	}
	log.Printf("OK")
}
func main() {
	flag.Parse()
	util.InitLogs()
	defer util.FlushLogs()

	verflag.PrintAndExitIfRequested()

	if len(*master) == 0 {
		glog.Fatal("usage: controller-manager -master <master>")
	}

	controllerManager := controller.MakeReplicationManager(
		client.New("http://"+*master, nil))

	controllerManager.Run(10 * time.Second)
	select {}
}
func main() {
	flag.Parse()

	if len(*etcd_servers) == 0 || len(*master) == 0 {
		log.Fatal("usage: controller-manager -etcd_servers <servers> -master <master>")
	}

	// Set up logger for etcd client
	etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags))

	controllerManager := controller.MakeReplicationManager(etcd.NewClient([]string{*etcd_servers}),
		client.Client{
			Host: "http://" + *master,
		})

	controllerManager.Run(10 * time.Second)
	select {}
}
func main() {
	flag.Parse()
	util.InitLogs()
	defer util.FlushLogs()

	if len(*etcdServers) == 0 || len(*master) == 0 {
		glog.Fatal("usage: controller-manager -etcd_servers <servers> -master <master>")
	}

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

	controllerManager := controller.MakeReplicationManager(
		etcd.NewClient([]string{*etcdServers}),
		client.New("http://"+*master, nil))

	controllerManager.Run(10 * time.Second)
	select {}
}
Exemple #7
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
}
Exemple #8
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")
}