From 50eb2cf59ce1c516e289a25e858ddda13f67efdb Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 24 Sep 2014 14:25:21 -0700 Subject: [PATCH 1/2] fix verify-gofmt's version detection --- .travis.yml | 2 +- hack/verify-gofmt.sh | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b0383b0558fb7..3b14147e082f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ go: - 1.3 - 1.2 -install: +install: - go get code.google.com/p/go.tools/cmd/cover - ./hack/install-etcd.sh - ./hack/verify-gofmt.sh diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index 262637553c465..d929d6dcc3b9a 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -17,10 +17,9 @@ # GoFmt apparently is changing @ head... GO_VERSION=($(go version)) -echo "Detected go version: $(go version)" -if [[ ${GO_VERSION[2]} != "go1.2" && ${GO_VERSION[2]} != "go1.3" ]]; then - echo "Unknown go version, skipping gofmt." +if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3') ]]; then + echo "Unknown go version '${GO_VERSION}', skipping gofmt." exit 0 fi From bb0cd95a83c34bf73b70f19643b2929462a9878b Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 24 Sep 2014 14:27:10 -0700 Subject: [PATCH 2/2] fix non-gofmt'd things --- cmd/apiserver/plugins.go | 2 +- pkg/api/latest/latest_test.go | 2 +- pkg/cloudprovider/aws/aws_test.go | 10 +- pkg/cloudprovider/ovirt/ovirt.go | 24 +-- pkg/kubelet/config/http_test.go | 4 +- pkg/kubelet/dockertools/config_test.go | 8 +- pkg/kubelet/dockertools/docker.go | 2 +- pkg/kubelet/handlers.go | 6 +- pkg/kubelet/kubelet.go | 4 +- pkg/kubelet/server.go | 2 +- pkg/kubelet/server_test.go | 234 ++++++++++++------------- 11 files changed, 149 insertions(+), 149 deletions(-) diff --git a/cmd/apiserver/plugins.go b/cmd/apiserver/plugins.go index 3eddf5c0545bc..1e92d034eaefc 100644 --- a/cmd/apiserver/plugins.go +++ b/cmd/apiserver/plugins.go @@ -22,6 +22,6 @@ package main import ( _ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/aws" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/gce" - _ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/vagrant" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/ovirt" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/vagrant" ) diff --git a/pkg/api/latest/latest_test.go b/pkg/api/latest/latest_test.go index 61b698e9431e9..4c6c6f9d5c7c8 100644 --- a/pkg/api/latest/latest_test.go +++ b/pkg/api/latest/latest_test.go @@ -85,7 +85,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( func TestInternalRoundTrip(t *testing.T) { latest := "v1beta2" - for k, _ := range internal.Scheme.KnownTypes("") { + for k := range internal.Scheme.KnownTypes("") { obj, err := internal.Scheme.New("", k) if err != nil { t.Errorf("%s: unexpected error: %v", k, err) diff --git a/pkg/cloudprovider/aws/aws_test.go b/pkg/cloudprovider/aws/aws_test.go index bc026db3d01b9..778de9cdf47a5 100644 --- a/pkg/cloudprovider/aws/aws_test.go +++ b/pkg/cloudprovider/aws/aws_test.go @@ -89,20 +89,20 @@ func mockInstancesResp(instances []ec2.Instance) (aws *AWSCloud) { func(instanceIds []string, filter *ec2.Filter) (resp *ec2.InstancesResp, err error) { return &ec2.InstancesResp{"", []ec2.Reservation{ - ec2.Reservation{"", "", "", nil, instances}}}, nil + {"", "", "", nil, instances}}}, nil }}, nil} } func TestList(t *testing.T) { instances := make([]ec2.Instance, 4) - instances[0].Tags = []ec2.Tag{ec2.Tag{"Name", "foo"}} + instances[0].Tags = []ec2.Tag{{"Name", "foo"}} instances[0].PrivateDNSName = "instance1" - instances[1].Tags = []ec2.Tag{ec2.Tag{"Name", "bar"}} + instances[1].Tags = []ec2.Tag{{"Name", "bar"}} instances[1].PrivateDNSName = "instance2" - instances[2].Tags = []ec2.Tag{ec2.Tag{"Name", "baz"}} + instances[2].Tags = []ec2.Tag{{"Name", "baz"}} instances[2].PrivateDNSName = "instance3" - instances[3].Tags = []ec2.Tag{ec2.Tag{"Name", "quux"}} + instances[3].Tags = []ec2.Tag{{"Name", "quux"}} instances[3].PrivateDNSName = "instance4" aws := mockInstancesResp(instances) diff --git a/pkg/cloudprovider/ovirt/ovirt.go b/pkg/cloudprovider/ovirt/ovirt.go index 9255d4bf7aa76..a63ab080c372f 100644 --- a/pkg/cloudprovider/ovirt/ovirt.go +++ b/pkg/cloudprovider/ovirt/ovirt.go @@ -18,9 +18,9 @@ package ovirt_cloud import ( "encoding/xml" + "fmt" "io" "io/ioutil" - "fmt" "net" "net/http" "net/url" @@ -32,8 +32,8 @@ import ( ) type OVirtCloud struct { - VmsRequest *url.URL - HostsRequest *url.URL + VmsRequest *url.URL + HostsRequest *url.URL } type OVirtApiConfig struct { @@ -43,18 +43,18 @@ type OVirtApiConfig struct { Password string `gcfg:"password"` } Filters struct { - VmsQuery string `gcfg:"vms"` + VmsQuery string `gcfg:"vms"` } } type XmlVmInfo struct { - Hostname string `xml:"guest_info>fqdn"` - State string `xml:"status>state"` + Hostname string `xml:"guest_info>fqdn"` + State string `xml:"status>state"` } type XmlVmsList struct { - XMLName xml.Name `xml:"vms"` - Vm []XmlVmInfo `xml:"vm"` + XMLName xml.Name `xml:"vms"` + Vm []XmlVmInfo `xml:"vm"` } func init() { @@ -74,7 +74,7 @@ func newOVirtCloud(config io.Reader) (*OVirtCloud, error) { /* defaults */ oVirtConfig.Connection.Username = "admin@internal" - if err := gcfg.ReadInto(&oVirtConfig, config); err != nil { + if err := gcfg.ReadInto(&oVirtConfig, config); err != nil { return nil, err } @@ -83,7 +83,7 @@ func newOVirtCloud(config io.Reader) (*OVirtCloud, error) { } request, err := url.Parse(oVirtConfig.Connection.ApiEntry) - if err != nil { + if err != nil { return nil, err } @@ -121,7 +121,7 @@ func getInstancesFromXml(body io.Reader) ([]string, error) { } content, err := ioutil.ReadAll(body) - if err != nil { + if err != nil { return nil, err } @@ -146,7 +146,7 @@ func getInstancesFromXml(body io.Reader) ([]string, error) { // List enumerates the set of minions instances known by the cloud provider func (v *OVirtCloud) List(filter string) ([]string, error) { response, err := http.Get(v.VmsRequest.String()) - if err != nil { + if err != nil { return nil, err } diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index ce4fb5a1bc782..e561d0d7d5738 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -79,7 +79,7 @@ func TestExtractInvalidManifest(t *testing.T) { desc: "Unspecified container name", manifests: []api.ContainerManifest{ { - Version: "v1beta1", + Version: "v1beta1", Containers: []api.Container{{Name: ""}}, }, }, @@ -88,7 +88,7 @@ func TestExtractInvalidManifest(t *testing.T) { desc: "Invalid container name", manifests: []api.ContainerManifest{ { - Version: "v1beta1", + Version: "v1beta1", Containers: []api.Container{{Name: "_INVALID_"}}, }, }, diff --git a/pkg/kubelet/dockertools/config_test.go b/pkg/kubelet/dockertools/config_test.go index 9c7a6af84808b..9b1a75e48bfa7 100644 --- a/pkg/kubelet/dockertools/config_test.go +++ b/pkg/kubelet/dockertools/config_test.go @@ -28,12 +28,12 @@ func TestDockerConfigJSONDecode(t *testing.T) { input := []byte(`{"http://foo.example.com":{"username": "foo", "password": "bar", "email": "foo@example.com"}, "http://bar.example.com":{"username": "bar", "password": "baz", "email": "bar@example.com"}}`) expect := dockerConfig(map[string]dockerConfigEntry{ - "http://foo.example.com": dockerConfigEntry{ + "http://foo.example.com": { Username: "foo", Password: "bar", Email: "foo@example.com", }, - "http://bar.example.com": dockerConfigEntry{ + "http://bar.example.com": { Username: "bar", Password: "baz", Email: "bar@example.com", @@ -171,12 +171,12 @@ func TestDecodeDockerConfigFieldAuth(t *testing.T) { func TestDockerKeyringFromConfig(t *testing.T) { cfg := dockerConfig(map[string]dockerConfigEntry{ - "http://foo.example.com": dockerConfigEntry{ + "http://foo.example.com": { Username: "foo", Password: "bar", Email: "foo@example.com", }, - "https://bar.example.com": dockerConfigEntry{ + "https://bar.example.com": { Username: "bar", Password: "baz", Email: "bar@example.com", diff --git a/pkg/kubelet/dockertools/docker.go b/pkg/kubelet/dockertools/docker.go index 743f024e77655..306a6245e3707 100644 --- a/pkg/kubelet/dockertools/docker.go +++ b/pkg/kubelet/dockertools/docker.go @@ -20,12 +20,12 @@ import ( "errors" "fmt" "hash/adler32" + "io" "math/rand" "os/exec" "sort" "strconv" "strings" - "io" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/fsouza/go-dockerclient" diff --git a/pkg/kubelet/handlers.go b/pkg/kubelet/handlers.go index 77934595721f8..f3583fc71beb2 100644 --- a/pkg/kubelet/handlers.go +++ b/pkg/kubelet/handlers.go @@ -18,10 +18,10 @@ package kubelet import ( "fmt" + "io" "net" - "strconv" "net/http" - "io" + "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -101,7 +101,7 @@ func (h *httpActionHandler) Run(podFullName, uuid string, container *api.Contain // FlushWriter provides wrapper for responseWriter with HTTP streaming capabilities type FlushWriter struct { flusher http.Flusher - writer io.Writer + writer io.Writer } // Write is a FlushWriter implementation of the io.Writer that sends any buffered data to the client. diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 6f0f3cb450856..012531fd18cb8 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -20,13 +20,13 @@ import ( "encoding/json" "errors" "fmt" + "io" "net/http" "path" "strconv" "strings" "sync" "time" - "io" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" @@ -758,7 +758,7 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri if !found { return fmt.Errorf("container not found (%s)\n", containerName) } - return dockertools.GetKubeletDockerContainerLogs(kl.dockerClient, dockerContainer.ID, tail , follow, stdout, stderr) + return dockertools.GetKubeletDockerContainerLogs(kl.dockerClient, dockerContainer.ID, tail, follow, stdout, stderr) } // GetPodInfo returns information from Docker about the containers in a pod diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index 40709650d506c..839b31c9cb651 100644 --- a/pkg/kubelet/server.go +++ b/pkg/kubelet/server.go @@ -172,7 +172,7 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) { http.Error(w, `{"message": "Missing container name."}`, http.StatusBadRequest) return } - + uriValues := u.Query() follow, _ := strconv.ParseBool(uriValues.Get("follow")) tail := uriValues.Get("tail") diff --git a/pkg/kubelet/server_test.go b/pkg/kubelet/server_test.go index dbf4094528513..3b7f8417a7760 100644 --- a/pkg/kubelet/server_test.go +++ b/pkg/kubelet/server_test.go @@ -20,6 +20,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "io/ioutil" "net/http" "net/http/httptest" @@ -27,7 +28,6 @@ import ( "reflect" "strings" "testing" - "io" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -36,13 +36,13 @@ import ( ) type fakeKubelet struct { - infoFunc func(name string) (api.PodInfo, error) - containerInfoFunc func(podFullName, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) - rootInfoFunc func(query *info.ContainerInfoRequest) (*info.ContainerInfo, error) - machineInfoFunc func() (*info.MachineInfo, error) - logFunc func(w http.ResponseWriter, req *http.Request) - runFunc func(podFullName, uuid, containerName string, cmd []string) ([]byte, error) - containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error + infoFunc func(name string) (api.PodInfo, error) + containerInfoFunc func(podFullName, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) + rootInfoFunc func(query *info.ContainerInfoRequest) (*info.ContainerInfo, error) + machineInfoFunc func() (*info.MachineInfo, error) + logFunc func(w http.ResponseWriter, req *http.Request) + runFunc func(podFullName, uuid, containerName string, cmd []string) ([]byte, error) + containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error } func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) { @@ -355,119 +355,119 @@ func TestServeRunInContainerWithUUID(t *testing.T) { } func TestContainerLogs(t *testing.T) { - fw := newServerTest() - output := "foo bar" - podName := "foo" - expectedPodName := podName + ".etcd" - expectedContainerName := "baz" - expectedTail := "" - expectedFollow := false - // expected := api.Container{"goodpod": docker.Container{ID: "myContainerID"}} - fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error { - if podFullName != expectedPodName { - t.Errorf("expected %s, got %s", expectedPodName, podFullName) - } - if containerName != expectedContainerName { - t.Errorf("expected %s, got %s", expectedContainerName, containerName) - } - if tail != expectedTail { - t.Errorf("expected %s, got %s", expectedTail, tail) - } - if follow != expectedFollow { - t.Errorf("expected %t, got %t", expectedFollow, follow) - } - return nil - } - resp, err := http.Get(fw.testHTTPServer.URL+"/containerLogs/" + podName + "/" + expectedContainerName) - if err != nil { - t.Errorf("Got error GETing: %v", err) - } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Errorf("Error reading container logs: %v", err) - } - result := string(body) - if result != string(body) { - t.Errorf("Expected: '%v', got: '%v'", output, result) - } + fw := newServerTest() + output := "foo bar" + podName := "foo" + expectedPodName := podName + ".etcd" + expectedContainerName := "baz" + expectedTail := "" + expectedFollow := false + // expected := api.Container{"goodpod": docker.Container{ID: "myContainerID"}} + fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error { + if podFullName != expectedPodName { + t.Errorf("expected %s, got %s", expectedPodName, podFullName) + } + if containerName != expectedContainerName { + t.Errorf("expected %s, got %s", expectedContainerName, containerName) + } + if tail != expectedTail { + t.Errorf("expected %s, got %s", expectedTail, tail) + } + if follow != expectedFollow { + t.Errorf("expected %t, got %t", expectedFollow, follow) + } + return nil + } + resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podName + "/" + expectedContainerName) + if err != nil { + t.Errorf("Got error GETing: %v", err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Errorf("Error reading container logs: %v", err) + } + result := string(body) + if result != string(body) { + t.Errorf("Expected: '%v', got: '%v'", output, result) + } } func TestContainerLogsWithTail(t *testing.T) { - fw := newServerTest() - output := "foo bar" - podName := "foo" - expectedPodName := podName + ".etcd" - expectedContainerName := "baz" - expectedTail := "5" - expectedFollow := false - fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error { - if podFullName != expectedPodName { - t.Errorf("expected %s, got %s", expectedPodName, podFullName) - } - if containerName != expectedContainerName { - t.Errorf("expected %s, got %s", expectedContainerName, containerName) - } - if tail != expectedTail { - t.Errorf("expected %s, got %s", expectedTail, tail) - } - if follow != expectedFollow { - t.Errorf("expected %t, got %t", expectedFollow, follow) - } - return nil - } - resp, err := http.Get(fw.testHTTPServer.URL+"/containerLogs/" + podName + "/" + expectedContainerName + "?tail=5") - if err != nil { - t.Errorf("Got error GETing: %v", err) - } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Errorf("Error reading container logs: %v", err) - } - result := string(body) - if result != string(body) { - t.Errorf("Expected: '%v', got: '%v'", output, result) - } + fw := newServerTest() + output := "foo bar" + podName := "foo" + expectedPodName := podName + ".etcd" + expectedContainerName := "baz" + expectedTail := "5" + expectedFollow := false + fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error { + if podFullName != expectedPodName { + t.Errorf("expected %s, got %s", expectedPodName, podFullName) + } + if containerName != expectedContainerName { + t.Errorf("expected %s, got %s", expectedContainerName, containerName) + } + if tail != expectedTail { + t.Errorf("expected %s, got %s", expectedTail, tail) + } + if follow != expectedFollow { + t.Errorf("expected %t, got %t", expectedFollow, follow) + } + return nil + } + resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podName + "/" + expectedContainerName + "?tail=5") + if err != nil { + t.Errorf("Got error GETing: %v", err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Errorf("Error reading container logs: %v", err) + } + result := string(body) + if result != string(body) { + t.Errorf("Expected: '%v', got: '%v'", output, result) + } } func TestContainerLogsWithFollow(t *testing.T) { - fw := newServerTest() - output := "foo bar" - podName := "foo" - expectedPodName := podName + ".etcd" - expectedContainerName := "baz" - expectedTail := "" - expectedFollow := true - fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error { - if podFullName != expectedPodName { - t.Errorf("expected %s, got %s", expectedPodName, podFullName) - } - if containerName != expectedContainerName { - t.Errorf("expected %s, got %s", expectedContainerName, containerName) - } - if tail != expectedTail { - t.Errorf("expected %s, got %s", expectedTail, tail) - } - if follow != expectedFollow { - t.Errorf("expected %t, got %t", expectedFollow, follow) - } - return nil - } - resp, err := http.Get(fw.testHTTPServer.URL+"/containerLogs/" + podName + "/" + expectedContainerName + "?follow=1") - if err != nil { - t.Errorf("Got error GETing: %v", err) - } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Errorf("Error reading container logs: %v", err) - } - result := string(body) - if result != string(body) { - t.Errorf("Expected: '%v', got: '%v'", output, result) - } + fw := newServerTest() + output := "foo bar" + podName := "foo" + expectedPodName := podName + ".etcd" + expectedContainerName := "baz" + expectedTail := "" + expectedFollow := true + fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error { + if podFullName != expectedPodName { + t.Errorf("expected %s, got %s", expectedPodName, podFullName) + } + if containerName != expectedContainerName { + t.Errorf("expected %s, got %s", expectedContainerName, containerName) + } + if tail != expectedTail { + t.Errorf("expected %s, got %s", expectedTail, tail) + } + if follow != expectedFollow { + t.Errorf("expected %t, got %t", expectedFollow, follow) + } + return nil + } + resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podName + "/" + expectedContainerName + "?follow=1") + if err != nil { + t.Errorf("Got error GETing: %v", err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Errorf("Error reading container logs: %v", err) + } + result := string(body) + if result != string(body) { + t.Errorf("Expected: '%v', got: '%v'", output, result) + } }