Merge pull request #464 from yugui/fix/golint2

Fixes Go lint errors
This commit is contained in:
brendandburns 2014-07-16 09:55:30 -07:00
commit 8ddc33998c
7 changed files with 22 additions and 18 deletions

View File

@ -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"

View File

@ -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 == "" {

View File

@ -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)
}

View File

@ -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

View File

@ -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/<podid>/<containerName>
components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/")
var stats *info.ContainerInfo

View File

@ -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,
}

View File

@ -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)