diff --git a/cmd/kubelet/kubelet.go b/cmd/kubelet/kubelet.go index 91e69938bb9..fc558d68f17 100644 --- a/cmd/kubelet/kubelet.go +++ b/cmd/kubelet/kubelet.go @@ -27,6 +27,7 @@ import ( "os/exec" "time" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/coreos/go-etcd/etcd" diff --git a/pkg/api/validation.go b/pkg/api/validation.go index a73373efa97..a29dec05c0d 100644 --- a/pkg/api/validation.go +++ b/pkg/api/validation.go @@ -247,6 +247,7 @@ func ValidateManifest(manifest *ContainerManifest) []error { return []error(allErrs) } +// ValidateService tests if required fields in the service are set. func ValidateService(service *Service) []error { allErrs := errorList{} if service.ID == "" { diff --git a/pkg/kubecfg/resource_printer.go b/pkg/kubecfg/resource_printer.go index 39864f75859..52e26278fdc 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -237,10 +237,12 @@ func (h *HumanReadablePrinter) PrintObj(obj interface{}, output io.Writer) error } } +// TemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template. type TemplatePrinter struct { Template *template.Template } +// Print parses the data as JSON, and re-formats it with the Go Template. func (t *TemplatePrinter) Print(data []byte, w io.Writer) error { obj, err := api.Decode(data) if err != nil { @@ -249,6 +251,7 @@ func (t *TemplatePrinter) Print(data []byte, w io.Writer) error { return t.PrintObj(obj, w) } +// PrintObj formats the obj with the Go Template. func (t *TemplatePrinter) PrintObj(obj interface{}, w io.Writer) error { return t.Template.Execute(w, obj) } diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 24c2c62cf20..6e5bb93f328 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -34,7 +34,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/health" - _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/coreos/go-etcd/etcd" @@ -49,8 +48,8 @@ const defaultChanSize = 1024 // taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc const minShares = 2 -const sharesPerCpu = 1024 -const milliCpuToCpu = 1000 +const sharesPerCPU = 1024 +const milliCPUToCPU = 1000 // CadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client. type CadvisorInterface interface { @@ -125,7 +124,7 @@ func (kl *Kubelet) RunKubelet(dockerEndpoint, configPath, manifestURL, etcdServe } if address != "" { glog.Infof("Starting to listen on %s:%d", address, port) - handler := KubeletServer{ + handler := Server{ Kubelet: kl, UpdateChannel: updateChannel, DelegateHandler: http.DefaultServeMux, @@ -275,9 +274,9 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m return exposedPorts, portBindings } -func milliCpuToShares(milliCpu int) int { - // Conceptually (milliCpu / milliCpuToCpu) * sharesPerCpu, but factored to improve rounding. - shares := (milliCpu * sharesPerCpu) / milliCpuToCpu +func milliCPUToShares(milliCPU int) int { + // Conceptually (milliCPU / milliCPUToCPU) * sharesPerCPU, but factored to improve rounding. + shares := (milliCPU * sharesPerCPU) / milliCPUToCPU if shares < minShares { return minShares } @@ -299,7 +298,7 @@ func (kl *Kubelet) runContainer(manifest *api.ContainerManifest, container *api. Hostname: container.Name, Image: container.Image, Memory: int64(container.Memory), - CpuShares: int64(milliCpuToShares(container.CPU)), + CpuShares: int64(milliCPUToShares(container.CPU)), Volumes: volumes, WorkingDir: container.WorkingDir, }, @@ -865,7 +864,7 @@ func (kl *Kubelet) statsFromContainerPath(containerPath string, req *info.Contai return cinfo, nil } -// GetContainerStats returns stats (from Cadvisor) for a container. +// GetContainerInfo returns stats (from Cadvisor) for a container. func (kl *Kubelet) GetContainerInfo(podID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { if kl.CadvisorClient == nil { return nil, nil diff --git a/pkg/kubelet/kubelet_server.go b/pkg/kubelet/kubelet_server.go index e872a69b2a7..5789df17fc0 100644 --- a/pkg/kubelet/kubelet_server.go +++ b/pkg/kubelet/kubelet_server.go @@ -28,13 +28,13 @@ import ( "strings" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/google/cadvisor/info" "github.com/GoogleCloudPlatform/kubernetes/pkg/httplog" + "github.com/google/cadvisor/info" "gopkg.in/v1/yaml" ) -// KubeletServer is a http.Handler which exposes kubelet functionality over HTTP. -type KubeletServer struct { +// Server is a http.Handler which exposes kubelet functionality over HTTP. +type Server struct { Kubelet kubeletInterface UpdateChannel chan<- manifestUpdate DelegateHandler http.Handler @@ -48,11 +48,11 @@ type kubeletInterface interface { GetPodInfo(name string) (api.PodInfo, error) } -func (s *KubeletServer) error(w http.ResponseWriter, err error) { +func (s *Server) error(w http.ResponseWriter, err error) { http.Error(w, fmt.Sprintf("Internal Error: %v", err), http.StatusInternalServerError) } -func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { +func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { defer httplog.MakeLogged(req, &w).Log() u, err := url.ParseRequestURI(req.RequestURI) @@ -113,7 +113,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { } } -func (s *KubeletServer) serveStats(w http.ResponseWriter, req *http.Request) { +func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) { // /stats// components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/") var stats *info.ContainerInfo diff --git a/pkg/kubelet/kubelet_server_test.go b/pkg/kubelet/kubelet_server_test.go index fce6913be8e..0db9b2f9a4e 100644 --- a/pkg/kubelet/kubelet_server_test.go +++ b/pkg/kubelet/kubelet_server_test.go @@ -53,7 +53,7 @@ func (fk *fakeKubelet) GetMachineStats(req *info.ContainerInfoRequest) (*info.Co type serverTestFramework struct { updateChan chan manifestUpdate updateReader *channelReader - serverUnderTest *KubeletServer + serverUnderTest *Server fakeKubelet *fakeKubelet testHTTPServer *httptest.Server } @@ -64,7 +64,7 @@ func makeServerTest() *serverTestFramework { } fw.updateReader = startReading(fw.updateChan) fw.fakeKubelet = &fakeKubelet{} - fw.serverUnderTest = &KubeletServer{ + fw.serverUnderTest = &Server{ Kubelet: fw.fakeKubelet, UpdateChannel: fw.updateChan, } diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 0d32062f734..dbfb884a323 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -1064,7 +1064,7 @@ func TestGetContainerStatsWithoutCadvisor(t *testing.T) { t.Errorf("MaxMemoryUsage is %v even if there's no cadvisor", stats.StatsPercentiles.MaxMemoryUsage) } if len(stats.StatsPercentiles.CpuUsagePercentiles) > 0 { - t.Errorf("Cpu usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.CpuUsagePercentiles) + t.Errorf("CPU usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.CpuUsagePercentiles) } if len(stats.StatsPercentiles.MemoryUsagePercentiles) > 0 { t.Errorf("Memory usage percentiles is not empty (%+v) even if there's no cadvisor", stats.StatsPercentiles.MemoryUsagePercentiles)