Skip to content

Commit

Permalink
Fixing several (but not all) go vet errors. Most are around string fo…
Browse files Browse the repository at this point in the history
…rmatting, or unreachable code.
  • Loading branch information
goltermann committed Mar 23, 2016
1 parent 1f8773e commit 34d4eae
Show file tree
Hide file tree
Showing 42 changed files with 68 additions and 72 deletions.
2 changes: 1 addition & 1 deletion cluster/addons/dns/kube2sky/kube2sky.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (ks *kube2sky) mutateEtcdOrDie(mutator func() error) {
for {
select {
case <-timeout:
glog.Fatalf("Failed to mutate etcd for %v using mutator: %v", ks.etcdMutationTimeout, mutator)
glog.Fatalf("Failed to mutate etcd for %v using mutator: %v", ks.etcdMutationTimeout, mutator())
default:
if err := mutator(); err != nil {
delay := 50 * time.Millisecond
Expand Down
6 changes: 3 additions & 3 deletions cmd/kube-apiserver/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ func TestParseRuntimeConfig(t *testing.T) {
apiGroupVersionOverrides, err := parseRuntimeConfig(s)

if err == nil && test.err {
t.Fatalf("expected error for test: %q", test)
t.Fatalf("expected error for test: %v", test)
} else if err != nil && !test.err {
t.Fatalf("unexpected error: %s, for test: %q", err, test)
t.Fatalf("unexpected error: %s, for test: %v", err, test)
}

if err == nil && !reflect.DeepEqual(apiGroupVersionOverrides, test.apiGroupVersionOverrides) {
t.Fatalf("unexpected apiGroupVersionOverrides. Actual: %q, expected: %q", apiGroupVersionOverrides, test.apiGroupVersionOverrides)
t.Fatalf("unexpected apiGroupVersionOverrides. Actual: %v, expected: %v", apiGroupVersionOverrides, test.apiGroupVersionOverrides)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/kube-proxy/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ func getProxyMode(proxyMode string, client nodeGetter, hostname string, iptver i
}
node, err := client.Get(hostname)
if err != nil {
glog.Errorf("Can't get Node %q, assuming iptables proxy: %v", hostname, err)
glog.Errorf("Can't get Node %q, assuming iptables proxy, err: %v", hostname, err)
return tryIptablesProxy(iptver, kcompat)
}
if node == nil {
glog.Errorf("Got nil Node %q, assuming iptables proxy: %v", hostname)
glog.Errorf("Got nil Node %q, assuming iptables proxy", hostname)
return tryIptablesProxy(iptver, kcompat)
}
proxyMode, found := node.Annotations[betaProxyModeAnnotation]
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/rest/resttest/resttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (t *Tester) testDeleteGracefulHasDefault(obj runtime.Object, setFn SetFunc,
t.Errorf("unexpected error: %v", err)
}
if _, err := getFn(ctx, foo); err != nil {
t.Fatalf("did not gracefully delete resource", err)
t.Fatalf("did not gracefully delete resource: %v", err)
}

object, err := t.storage.(rest.Getter).Get(ctx, objectMeta.Name)
Expand All @@ -601,7 +601,7 @@ func (t *Tester) testDeleteGracefulWithValue(obj runtime.Object, setFn SetFunc,
t.Errorf("unexpected error: %v", err)
}
if _, err := getFn(ctx, foo); err != nil {
t.Fatalf("did not gracefully delete resource", err)
t.Fatalf("did not gracefully delete resource: %v", err)
}

object, err := t.storage.(rest.Getter).Get(ctx, objectMeta.Name)
Expand All @@ -628,7 +628,7 @@ func (t *Tester) testDeleteGracefulExtend(obj runtime.Object, setFn SetFunc, get
t.Errorf("unexpected error: %v", err)
}
if _, err := getFn(ctx, foo); err != nil {
t.Fatalf("did not gracefully delete resource", err)
t.Fatalf("did not gracefully delete resource: %v", err)
}

// second delete duration is ignored
Expand Down Expand Up @@ -660,7 +660,7 @@ func (t *Tester) testDeleteGracefulImmediate(obj runtime.Object, setFn SetFunc,
t.Errorf("unexpected error: %v", err)
}
if _, err := getFn(ctx, foo); err != nil {
t.Fatalf("did not gracefully delete resource", err)
t.Fatalf("did not gracefully delete resource: %v", err)
}

// second delete is immediate, resource is deleted
Expand Down
12 changes: 6 additions & 6 deletions pkg/apiserver/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestProxyRequestContentLengthAndTransferEncoding(t *testing.T) {
// Dial the proxy server
conn, err := net.Dial(server.Listener.Addr().Network(), server.Listener.Addr().String())
if err != nil {
t.Errorf("%s: unexpected error %v", err)
t.Errorf("%s: unexpected error %v", k, err)
continue
}
defer conn.Close()
Expand All @@ -228,28 +228,28 @@ func TestProxyRequestContentLengthAndTransferEncoding(t *testing.T) {
// Write the request headers
post := fmt.Sprintf("POST /%s/%s/%s/proxy/namespaces/default/foo/id/some/dir HTTP/1.1\r\n", prefix, newGroupVersion.Group, newGroupVersion.Version)
if _, err := fmt.Fprint(conn, post); err != nil {
t.Fatalf("%s: unexpected error %v", err)
t.Fatalf("%s: unexpected error %v", k, err)
}
for header, values := range item.reqHeaders {
for _, value := range values {
if _, err := fmt.Fprintf(conn, "%s: %s\r\n", header, value); err != nil {
t.Fatalf("%s: unexpected error %v", err)
t.Fatalf("%s: unexpected error %v", k, err)
}
}
}
// Header separator
if _, err := fmt.Fprint(conn, "\r\n"); err != nil {
t.Fatalf("%s: unexpected error %v", err)
t.Fatalf("%s: unexpected error %v", k, err)
}
// Body
if _, err := conn.Write(item.reqBody); err != nil {
t.Fatalf("%s: unexpected error %v", err)
t.Fatalf("%s: unexpected error %v", k, err)
}

// Read response
response, err := ioutil.ReadAll(conn)
if err != nil {
t.Errorf("%s: unexpected error %v", err)
t.Errorf("%s: unexpected error %v", k, err)
continue
}
if !strings.HasSuffix(string(response), successfulResponse) {
Expand Down
2 changes: 0 additions & 2 deletions pkg/client/testing/core/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ func ObjectReaction(o ObjectRetriever, mapper meta.RESTMapper) ReactionFunc {
default:
return false, nil, fmt.Errorf("no reaction implemented for %s", action)
}

return true, nil, nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ func (s *AWSCloud) describeLoadBalancer(name string) (*elb.LoadBalancerDescripti
func (self *AWSCloud) findVPCID() (string, error) {
macs, err := self.metadata.GetMetadata("network/interfaces/macs/")
if err != nil {
return "", fmt.Errorf("Could not list interfaces of the instance", err)
return "", fmt.Errorf("Could not list interfaces of the instance: %v", err)
}

// loop over interfaces, first vpc id returned wins
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/providers/aws/aws_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (s *AWSCloud) CreateRoute(clusterName string, nameHint string, route *cloud

_, err = s.ec2.DeleteRoute(request)
if err != nil {
return fmt.Errorf("error deleting blackholed AWS route (%s): %v", deleteRoute.DestinationCidrBlock, err)
return fmt.Errorf("error deleting blackholed AWS route (%s): %v", aws.StringValue(deleteRoute.DestinationCidrBlock), err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/providers/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func TestFindVPCID(t *testing.T) {
}
vpcID, err := c.findVPCID()
if err != nil {
t.Errorf("Unexpected error:", err)
t.Errorf("Unexpected error: %v", err)
}
if vpcID != "vpc-mac0" {
t.Errorf("Unexpected vpcID: %s", vpcID)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/job/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestControllerSyncJob(t *testing.T) {
// run
err := manager.syncJob(getKey(job, t))
if err != nil {
t.Errorf("%s: unexpected error when syncing jobs %v", err)
t.Errorf("%s: unexpected error when syncing jobs %v", name, err)
}

// validate created/deleted pods
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestSyncJobPastDeadline(t *testing.T) {
// run
err := manager.syncJob(getKey(job, t))
if err != nil {
t.Errorf("%s: unexpected error when syncing jobs %v", err)
t.Errorf("%s: unexpected error when syncing jobs %v", name, err)
}

// validate created/deleted pods
Expand Down
2 changes: 1 addition & 1 deletion pkg/credentialprovider/aws/aws_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (p *ecrProvider) Provide() credentialprovider.DockerConfig {
data.AuthorizationToken != nil {
decodedToken, err := base64.StdEncoding.DecodeString(aws.StringValue(data.AuthorizationToken))
if err != nil {
glog.Errorf("while decoding token for endpoint %s %v", data.ProxyEndpoint, err)
glog.Errorf("while decoding token for endpoint %v %v", data.ProxyEndpoint, err)
return cfg
}
parts := strings.SplitN(string(decodedToken), ":", 2)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func TestGenerateService(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
if test.expectPOST != sawPOST {
t.Error("expectPost: %v, sawPost: %v", test.expectPOST, sawPOST)
t.Errorf("expectPost: %v, sawPost: %v", test.expectPOST, sawPOST)
}
}
}
2 changes: 1 addition & 1 deletion pkg/kubectl/resource_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ func printConfigMapList(list *api.ConfigMapList, w io.Writer, options PrintOptio
}

func printPodSecurityPolicy(item *extensions.PodSecurityPolicy, w io.Writer, options PrintOptions) error {
_, err := fmt.Fprintf(w, "%s\t%t\t%v\t%t\t%s\t%s\n", item.Name, item.Spec.Privileged,
_, err := fmt.Fprintf(w, "%s\t%t\t%v\t%v\t%s\t%s\n", item.Name, item.Spec.Privileged,
item.Spec.Capabilities, item.Spec.Volumes, item.Spec.SELinux.Rule,
item.Spec.RunAsUser.Rule)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cm/container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (cm *containerManagerImpl) setupNode() error {
cm.periodicTasks = append(cm.periodicTasks, func() {
cont, err := getContainer(os.Getpid())
if err != nil {
glog.Error("failed to find cgroups of kubelet - %v", err)
glog.Errorf("failed to find cgroups of kubelet - %v", err)
return
}
cm.Lock()
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/dockertools/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func TestGetRestartCount(t *testing.T) {
}
cs := status.FindContainerStatusByName(containerName)
if cs == nil {
t.Fatal("Can't find status for container %q", containerName)
t.Fatalf("Can't find status for container %q", containerName)
}
restartCount := cs.RestartCount
if restartCount != expectedCount {
Expand All @@ -1161,7 +1161,7 @@ func TestGetRestartCount(t *testing.T) {
}
cs := status.FindContainerStatusByName(containerName)
if cs == nil {
t.Fatal("Can't find status for container %q", containerName)
t.Fatalf("Can't find status for container %q", containerName)
}
dm.KillContainerInPod(cs.ID, &pod.Spec.Containers[0], pod, "test container restart count.")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4165,7 +4165,7 @@ func TestCleanupBandwidthLimits(t *testing.T) {

err := testKube.kubelet.cleanupBandwidthLimits(test.pods)
if err != nil {
t.Errorf("unexpected error: %v (%s)", test.name)
t.Errorf("unexpected error: %v (%s)", test.name, err)
}
if !reflect.DeepEqual(shaper.ResetCIDRs, test.expectResetCIDRs) {
t.Errorf("[%s]\nexpected: %v, saw: %v", test.name, test.expectResetCIDRs, shaper.ResetCIDRs)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/network/kubenet/kubenet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func findMinMTU() (*net.Interface, error) {
}

if mtu >= 999999 || mtu < 576 || defIntfIndex < 0 {
return nil, fmt.Errorf("no suitable interface", BridgeName)
return nil, fmt.Errorf("no suitable interface: %v", BridgeName)
}

return &intfs[defIntfIndex], nil
Expand Down
1 change: 0 additions & 1 deletion pkg/kubelet/pleg/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func generateEvent(podID types.UID, cid string, oldState, newState plegContainer
default:
panic(fmt.Sprintf("unrecognized container state: %v", newState))
}
return nil
}

func (g *GenericPLEG) getRelistTime() time.Time {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/prober/results/results_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestUpdates(t *testing.T) {
select {
case u := <-m.Updates():
if expected != u {
t.Errorf("Expected update %v, recieved %v: %s %s", expected, u, msg)
t.Errorf("Expected update %v, recieved %v: %s", expected, u, msg)
}
case <-time.After(wait.ForeverTestTimeout):
t.Errorf("Timed out waiting for update %v: %s", expected, msg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/rkt/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ func (r *Runtime) GetContainerLogs(pod *api.Pod, containerID kubecontainer.Conta

outPipe, err := cmd.StdoutPipe()
if err != nil {
glog.Errorf("rkt: cannot create pipe for journalctl's stdout", err)
glog.Errorf("rkt: cannot create pipe for journalctl's stdout: %v", err)
return err
}
errPipe, err := cmd.StderrPipe()
if err != nil {
glog.Errorf("rkt: cannot create pipe for journalctl's stderr", err)
glog.Errorf("rkt: cannot create pipe for journalctl's stderr: %v", err)
return err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/rkt/rkt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,31 +713,31 @@ func TestGetPodStatus(t *testing.T) {
func generateCapRetainIsolator(t *testing.T, caps ...string) appctypes.Isolator {
retain, err := appctypes.NewLinuxCapabilitiesRetainSet(caps...)
if err != nil {
t.Fatalf("Error generating cap retain isolator", err)
t.Fatalf("Error generating cap retain isolator: %v", err)
}
return retain.AsIsolator()
}

func generateCapRevokeIsolator(t *testing.T, caps ...string) appctypes.Isolator {
revoke, err := appctypes.NewLinuxCapabilitiesRevokeSet(caps...)
if err != nil {
t.Fatalf("Error generating cap revoke isolator", err)
t.Fatalf("Error generating cap revoke isolator: %v", err)
}
return revoke.AsIsolator()
}

func generateCPUIsolator(t *testing.T, request, limit string) appctypes.Isolator {
cpu, err := appctypes.NewResourceCPUIsolator(request, limit)
if err != nil {
t.Fatalf("Error generating cpu resource isolator", err)
t.Fatalf("Error generating cpu resource isolator: %v", err)
}
return cpu.AsIsolator()
}

func generateMemoryIsolator(t *testing.T, request, limit string) appctypes.Isolator {
memory, err := appctypes.NewResourceMemoryIsolator(request, limit)
if err != nil {
t.Fatalf("Error generating memory resource isolator", err)
t.Fatalf("Error generating memory resource isolator: %v", err)
}
return memory.AsIsolator()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,11 @@ func (h *portForwardStreamHandler) getStreamPair(requestID string) (*portForward
func (h *portForwardStreamHandler) monitorStreamPair(p *portForwardStreamPair, timeout <-chan time.Time) {
select {
case <-timeout:
err := fmt.Errorf("(conn=%p, request=%s) timed out waiting for streams", h.conn, p.requestID)
err := fmt.Errorf("(conn=%v, request=%s) timed out waiting for streams", h.conn, p.requestID)
utilruntime.HandleError(err)
p.printError(err.Error())
case <-p.complete:
glog.V(5).Infof("(conn=%p, request=%s) successfully received error and data streams", h.conn, p.requestID)
glog.V(5).Infof("(conn=%v, request=%s) successfully received error and data streams", h.conn, p.requestID)
}
h.removeStreamPair(p.requestID)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/status/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func TestReconcilePodStatus(t *testing.T) {

podStatus, ok := syncer.GetPodStatus(testPod.UID)
if !ok {
t.Fatal("Should find pod status for pod: %+v", testPod)
t.Fatalf("Should find pod status for pod: %+v", testPod)
}
testPod.Status = podStatus

Expand Down
2 changes: 1 addition & 1 deletion pkg/master/thirdparty_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestSyncAPIs(t *testing.T) {
cntrl := ThirdPartyController{master: &fake}

if err := cntrl.syncResourceList(test.list); err != nil {
t.Errorf("[%s] unexpected error: %v", test.name)
t.Errorf("[%s] unexpected error: %v", test.name, err)
}
if len(test.expectedInstalled) != len(fake.installed) {
t.Errorf("[%s] unexpected installed APIs: %d, expected %d (%#v)", test.name, len(fake.installed), len(test.expectedInstalled), fake.installed[0])
Expand Down
1 change: 0 additions & 1 deletion pkg/metrics/generic_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func parseMetrics(data string, knownMetrics map[string][]string, output *Metrics
}
}
}
return nil
}

func (g *MetricsGrabber) getMetricsFromPod(podName string, namespace string, port int) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/quota/generic/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (g *GenericEvaluator) UsageStats(options quota.UsageStatsOptions) (quota.Us
}
list, err := g.ListFuncByNamespace(options.Namespace, api.ListOptions{})
if err != nil {
return result, fmt.Errorf("%s: Failed to list %v: %v", g.Name, g.GroupKind, err)
return result, fmt.Errorf("%s: Failed to list %v: %v", g.Name, g.GroupKind(), err)
}
_, err = meta.Accessor(list)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/quota/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestIsZero(t *testing.T) {
}
for testName, testCase := range testCases {
if result := IsZero(testCase.a); result != testCase.expected {
t.Errorf("%s expected: %v, actual: %v", testName, testCase.expected)
t.Errorf("%s expected: %v, actual: %v", testName, testCase.expected, result)
}
}
}
Loading

0 comments on commit 34d4eae

Please sign in to comment.