mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Readability fixes & address review comments.
This commit is contained in:
		@@ -49,25 +49,25 @@ func main() {
 | 
			
		||||
 | 
			
		||||
	// Kublet
 | 
			
		||||
	fakeDocker := &kubelet.FakeDockerClient{}
 | 
			
		||||
	my_kubelet := kubelet.Kubelet{
 | 
			
		||||
	myKubelet := kubelet.Kubelet{
 | 
			
		||||
		Hostname:           machineList[0],
 | 
			
		||||
		DockerClient:       fakeDocker,
 | 
			
		||||
		FileCheckFrequency: 5 * time.Second,
 | 
			
		||||
		SyncFrequency:      5 * time.Second,
 | 
			
		||||
		HTTPCheckFrequency: 5 * time.Second,
 | 
			
		||||
	}
 | 
			
		||||
	go my_kubelet.RunKubelet("", "https://raw.githubusercontent.com/GoogleCloudPlatform/container-vm-guestbook-redis-python/master/manifest.yaml", servers[0], "localhost", 0)
 | 
			
		||||
	go myKubelet.RunKubelet("", "https://raw.githubusercontent.com/GoogleCloudPlatform/container-vm-guestbook-redis-python/master/manifest.yaml", servers[0], "localhost", 0)
 | 
			
		||||
 | 
			
		||||
	// Create a second kublet so that the guestbook example's two redis slaves both
 | 
			
		||||
	// have a place they can schedule.
 | 
			
		||||
	other_kubelet := kubelet.Kubelet{
 | 
			
		||||
	otherKubelet := kubelet.Kubelet{
 | 
			
		||||
		Hostname:           machineList[1],
 | 
			
		||||
		DockerClient:       &kubelet.FakeDockerClient{},
 | 
			
		||||
		FileCheckFrequency: 5 * time.Second,
 | 
			
		||||
		SyncFrequency:      5 * time.Second,
 | 
			
		||||
		HTTPCheckFrequency: 5 * time.Second,
 | 
			
		||||
	}
 | 
			
		||||
	go other_kubelet.RunKubelet("", "", servers[0], "localhost", 0)
 | 
			
		||||
	go otherKubelet.RunKubelet("", "", servers[0], "localhost", 0)
 | 
			
		||||
 | 
			
		||||
	// Ok. we're good to go.
 | 
			
		||||
	log.Printf("API Server started on %s", apiserver.URL)
 | 
			
		||||
@@ -102,8 +102,7 @@ func main() {
 | 
			
		||||
	createdPods := map[string]struct{}{}
 | 
			
		||||
	for _, p := range fakeDocker.Created {
 | 
			
		||||
		// The last 8 characters are random, so slice them off.
 | 
			
		||||
		n := len(p)
 | 
			
		||||
		if n > 8 {
 | 
			
		||||
		if n := len(p); n > 8 {
 | 
			
		||||
			createdPods[p[:n-8]] = struct{}{}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -43,52 +43,52 @@ var (
 | 
			
		||||
	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")
 | 
			
		||||
	manifest_url       = flag.String("manifest_url", "", "URL for accessing the container manifest")
 | 
			
		||||
	kubelet_address    = flag.String("kubelet_address", "127.0.0.1", "The address for the kubelet info server to serve on")
 | 
			
		||||
	kubelet_port       = flag.Uint("kubelet_port", 10250, "The port for the kubelete info server to serve on")
 | 
			
		||||
	manifestUrl        = flag.String("manifest_url", "", "URL for accessing the container manifest")
 | 
			
		||||
	kubeletAddress     = flag.String("kubelet_address", "127.0.0.1", "The address for the kubelet info server to serve on")
 | 
			
		||||
	kubeletPort        = flag.Uint("kubelet_port", 10250, "The port for the kubelete info server to serve on")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// master flags
 | 
			
		||||
var (
 | 
			
		||||
	master_port    = flag.Uint("master_port", 8080, "The port for the master to listen on.  Default 8080.")
 | 
			
		||||
	master_address = flag.String("master_address", "127.0.0.1", "The address for the master to listen to. Default 127.0.0.1")
 | 
			
		||||
	apiPrefix      = flag.String("api_prefix", "/api/v1beta1", "The prefix for API requests on the server. Default '/api/v1beta1'")
 | 
			
		||||
	masterPort    = flag.Uint("master_port", 8080, "The port for the master to listen on.  Default 8080.")
 | 
			
		||||
	masterAddress = flag.String("master_address", "127.0.0.1", "The address for the master to listen to. Default 127.0.0.1")
 | 
			
		||||
	apiPrefix     = flag.String("api_prefix", "/api/v1beta1", "The prefix for API requests on the server. Default '/api/v1beta1'")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// flags that affect both
 | 
			
		||||
var (
 | 
			
		||||
	etcd_server = flag.String("etcd_server", "http://localhost:4001", "Url of local etcd server")
 | 
			
		||||
	etcdServer = flag.String("etcd_server", "http://localhost:4001", "Url of local etcd server")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Starts kubelet services. Never returns.
 | 
			
		||||
func fake_kubelet() {
 | 
			
		||||
func fakeKubelet() {
 | 
			
		||||
	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,
 | 
			
		||||
	myKubelet := kubelet.Kubelet{
 | 
			
		||||
		Hostname:           *kubeletAddress,
 | 
			
		||||
		DockerClient:       dockerClient,
 | 
			
		||||
		FileCheckFrequency: *fileCheckFrequency,
 | 
			
		||||
		SyncFrequency:      *syncFrequency,
 | 
			
		||||
		HTTPCheckFrequency: *httpCheckFrequency,
 | 
			
		||||
	}
 | 
			
		||||
	my_kubelet.RunKubelet(*file, *manifest_url, *etcd_server, *kubelet_address, *kubelet_port)
 | 
			
		||||
	myKubelet.RunKubelet(*file, *manifestUrl, *etcdServer, *kubeletAddress, *kubeletPort)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Starts api services (the master). Never returns.
 | 
			
		||||
func api_server() {
 | 
			
		||||
	m := master.New([]string{*etcd_server}, []string{*kubelet_address}, nil)
 | 
			
		||||
	log.Fatal(m.Run(net.JoinHostPort(*master_address, strconv.Itoa(int(*master_port))), *apiPrefix))
 | 
			
		||||
func apiServer() {
 | 
			
		||||
	m := master.New([]string{*etcdServer}, []string{*kubeletAddress}, nil)
 | 
			
		||||
	log.Fatal(m.Run(net.JoinHostPort(*masterAddress, strconv.Itoa(int(*masterPort))), *apiPrefix))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Starts up a controller manager. Never returns.
 | 
			
		||||
func controller_manager() {
 | 
			
		||||
func controllerManager() {
 | 
			
		||||
	controllerManager := controller.MakeReplicationManager(
 | 
			
		||||
		etcd.NewClient([]string{*etcd_server}),
 | 
			
		||||
		client.New(fmt.Sprintf("http://%s:%d", *master_address, *master_port), nil))
 | 
			
		||||
		etcd.NewClient([]string{*etcdServer}),
 | 
			
		||||
		client.New(fmt.Sprintf("http://%s:%d", *masterAddress, *masterPort), nil))
 | 
			
		||||
 | 
			
		||||
	controllerManager.Run(20 * time.Second)
 | 
			
		||||
	select {}
 | 
			
		||||
@@ -101,12 +101,12 @@ func main() {
 | 
			
		||||
	// Set up logger for etcd client
 | 
			
		||||
	etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags))
 | 
			
		||||
 | 
			
		||||
	go api_server()
 | 
			
		||||
	go fake_kubelet()
 | 
			
		||||
	go controller_manager()
 | 
			
		||||
	go apiServer()
 | 
			
		||||
	go fakeKubelet()
 | 
			
		||||
	go controllerManager()
 | 
			
		||||
 | 
			
		||||
	log.Printf("All components started.\nMaster running at: http://%s:%d\nKubelet running at: http://%s:%d\n",
 | 
			
		||||
		*master_address, *master_port,
 | 
			
		||||
		*kubelet_address, *kubelet_port)
 | 
			
		||||
		*masterAddress, *masterPort,
 | 
			
		||||
		*kubeletAddress, *kubeletPort)
 | 
			
		||||
	select {}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -505,6 +505,10 @@ func (kl *Kubelet) extractFromHTTP(url string, updateChannel chan<- manifestUpda
 | 
			
		||||
	var manifest api.ContainerManifest
 | 
			
		||||
	singleErr := yaml.Unmarshal(data, &manifest)
 | 
			
		||||
	if singleErr == nil && manifest.Version == "" {
 | 
			
		||||
		// If data is a []ContainerManifest, trying to put it into a ContainerManifest
 | 
			
		||||
		// will not give an error but also won't set any of the fields.
 | 
			
		||||
		// Our docs say that the version field is mandatory, so using that to judge wether
 | 
			
		||||
		// this was actually successful.
 | 
			
		||||
		singleErr = fmt.Errorf("got blank version field")
 | 
			
		||||
	}
 | 
			
		||||
	if singleErr == nil {
 | 
			
		||||
@@ -515,6 +519,9 @@ func (kl *Kubelet) extractFromHTTP(url string, updateChannel chan<- manifestUpda
 | 
			
		||||
	// That didn't work, so try an array of manifests.
 | 
			
		||||
	var manifests []api.ContainerManifest
 | 
			
		||||
	multiErr := yaml.Unmarshal(data, &manifests)
 | 
			
		||||
	// We're not sure if the person reading the logs is going to care about the single or
 | 
			
		||||
	// multiple manifest unmarshalling attempt, so we need to put both in the logs, as is
 | 
			
		||||
	// done at the end. Hence not returning early here.
 | 
			
		||||
	if multiErr == nil && len(manifests) == 0 {
 | 
			
		||||
		multiErr = fmt.Errorf("no elements in ContainerManifest array")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user