Skip to content

Commit

Permalink
Fix most golint issues that are not comment related (#1982)
Browse files Browse the repository at this point in the history
Signed-off-by: Radu Matei <radu@radu-matei.com>
  • Loading branch information
radu-matei authored and siggy committed Dec 20, 2018
1 parent 10d5ebd commit 07cbfe2
Show file tree
Hide file tree
Showing 70 changed files with 455 additions and 450 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func configureAndRunChecks(options *checkOptions) {

checks = append(checks, healthcheck.LinkerdVersionChecks)

hc := healthcheck.NewHealthChecker(checks, &healthcheck.HealthCheckOptions{
hc := healthcheck.NewHealthChecker(checks, &healthcheck.Options{
ControlPlaneNamespace: controlPlaneNamespace,
DataPlaneNamespace: options.namespace,
KubeConfig: kubeconfigPath,
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestCheckStatus(t *testing.T) {
t.Run("Prints expected output", func(t *testing.T) {
hc := healthcheck.NewHealthChecker(
[]healthcheck.Checks{},
&healthcheck.HealthCheckOptions{},
&healthcheck.Options{},
)
hc.Add("category", "check1", func() error {
return nil
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newCmdDashboard() *cobra.Command {
os.Exit(1)
}

grafanaUrl, err := kubernetesProxy.URLFor(controlPlaneNamespace, "/services/linkerd-grafana:http/proxy/")
grafanaURL, err := kubernetesProxy.URLFor(controlPlaneNamespace, "/services/linkerd-grafana:http/proxy/")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to generate URL for Grafana: %s\n", err)
os.Exit(1)
Expand All @@ -74,7 +74,7 @@ func newCmdDashboard() *cobra.Command {
validatedPublicAPIClient(time.Now().Add(options.wait))

fmt.Printf("Linkerd dashboard available at:\n%s\n", url.String())
fmt.Printf("Grafana dashboard available at:\n%s\n", grafanaUrl.String())
fmt.Printf("Grafana dashboard available at:\n%s\n", grafanaURL.String())

switch options.dashboardShow {
case showLinkerd:
Expand All @@ -88,9 +88,9 @@ func newCmdDashboard() *cobra.Command {
case showGrafana:
fmt.Println("Opening Grafana dashboard in the default browser")

err = browser.OpenURL(grafanaUrl.String())
err = browser.OpenURL(grafanaURL.String())
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open Grafana URL %s in the default browser: %s", grafanaUrl, err)
fmt.Fprintf(os.Stderr, "Failed to open Grafana URL %s in the default browser: %s", grafanaURL, err)
os.Exit(1)
}
case showURL:
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestGetPods(t *testing.T) {
t.Run("Returns names of existing pods if everything went ok", func(t *testing.T) {
mockClient := &public.MockApiClient{}
mockClient := &public.MockAPIClient{}

pods := []*pb.Pod{
{Name: "pod-a"},
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestGetPods(t *testing.T) {
})

t.Run("Returns empty list if no pods found", func(t *testing.T) {
mockClient := &public.MockApiClient{}
mockClient := &public.MockAPIClient{}

mockClient.ListPodsResponseToReturn = &pb.ListPodsResponse{
Pods: []*pb.Pod{},
Expand All @@ -59,7 +59,7 @@ func TestGetPods(t *testing.T) {
})

t.Run("Returns error if cant find pods in API", func(t *testing.T) {
mockClient := &public.MockApiClient{}
mockClient := &public.MockAPIClient{}
mockClient.ErrorToReturn = errors.New("expected")

_, err := getPods(mockClient, newGetOptions())
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
LocalhostDNSNameOverride = "localhost."
// ControlPlanePodName default control plane pod name.
ControlPlanePodName = "linkerd-controller"
// The name of the variable used to pass the pod's namespace.
// PodNamespaceEnvVarName is the name of the variable used to pass the pod's namespace.
PodNamespaceEnvVarName = "LINKERD2_PROXY_POD_NAMESPACE"

// for inject reports
Expand Down Expand Up @@ -251,8 +251,8 @@ func injectPodSpec(t *v1.PodSpec, identity k8s.TLSIdentity, controlPlaneDNSNameO
Requests: v1.ResourceList{},
}

if options.proxyCpuRequest != "" {
resources.Requests["cpu"] = k8sResource.MustParse(options.proxyCpuRequest)
if options.proxyCPURequest != "" {
resources.Requests["cpu"] = k8sResource.MustParse(options.proxyCPURequest)
}

if options.proxyMemoryRequest != "" {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestInjectYAML(t *testing.T) {

proxyRequestOptions := newInjectOptions()
proxyRequestOptions.linkerdVersion = "testinjectversion"
proxyRequestOptions.proxyCpuRequest = "110m"
proxyRequestOptions.proxyCPURequest = "110m"
proxyRequestOptions.proxyMemoryRequest = "100Mi"

testCases := []struct {
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func validateAndBuildConfig(options *installOptions) (*installConfig, error) {
options.controllerReplicas = defaultHAControllerReplicas
}

if options.highAvailability && options.proxyCpuRequest == "" {
options.proxyCpuRequest = "10m"
if options.highAvailability && options.proxyCPURequest == "" {
options.proxyCPURequest = "10m"
}

if options.highAvailability && options.proxyMemoryRequest == "" {
Expand Down Expand Up @@ -195,7 +195,7 @@ func validateAndBuildConfig(options *installOptions) (*installConfig, error) {
ProxyInitSpecFileName: k8s.ProxyInitSpecFileName,
ProxyInitImage: options.taggedProxyInitImage(),
ProxyImage: options.taggedProxyImage(),
ProxyResourceRequestCPU: options.proxyCpuRequest,
ProxyResourceRequestCPU: options.proxyCPURequest,
ProxyResourceRequestMemory: options.proxyMemoryRequest,
ProxyBindTimeout: "1m",
SingleNamespace: options.singleNamespace,
Expand All @@ -217,7 +217,7 @@ func render(config installConfig, w io.Writer, options *installOptions) error {
}

if config.EnableTLS {
tlsTemplate, err := template.New("linkerd").Parse(install.TlsTemplate)
tlsTemplate, err := template.New("linkerd").Parse(install.TLSTemplate)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestRender(t *testing.T) {
haWithOverridesOptions := newInstallOptions()
haWithOverridesOptions.highAvailability = true
haWithOverridesOptions.controllerReplicas = 2
haWithOverridesOptions.proxyCpuRequest = "400m"
haWithOverridesOptions.proxyCPURequest = "400m"
haWithOverridesOptions.proxyMemoryRequest = "300Mi"
haWithOverridesConfig, _ := validateAndBuildConfig(haWithOverridesOptions)
haWithOverridesConfig.UUID = "deaab91a-f4ab-448a-b7d1-c832a2fa0a60"
Expand Down
15 changes: 8 additions & 7 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
alphaNumDashDotSlashColon = regexp.MustCompile("^[\\./a-zA-Z0-9-:]+$")
)

// RootCmd represents the root Cobra command
var RootCmd = &cobra.Command{
Use: "linkerd",
Short: "linkerd manages the Linkerd service mesh",
Expand Down Expand Up @@ -94,7 +95,7 @@ func validatedPublicAPIClient(retryDeadline time.Time) pb.ApiClient {
healthcheck.LinkerdAPIChecks,
}

hc := healthcheck.NewHealthChecker(checks, &healthcheck.HealthCheckOptions{
hc := healthcheck.NewHealthChecker(checks, &healthcheck.Options{
ControlPlaneNamespace: controlPlaneNamespace,
KubeConfig: kubeconfigPath,
KubeContext: kubeContext,
Expand Down Expand Up @@ -185,7 +186,7 @@ type proxyConfigOptions struct {
proxyAPIPort uint
proxyControlPort uint
proxyMetricsPort uint
proxyCpuRequest string
proxyCPURequest string
proxyMemoryRequest string
proxyOutboundCapacity map[string]uint
tls string
Expand Down Expand Up @@ -215,7 +216,7 @@ func newProxyConfigOptions() *proxyConfigOptions {
proxyControlPort: 4190,
proxyMetricsPort: 4191,
proxyOutboundCapacity: map[string]uint{},
proxyCpuRequest: "",
proxyCPURequest: "",
proxyMemoryRequest: "",
tls: "",
disableExternalProfiles: false,
Expand All @@ -239,9 +240,9 @@ func (options *proxyConfigOptions) validate() error {
return fmt.Errorf("Invalid duration '%s' for --proxy-bind-timeout flag", options.proxyBindTimeout)
}

if options.proxyCpuRequest != "" {
if _, err := k8sResource.ParseQuantity(options.proxyCpuRequest); err != nil {
return fmt.Errorf("Invalid cpu request '%s' for --proxy-cpu flag", options.proxyCpuRequest)
if options.proxyCPURequest != "" {
if _, err := k8sResource.ParseQuantity(options.proxyCPURequest); err != nil {
return fmt.Errorf("Invalid cpu request '%s' for --proxy-cpu flag", options.proxyCPURequest)
}
}

Expand Down Expand Up @@ -287,7 +288,7 @@ func addProxyConfigFlags(cmd *cobra.Command, options *proxyConfigOptions) {
cmd.PersistentFlags().UintVar(&options.proxyControlPort, "control-port", options.proxyControlPort, "Proxy port to use for control")
cmd.PersistentFlags().UintVar(&options.proxyMetricsPort, "metrics-port", options.proxyMetricsPort, "Proxy port to serve metrics on")
cmd.PersistentFlags().StringVar(&options.tls, "tls", options.tls, "Enable TLS; valid settings: \"optional\"")
cmd.PersistentFlags().StringVar(&options.proxyCpuRequest, "proxy-cpu", options.proxyCpuRequest, "Amount of CPU units that the proxy sidecar requests")
cmd.PersistentFlags().StringVar(&options.proxyCPURequest, "proxy-cpu", options.proxyCPURequest, "Amount of CPU units that the proxy sidecar requests")
cmd.PersistentFlags().StringVar(&options.proxyMemoryRequest, "proxy-memory", options.proxyMemoryRequest, "Amount of Memory that the proxy sidecar requests")
cmd.PersistentFlags().UintSliceVar(&options.ignoreInboundPorts, "skip-inbound-ports", options.ignoreInboundPorts, "Ports that should skip the proxy and send directly to the application")
cmd.PersistentFlags().UintSliceVar(&options.ignoreOutboundPorts, "skip-outbound-ports", options.ignoreOutboundPorts, "Outbound ports that should skip the proxy")
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func writeRouteStatsToBuffer(resp *pb.TopRoutesResponse, w *tabwriter.Writer, op
}
printRouteTable(table, w, options)
case "json":
printRouteJson(table, w)
printRouteJSON(table, w)
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ type jsonRouteStats struct {
LatencyMSp99 *uint64 `json:"latency_ms_p99"`
}

func printRouteJson(stats []*rowStats, w *tabwriter.Writer) {
func printRouteJSON(stats []*rowStats, w *tabwriter.Writer) {
// avoid nil initialization so that if there are not stats it gets marshalled as an empty array vs null
entries := []*jsonRouteStats{}
for _, row := range stats {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestRoutes(t *testing.T) {
}

func testRoutesCall(exp routesParamsExp, t *testing.T) {
mockClient := &public.MockApiClient{}
mockClient := &public.MockAPIClient{}

response := public.GenTopRoutesResponse(exp.routes, exp.counts)

Expand Down
16 changes: 8 additions & 8 deletions cli/cmd/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer,
statTables[resourceKey][key].rowStats = &rowStats{
requestRate: util.GetRequestRate(r.Stats, r.TimeWindow),
successRate: util.GetSuccessRate(r.Stats),
tlsPercent: util.GetPercentTls(r.Stats),
tlsPercent: util.GetPercentTLS(r.Stats),
latencyP50: r.Stats.LatencyMsP50,
latencyP95: r.Stats.LatencyMsP95,
latencyP99: r.Stats.LatencyMsP99,
Expand All @@ -283,7 +283,7 @@ func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer,
}
printStatTables(statTables, w, maxNameLength, maxNamespaceLength, options)
case "json":
printStatJson(statTables, w)
printStatJSON(statTables, w)
}
}

Expand Down Expand Up @@ -386,10 +386,10 @@ type jsonStats struct {
LatencyMSp50 *uint64 `json:"latency_ms_p50"`
LatencyMSp95 *uint64 `json:"latency_ms_p95"`
LatencyMSp99 *uint64 `json:"latency_ms_p99"`
Tls *float64 `json:"tls"`
TLS *float64 `json:"tls"`
}

func printStatJson(statTables map[string]map[string]*row, w *tabwriter.Writer) {
func printStatJSON(statTables map[string]map[string]*row, w *tabwriter.Writer) {
// avoid nil initialization so that if there are not stats it gets marshalled as an empty array vs null
entries := []*jsonStats{}
for _, resourceType := range k8s.AllResources {
Expand All @@ -409,7 +409,7 @@ func printStatJson(statTables map[string]map[string]*row, w *tabwriter.Writer) {
entry.LatencyMSp50 = &stats[key].latencyP50
entry.LatencyMSp95 = &stats[key].latencyP95
entry.LatencyMSp99 = &stats[key].latencyP99
entry.Tls = &stats[key].tlsPercent
entry.TLS = &stats[key].tlsPercent
}

entries = append(entries, entry)
Expand All @@ -427,10 +427,10 @@ func printStatJson(statTables map[string]map[string]*row, w *tabwriter.Writer) {
func getNamePrefix(resourceType string) string {
if resourceType == "" {
return ""
} else {
canonicalType := k8s.ShortNameFromCanonicalResourceName(resourceType)
return canonicalType + "/"
}

canonicalType := k8s.ShortNameFromCanonicalResourceName(resourceType)
return canonicalType + "/"
}

func buildStatSummaryRequests(resources []string, options *statOptions) ([]*pb.StatSummaryRequest, error) {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestStat(t *testing.T) {
}

func testStatCall(exp paramsExp, t *testing.T) {
mockClient := &public.MockApiClient{}
mockClient := &public.MockAPIClient{}

response := public.GenStatSummaryResponse("emoji", k8s.Namespace, exp.resNs, exp.counts, true)

Expand Down
30 changes: 15 additions & 15 deletions cli/cmd/tap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ func busyTest(t *testing.T, wide bool) {
},
map[string]string{},
)
mockApiClient := &public.MockApiClient{}
mockApiClient.Api_TapByResourceClientToReturn = &public.MockApi_TapByResourceClient{
mockAPIClient := &public.MockAPIClient{}
mockAPIClient.APITapByResourceClientToReturn = &public.MockAPITapByResourceClient{
TapEventsToReturn: []pb.TapEvent{event1, event2},
}

writer := bytes.NewBufferString("")
err = requestTapByResourceFromAPI(writer, mockApiClient, req, wide)
err = requestTapByResourceFromAPI(writer, mockAPIClient, req, wide)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down Expand Up @@ -125,13 +125,13 @@ func TestRequestTapByResourceFromAPI(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}

mockApiClient := &public.MockApiClient{}
mockApiClient.Api_TapByResourceClientToReturn = &public.MockApi_TapByResourceClient{
mockAPIClient := &public.MockAPIClient{}
mockAPIClient.APITapByResourceClientToReturn = &public.MockAPITapByResourceClient{
TapEventsToReturn: []pb.TapEvent{},
}

writer := bytes.NewBufferString("")
err = requestTapByResourceFromAPI(writer, mockApiClient, req, false)
err = requestTapByResourceFromAPI(writer, mockAPIClient, req, false)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down Expand Up @@ -164,13 +164,13 @@ func TestRequestTapByResourceFromAPI(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}

mockApiClient := &public.MockApiClient{}
mockApiClient.Api_TapByResourceClientToReturn = &public.MockApi_TapByResourceClient{
mockAPIClient := &public.MockAPIClient{}
mockAPIClient.APITapByResourceClientToReturn = &public.MockAPITapByResourceClient{
ErrorsToReturn: []error{errors.New("expected")},
}

writer := bytes.NewBufferString("")
err = requestTapByResourceFromAPI(writer, mockApiClient, req, false)
err = requestTapByResourceFromAPI(writer, mockAPIClient, req, false)
if err == nil {
t.Fatalf("Expecting error, got nothing but output [%s]", writer.String())
}
Expand All @@ -179,18 +179,18 @@ func TestRequestTapByResourceFromAPI(t *testing.T) {

func TestEventToString(t *testing.T) {
toTapEvent := func(httpEvent *pb.TapEvent_Http) *pb.TapEvent {
streamId := &pb.TapEvent_Http_StreamId{
streamID := &pb.TapEvent_Http_StreamId{
Base: 7,
Stream: 8,
}

switch httpEvent.Event.(type) {
case *pb.TapEvent_Http_RequestInit_:
httpEvent.GetRequestInit().Id = streamId
httpEvent.GetRequestInit().Id = streamID
case *pb.TapEvent_Http_ResponseInit_:
httpEvent.GetResponseInit().Id = streamId
httpEvent.GetResponseInit().Id = streamID
case *pb.TapEvent_Http_ResponseEnd_:
httpEvent.GetResponseEnd().Id = streamId
httpEvent.GetResponseEnd().Id = streamID
}

return &pb.TapEvent{
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestEventToString(t *testing.T) {
})
}

func createEvent(event_http *pb.TapEvent_Http, dstMeta map[string]string) pb.TapEvent {
func createEvent(eventHTTP *pb.TapEvent_Http, dstMeta map[string]string) pb.TapEvent {
event := pb.TapEvent{
ProxyDirection: pb.TapEvent_OUTBOUND,
Source: &pb.TcpAddress{
Expand All @@ -359,7 +359,7 @@ func createEvent(event_http *pb.TapEvent_Http, dstMeta map[string]string) pb.Tap
},
},
Event: &pb.TapEvent_Http_{
Http: event_http,
Http: eventHTTP,
},
DestinationMeta: &pb.TapEvent_EndpointMeta{
Labels: dstMeta,
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)

const DefaultVersionString = "unavailable"
const defaultVersionString = "unavailable"

type versionOptions struct {
shortVersion bool
Expand Down Expand Up @@ -67,7 +67,7 @@ func newCmdVersion() *cobra.Command {
func getServerVersion(client pb.ApiClient) string {
resp, err := client.Version(context.Background(), &pb.Empty{})
if err != nil {
return DefaultVersionString
return defaultVersionString
}

return resp.GetReleaseVersion()
Expand Down
Loading

0 comments on commit 07cbfe2

Please sign in to comment.