Readability fixes & address review comments.

This commit is contained in:
Daniel Smith 2014-06-24 10:19:47 -07:00
parent 6900431b13
commit fd66a8b59b
3 changed files with 34 additions and 28 deletions

View File

@ -49,25 +49,25 @@ func main() {
// Kublet // Kublet
fakeDocker := &kubelet.FakeDockerClient{} fakeDocker := &kubelet.FakeDockerClient{}
my_kubelet := kubelet.Kubelet{ myKubelet := kubelet.Kubelet{
Hostname: machineList[0], Hostname: machineList[0],
DockerClient: fakeDocker, DockerClient: fakeDocker,
FileCheckFrequency: 5 * time.Second, FileCheckFrequency: 5 * time.Second,
SyncFrequency: 5 * time.Second, SyncFrequency: 5 * time.Second,
HTTPCheckFrequency: 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 // Create a second kublet so that the guestbook example's two redis slaves both
// have a place they can schedule. // have a place they can schedule.
other_kubelet := kubelet.Kubelet{ otherKubelet := kubelet.Kubelet{
Hostname: machineList[1], Hostname: machineList[1],
DockerClient: &kubelet.FakeDockerClient{}, DockerClient: &kubelet.FakeDockerClient{},
FileCheckFrequency: 5 * time.Second, FileCheckFrequency: 5 * time.Second,
SyncFrequency: 5 * time.Second, SyncFrequency: 5 * time.Second,
HTTPCheckFrequency: 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. // Ok. we're good to go.
log.Printf("API Server started on %s", apiserver.URL) log.Printf("API Server started on %s", apiserver.URL)
@ -102,8 +102,7 @@ func main() {
createdPods := map[string]struct{}{} createdPods := map[string]struct{}{}
for _, p := range fakeDocker.Created { for _, p := range fakeDocker.Created {
// The last 8 characters are random, so slice them off. // The last 8 characters are random, so slice them off.
n := len(p) if n := len(p); n > 8 {
if n > 8 {
createdPods[p[:n-8]] = struct{}{} createdPods[p[:n-8]] = struct{}{}
} }
} }

View File

@ -43,52 +43,52 @@ var (
syncFrequency = flag.Duration("sync_frequency", 10*time.Second, "Max period between synchronizing running containers and config") 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") 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") 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") manifestUrl = 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") kubeletAddress = 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") kubeletPort = flag.Uint("kubelet_port", 10250, "The port for the kubelete info server to serve on")
) )
// master flags // master flags
var ( var (
master_port = flag.Uint("master_port", 8080, "The port for the master to listen on. Default 8080.") masterPort = 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") 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'") apiPrefix = flag.String("api_prefix", "/api/v1beta1", "The prefix for API requests on the server. Default '/api/v1beta1'")
) )
// flags that affect both // flags that affect both
var ( 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. // Starts kubelet services. Never returns.
func fake_kubelet() { func fakeKubelet() {
endpoint := "unix:///var/run/docker.sock" endpoint := "unix:///var/run/docker.sock"
dockerClient, err := docker.NewClient(endpoint) dockerClient, err := docker.NewClient(endpoint)
if err != nil { if err != nil {
log.Fatal("Couldn't connnect to docker.") log.Fatal("Couldn't connnect to docker.")
} }
my_kubelet := kubelet.Kubelet{ myKubelet := kubelet.Kubelet{
Hostname: *kubelet_address, Hostname: *kubeletAddress,
DockerClient: dockerClient, DockerClient: dockerClient,
FileCheckFrequency: *fileCheckFrequency, FileCheckFrequency: *fileCheckFrequency,
SyncFrequency: *syncFrequency, SyncFrequency: *syncFrequency,
HTTPCheckFrequency: *httpCheckFrequency, 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. // Starts api services (the master). Never returns.
func api_server() { func apiServer() {
m := master.New([]string{*etcd_server}, []string{*kubelet_address}, nil) m := master.New([]string{*etcdServer}, []string{*kubeletAddress}, nil)
log.Fatal(m.Run(net.JoinHostPort(*master_address, strconv.Itoa(int(*master_port))), *apiPrefix)) log.Fatal(m.Run(net.JoinHostPort(*masterAddress, strconv.Itoa(int(*masterPort))), *apiPrefix))
} }
// Starts up a controller manager. Never returns. // Starts up a controller manager. Never returns.
func controller_manager() { func controllerManager() {
controllerManager := controller.MakeReplicationManager( controllerManager := controller.MakeReplicationManager(
etcd.NewClient([]string{*etcd_server}), etcd.NewClient([]string{*etcdServer}),
client.New(fmt.Sprintf("http://%s:%d", *master_address, *master_port), nil)) client.New(fmt.Sprintf("http://%s:%d", *masterAddress, *masterPort), nil))
controllerManager.Run(20 * time.Second) controllerManager.Run(20 * time.Second)
select {} select {}
@ -101,12 +101,12 @@ func main() {
// Set up logger for etcd client // Set up logger for etcd client
etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags)) etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags))
go api_server() go apiServer()
go fake_kubelet() go fakeKubelet()
go controller_manager() go controllerManager()
log.Printf("All components started.\nMaster running at: http://%s:%d\nKubelet running at: http://%s:%d\n", log.Printf("All components started.\nMaster running at: http://%s:%d\nKubelet running at: http://%s:%d\n",
*master_address, *master_port, *masterAddress, *masterPort,
*kubelet_address, *kubelet_port) *kubeletAddress, *kubeletPort)
select {} select {}
} }

View File

@ -505,6 +505,10 @@ func (kl *Kubelet) extractFromHTTP(url string, updateChannel chan<- manifestUpda
var manifest api.ContainerManifest var manifest api.ContainerManifest
singleErr := yaml.Unmarshal(data, &manifest) singleErr := yaml.Unmarshal(data, &manifest)
if singleErr == nil && manifest.Version == "" { 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") singleErr = fmt.Errorf("got blank version field")
} }
if singleErr == nil { 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. // That didn't work, so try an array of manifests.
var manifests []api.ContainerManifest var manifests []api.ContainerManifest
multiErr := yaml.Unmarshal(data, &manifests) 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 { if multiErr == nil && len(manifests) == 0 {
multiErr = fmt.Errorf("no elements in ContainerManifest array") multiErr = fmt.Errorf("no elements in ContainerManifest array")
} }