diff --git a/pkg/labels/labels.go b/pkg/labels/labels.go index 5c980d4dea0..8c1e050f876 100644 --- a/pkg/labels/labels.go +++ b/pkg/labels/labels.go @@ -23,7 +23,7 @@ import ( // Labels allows you to present labels independently from their storage. type Labels interface { - // Get returns the value identified by the label. + // Get returns the value for the provided label. Get(label string) (value string) } @@ -42,7 +42,7 @@ func (ls Set) String() string { return strings.Join(selector, ",") } -// Get returns the value for the provided label. +// Get returns the value in the map for the provided label. func (ls Set) Get(label string) string { return ls[label] } diff --git a/pkg/master/master.go b/pkg/master/master.go index 84816d6c5d9..7434ee135d4 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -43,7 +43,7 @@ type Master struct { storage map[string]apiserver.RESTStorage } -// NewMemoryServer returns a memory (not etcd) backed apiserver. +// NewMemoryServer returns a new instance of Master backed with memory (not etcd). func NewMemoryServer(minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface) *Master { m := &Master{ podRegistry: registry.MakeMemoryRegistry(), @@ -55,7 +55,7 @@ func NewMemoryServer(minions []string, podInfoGetter client.PodInfoGetter, cloud return m } -// New returns a new apiserver. +// New returns a new instance of Master connected to the given etcdServer. func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface, minionRegexp string) *Master { etcdClient := etcd.NewClient(etcdServers) minionRegistry := minionRegistryMaker(minions, cloud, minionRegexp) @@ -94,7 +94,7 @@ func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInf } -// Run runs master. Never returns. +// Run begins serving the Kubernetes API. It never returns. func (m *Master) Run(myAddress, apiPrefix string) error { endpoints := registry.MakeEndpointController(m.serviceRegistry, m.podRegistry) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) @@ -111,7 +111,7 @@ func (m *Master) Run(myAddress, apiPrefix string) error { // ConstructHandler returns an http.Handler which serves Kubernetes API. // Instead of calling Run, you can call this function to get a handler for your own server. -// Intended for testing. Only call once. +// It is intended for testing. Only call once. func (m *Master) ConstructHandler(apiPrefix string) http.Handler { endpoints := registry.MakeEndpointController(m.serviceRegistry, m.podRegistry) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) diff --git a/pkg/master/pod_cache.go b/pkg/master/pod_cache.go index a5dffe96dec..c6be9a9f9dd 100644 --- a/pkg/master/pod_cache.go +++ b/pkg/master/pod_cache.go @@ -40,7 +40,7 @@ type PodCache struct { podLock sync.Mutex } -// NewPodCache returns a new PodCache. +// NewPodCache returns a new PodCache which watches container information registered in the given PodRegistry. func NewPodCache(info client.PodInfoGetter, pods registry.PodRegistry, period time.Duration) *PodCache { return &PodCache{ containerInfo: info, @@ -88,7 +88,8 @@ func (p *PodCache) UpdateAllContainers() { } } -// Loop runs forever, it is expected to be placed in a go routine. +// Loop begins watching updates of container information. +// It runs forever, and is expected to be placed in a go routine. func (p *PodCache) Loop() { util.Forever(func() { p.UpdateAllContainers() }, p.period) } diff --git a/pkg/proxy/config/config.go b/pkg/proxy/config/config.go index 9ceec048b04..9a95e037c3a 100644 --- a/pkg/proxy/config/config.go +++ b/pkg/proxy/config/config.go @@ -54,14 +54,14 @@ type EndpointsUpdate struct { Op Operation } -// ServiceConfigHandler handles update notifications of the set of services. +// ServiceConfigHandler is an abstract interface of objects which receive update notifications of the set of services. type ServiceConfigHandler interface { // OnUpdate gets called when a configuration has been changed by one of the sources. // This is the union of all the configuration sources. OnUpdate(services []api.Service) } -// EndpointsConfigHandler handles update notifications of the set of endpoints. +// EndpointsConfigHandler is an abstract interface of objects which receive update notifications of the set of endpoints. type EndpointsConfigHandler interface { // OnUpdate gets called when endpoints configuration is changed for a given // service on any of the configuration sources. An example is when a new diff --git a/pkg/proxy/config/etcd.go b/pkg/proxy/config/etcd.go index cac508a649b..89488fca4f2 100644 --- a/pkg/proxy/config/etcd.go +++ b/pkg/proxy/config/etcd.go @@ -54,8 +54,7 @@ type ConfigSourceEtcd struct { endpointsChannel chan EndpointsUpdate } -// NewConfigSourceEtcd creates a new ConfigSourceEtcd. -// It immediately runs the created ConfigSourceEtcd in a goroutine. +// NewConfigSourceEtcd creates a new ConfigSourceEtcd and immediately runs the created ConfigSourceEtcd in a goroutine. func NewConfigSourceEtcd(client *etcd.Client, serviceChannel chan ServiceUpdate, endpointsChannel chan EndpointsUpdate) ConfigSourceEtcd { config := ConfigSourceEtcd{ client: client, diff --git a/pkg/proxy/config/file.go b/pkg/proxy/config/file.go index e0c1755621c..ac6810bdec3 100644 --- a/pkg/proxy/config/file.go +++ b/pkg/proxy/config/file.go @@ -51,15 +51,14 @@ type serviceConfig struct { } `json: "service"` } -// ConfigSourceFile periodically reads service configurations in JSON from a file, and sends the services and endpoints defined in th file to the specified channels. +// ConfigSourceFile periodically reads service configurations in JSON from a file, and sends the services and endpoints defined in the file to the specified channels. type ConfigSourceFile struct { serviceChannel chan ServiceUpdate endpointsChannel chan EndpointsUpdate filename string } -// NewConfigSourceFile creates a new ConfigSourceFile. -// It immediately runs the created ConfigSourceFile in a goroutine. +// NewConfigSourceFile creates a new ConfigSourceFile and let it immediately runs the created ConfigSourceFile in a goroutine. func NewConfigSourceFile(filename string, serviceChannel chan ServiceUpdate, endpointsChannel chan EndpointsUpdate) ConfigSourceFile { config := ConfigSourceFile{ filename: filename, diff --git a/pkg/proxy/proxier.go b/pkg/proxy/proxier.go index 0746dd24a5f..602b7c69b87 100644 --- a/pkg/proxy/proxier.go +++ b/pkg/proxy/proxier.go @@ -33,12 +33,11 @@ type Proxier struct { serviceMap map[string]int } -// NewProxier returns a new Proxier. +// NewProxier returns a newly created and correctly initialized instance of Proxier. func NewProxier(loadBalancer LoadBalancer) *Proxier { return &Proxier{loadBalancer: loadBalancer, serviceMap: make(map[string]int)} } -// copyBytes copies bytes from in to out until EOF. func copyBytes(in, out *net.TCPConn) { glog.Infof("Copying from %v <-> %v <-> %v <-> %v", in.RemoteAddr(), in.LocalAddr(), out.LocalAddr(), out.RemoteAddr()) @@ -122,7 +121,8 @@ func (proxier Proxier) addServiceCommon(service string, l net.Listener) { go proxier.AcceptHandler(service, l) } -// OnUpdate handles update notices for the updated services. +// OnUpdate recieves update notices for the updated services and start listening newly added services. +// It implements "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config".ServiceConfigHandler.OnUpdate. func (proxier Proxier) OnUpdate(services []api.Service) { glog.Infof("Received update notice: %+v", services) for _, service := range services { diff --git a/pkg/proxy/roundrobbin.go b/pkg/proxy/roundrobbin.go index 60eb41c5410..e6e192e399b 100644 --- a/pkg/proxy/roundrobbin.go +++ b/pkg/proxy/roundrobbin.go @@ -36,7 +36,7 @@ type LoadBalancerRR struct { rrIndex map[string]int } -// NewLoadBalancerRR returns a new LoadBalancerRR. +// NewLoadBalancerRR returns a newly created and correctly initialized instance of LoadBalancerRR. func NewLoadBalancerRR() *LoadBalancerRR { return &LoadBalancerRR{endpointsMap: make(map[string][]string), rrIndex: make(map[string]int)} } @@ -70,7 +70,6 @@ func (impl LoadBalancerRR) isValid(spec string) bool { return value > 0 } -// filterValidEndpoints filters out invalid endpoints. func (impl LoadBalancerRR) filterValidEndpoints(endpoints []string) []string { var result []string for _, spec := range endpoints {