Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make lint #495

Merged
merged 1 commit into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ LDFLAGS = $(shell ./hack/version.sh)
DOCKER_REGISTRY := $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY),localhost:5000)

PACKAGE_LIST := go list ./... | grep -vE "pkg/client" | grep -vE "zz_generated"
PACKAGES := $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/tidb-operator/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'
Expand Down Expand Up @@ -117,7 +116,7 @@ check-shadow:

lint:
@echo "linting"
CGO_ENABLED=0 retool do revive -formatter friendly -config revive.toml $$($(PACKAGES))
CGO_ENABLED=0 retool do revive -formatter friendly -config revive.toml $$($(PACKAGE_LIST))

check-gosec:
@echo "security checking"
Expand Down
14 changes: 7 additions & 7 deletions pkg/discovery/server/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ func StartServer(cli versioned.Interface, port int) {
}

func (svr *server) newHandler(req *restful.Request, resp *restful.Response) {
encodedAdvertisePeerUrl := req.PathParameter("advertise-peer-url")
data, err := base64.StdEncoding.DecodeString(encodedAdvertisePeerUrl)
encodedAdvertisePeerURL := req.PathParameter("advertise-peer-url")
data, err := base64.StdEncoding.DecodeString(encodedAdvertisePeerURL)
if err != nil {
glog.Errorf("failed to decode advertise-peer-url: %s", encodedAdvertisePeerUrl)
glog.Errorf("failed to decode advertise-peer-url: %s", encodedAdvertisePeerURL)
if err := resp.WriteError(http.StatusInternalServerError, err); err != nil {
glog.Errorf("failed to writeError: %v", err)
}
return
}
advertisePeerUrl := string(data)
advertisePeerURL := string(data)

result, err := svr.discovery.Discover(advertisePeerUrl)
result, err := svr.discovery.Discover(advertisePeerURL)
if err != nil {
glog.Errorf("failed to discover: %s, %v", advertisePeerUrl, err)
glog.Errorf("failed to discover: %s, %v", advertisePeerURL, err)
if err := resp.WriteError(http.StatusInternalServerError, err); err != nil {
glog.Errorf("failed to writeError: %v", err)
}
return
}

glog.Infof("generated args for %s: %s", advertisePeerUrl, result)
glog.Infof("generated args for %s: %s", advertisePeerURL, result)
if _, err := io.WriteString(resp, result); err != nil {
glog.Errorf("failed to writeString: %s, %v", result, err)
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/tkctl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
package config

import (
"io/ioutil"
"os"
"os/user"
"path/filepath"
"sync"

"github.com/golang/glog"
"gopkg.in/yaml.v2"
"io/ioutil"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericclioptions/resource"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
"os/user"
"path/filepath"
"sync"
Copy link
Contributor Author

@cofyc cofyc May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports changed because the code is formatted by goimports tool in my editor. It automatically puts the standard packages at the front of the import list.


restclient "k8s.io/client-go/rest"
)
Expand Down Expand Up @@ -189,10 +190,7 @@ func (c *TkcContext) SwitchTidbCluster(context, namespace, clusterName string) e
if err != nil {
return err
}
if err := ioutil.WriteFile(tcConfigFile, content, 0644); err != nil {
return err
}
return nil
return ioutil.WriteFile(tcConfigFile, content, 0644)
}

func (c *TkcContext) collectOverrides() *clientcmd.ConfigOverrides {
Expand Down
8 changes: 3 additions & 5 deletions pkg/tkctl/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package executor
import (
"context"
"fmt"
"time"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -30,7 +32,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd"
"k8s.io/kubernetes/pkg/util/interrupt"
"time"
)

const (
Expand Down Expand Up @@ -91,10 +92,7 @@ func (t *PodExecutor) attachPod(pod *v1.Pod) error {
attachOpts.Config = t.RestConfig
setKubernetesDefaults(attachOpts.Config)

if err := attachOpts.Run(); err != nil {
return err
}
return nil
return attachOpts.Run()
}

func (t *PodExecutor) removePod(pod *v1.Pod) error {
Expand Down
22 changes: 11 additions & 11 deletions pkg/tkctl/readable/print_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
package readable

import (
"strings"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
"k8s.io/kubernetes/pkg/kubectl/scheme"
kubeprinters "k8s.io/kubernetes/pkg/printers"
"strings"
)

type PrintFlags struct {
Expand Down Expand Up @@ -47,15 +48,14 @@ func (p *PrintFlags) ToPrinter(withKind, withNamespace bool) (printers.ResourceP
return nil, err
}
return printer, nil
} else {
// Reuse kubectl HumanReadablePrinter
printer := kubeprinters.NewHumanReadablePrinter(scheme.Codecs.UniversalDecoder(),
kubeprinters.PrintOptions{
WithNamespace: withNamespace,
WithKind: withKind,
})
// Add custom handlers
AddHandlers(printer)
return printer, nil
}
// Reuse kubectl HumanReadablePrinter
printer := kubeprinters.NewHumanReadablePrinter(scheme.Codecs.UniversalDecoder(),
kubeprinters.PrintOptions{
WithNamespace: withNamespace,
WithKind: withKind,
})
// Add custom handlers
AddHandlers(printer)
return printer, nil
}
14 changes: 7 additions & 7 deletions pkg/tkctl/readable/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ type PodBasicColumns struct {
Memory string
CPU string
Age string
PodIp string
HostIp string
PodIP string
HostIP string

MemInfo string
CpuInfo string
CPUInfo string
}

func AddHandlers(h printers.PrintHandler) {
Expand Down Expand Up @@ -144,7 +144,7 @@ func printPod(pod *v1.Pod, options printers.PrintOptions) ([]metav1beta1.TableRo
columns.CPU,
columns.Restarts,
columns.Age,
columns.HostIp)
columns.HostIP)
return []metav1beta1.TableRow{row}, nil
}

Expand Down Expand Up @@ -326,10 +326,10 @@ func basicPodColumns(pod *v1.Pod) *PodBasicColumns {
Reason: reason,
Restarts: int64(restarts),
Age: translateTimestampSince(pod.CreationTimestamp),
HostIp: hostIP,
PodIp: podIP,
HostIP: hostIP,
PodIP: podIP,
MemInfo: memInfo,
CpuInfo: cpuInfo,
CPUInfo: cpuInfo,
}
}

Expand Down
3 changes: 2 additions & 1 deletion revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ warningCode = 0
[rule.error-strings]
[rule.error-naming]
[rule.if-return]
[rule.var-naming]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
Expand All @@ -21,6 +20,8 @@ warningCode = 0
[rule.modifies-parameter]

# Add these once issues are fixed
[rule.var-naming]
severity = "warning"
Copy link
Contributor Author

@cofyc cofyc May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of places violates rule.var-naming, it makes the PR too complicated to fix all.

I decide to change the error level of it to "warning" temporarily. We can fix it in a separate PR.

[rule.confusing-naming]
severity = "warning"
[rule.confusing-results]
Expand Down
49 changes: 23 additions & 26 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sync"
"time"

// To register MySQL driver
_ "github.com/go-sql-driver/mysql"
"github.com/golang/glog"
pingcapErrors "github.com/pingcap/errors"
Expand Down Expand Up @@ -211,7 +212,7 @@ type TidbClusterConfig struct {
TiDBImage string
StorageClassName string
Password string
InitSql string
InitSQL string
RecordCount string
InsertBatchSize string
Resources map[string]string
Expand Down Expand Up @@ -280,7 +281,7 @@ func (tc *TidbClusterConfig) TidbClusterHelmSetString(m map[string]string) strin
"tikv.image": tc.TiKVImage,
"tidb.image": tc.TiDBImage,
"tidb.passwordSecretName": tc.InitSecretName,
"tidb.initSql": tc.InitSql,
"tidb.initSql": tc.InitSQL,
"monitor.create": strconv.FormatBool(tc.Monitor),
"enableConfigMapRollout": strconv.FormatBool(tc.EnableConfigMapRollout),
}
Expand Down Expand Up @@ -512,8 +513,8 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterConfig) error {
pvCmd := fmt.Sprintf("kubectl get pv | grep %s | grep %s 2>/dev/null|grep Released",
info.Namespace, info.ClusterName)
glog.V(4).Info(pvCmd)
if res, err := exec.Command("/bin/sh", "-c", pvCmd).
CombinedOutput(); len(res) == 0 {
if res, err := exec.Command("/bin/sh", "-c", pvCmd).CombinedOutput(); len(res) == 0 {
return true, nil
} else if err != nil {
glog.V(4).Infof("waiting for tidbcluster: %s/%s pv deleting, %v, %s",
info.Namespace, info.ClusterName, err, string(res))
Expand Down Expand Up @@ -1534,8 +1535,8 @@ func (oa *operatorActions) checkGrafanaData(clusterInfo *TidbClusterConfig) erro

// Grafana ready, init grafana client, no more sync logic because race condition is okay here
if clusterInfo.GrafanaClient == nil {
grafanaUrl := fmt.Sprintf("http://%s.%s:3000", svcName, ns)
client, err := metrics.NewClient(grafanaUrl, grafanaUsername, grafanaPassword, metricsPort)
grafanaURL := fmt.Sprintf("http://%s.%s:3000", svcName, ns)
client, err := metrics.NewClient(grafanaURL, grafanaUsername, grafanaPassword, metricsPort)
if err != nil {
return err
}
Expand Down Expand Up @@ -1695,17 +1696,13 @@ func (oa *operatorActions) ForceDeploy(info *TidbClusterConfig) error {
return err
}

if err := oa.DeployTidbCluster(info); err != nil {
return err
}

return nil
return oa.DeployTidbCluster(info)
}

func (info *TidbClusterConfig) DataIsTheSameAs(otherInfo *TidbClusterConfig) (bool, error) {
func (tc *TidbClusterConfig) DataIsTheSameAs(otherInfo *TidbClusterConfig) (bool, error) {
tableNum := otherInfo.BlockWriteConfig.TableNum

infoDb, err := sql.Open("mysql", getDSN(info.Namespace, info.ClusterName, "test", info.Password))
infoDb, err := sql.Open("mysql", getDSN(tc.Namespace, tc.ClusterName, "test", tc.Password))
if err != nil {
return false, err
}
Expand Down Expand Up @@ -1751,12 +1748,12 @@ func (info *TidbClusterConfig) DataIsTheSameAs(otherInfo *TidbClusterConfig) (bo

if cnt != otherCnt {
err := fmt.Errorf("cluster %s/%s's table %s count(*) = %d and cluster %s/%s's table %s count(*) = %d",
info.Namespace, info.ClusterName, tableName, cnt,
tc.Namespace, tc.ClusterName, tableName, cnt,
otherInfo.Namespace, otherInfo.ClusterName, tableName, otherCnt)
return false, err
}
glog.Infof("cluster %s/%s's table %s count(*) = %d and cluster %s/%s's table %s count(*) = %d",
info.Namespace, info.ClusterName, tableName, cnt,
tc.Namespace, tc.ClusterName, tableName, cnt,
otherInfo.Namespace, otherInfo.ClusterName, tableName, otherCnt)
}

Expand Down Expand Up @@ -1917,7 +1914,7 @@ func (oa *operatorActions) CheckScheduledBackup(info *TidbClusterConfig) error {
}

if len(dirs) <= 2 {
return fmt.Errorf("scheduler job failed!")
return fmt.Errorf("scheduler job failed")
}

return oa.disableScheduledBackup(info)
Expand Down Expand Up @@ -2021,8 +2018,8 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterConfig) ([]string, erro
return dirs, nil
}

func (info *TidbClusterConfig) FullName() string {
return fmt.Sprintf("%s/%s", info.Namespace, info.ClusterName)
func (tc *TidbClusterConfig) FullName() string {
return fmt.Sprintf("%s/%s", tc.Namespace, tc.ClusterName)
}

func (oa *operatorActions) DeployIncrementalBackup(from *TidbClusterConfig, to *TidbClusterConfig) error {
Expand Down Expand Up @@ -2195,10 +2192,10 @@ type nodeStatus struct {
}

func (oa *operatorActions) pumpHealth(info *TidbClusterConfig, hostName string) bool {
pumpHealthUrl := fmt.Sprintf("%s.%s-pump.%s:8250/status", hostName, info.ClusterName, info.Namespace)
res, err := http.Get(pumpHealthUrl)
pumpHealthURL := fmt.Sprintf("%s.%s-pump.%s:8250/status", hostName, info.ClusterName, info.Namespace)
res, err := http.Get(pumpHealthURL)
if err != nil {
glog.Errorf("cluster:[%s] call %s failed,error:%v", info.ClusterName, pumpHealthUrl, err)
glog.Errorf("cluster:[%s] call %s failed,error:%v", info.ClusterName, pumpHealthURL, err)
return false
}
if res.StatusCode >= 400 {
Expand Down Expand Up @@ -2233,10 +2230,10 @@ type drainerStatus struct {
}

func (oa *operatorActions) drainerHealth(info *TidbClusterConfig, hostName string) bool {
drainerHealthUrl := fmt.Sprintf("%s.%s-drainer.%s:8249/status", hostName, info.ClusterName, info.Namespace)
res, err := http.Get(drainerHealthUrl)
drainerHealthURL := fmt.Sprintf("%s.%s-drainer.%s:8249/status", hostName, info.ClusterName, info.Namespace)
res, err := http.Get(drainerHealthURL)
if err != nil {
glog.Errorf("cluster:[%s] call %s failed,error:%v", info.ClusterName, drainerHealthUrl, err)
glog.Errorf("cluster:[%s] call %s failed,error:%v", info.ClusterName, drainerHealthURL, err)
return false
}
if res.StatusCode >= 400 {
Expand Down Expand Up @@ -2321,8 +2318,8 @@ func (oa *operatorActions) EventWorker() {
for _, ev := range clusterEv.events {
ns := clusterEv.ns
clusterName := clusterEv.clusterName
grafanaUrl := fmt.Sprintf("http://%s-grafana.%s:3000", clusterName, ns)
client, err := metrics.NewClient(grafanaUrl, grafanaUsername, grafanaPassword, metricsPort)
grafanaURL := fmt.Sprintf("http://%s-grafana.%s:3000", clusterName, ns)
client, err := metrics.NewClient(grafanaURL, grafanaUsername, grafanaPassword, metricsPort)
if err != nil {
retryEvents = append(retryEvents, ev)
glog.V(4).Infof("failed to new grafana client: [%s/%s], %v", ns, clusterName, err)
Expand Down
6 changes: 3 additions & 3 deletions tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {
glog.Fatal(err)
}
// create database and table and insert a column for test backup and restore
initSql := `"create database record;use record;create table test(t char(32))"`
initSQL := `"create database record;use record;create table test(t char(32))"`

name1 := "e2e-cluster1"
name2 := "e2e-cluster2"
Expand All @@ -71,7 +71,7 @@ func main() {
TiDBImage: fmt.Sprintf("pingcap/tidb:%s", initTidbVersion),
StorageClassName: "local-storage",
Password: "admin",
InitSql: initSql,
InitSQL: initSQL,
UserName: "root",
InitSecretName: fmt.Sprintf("%s-set-secret", name1),
BackupSecretName: fmt.Sprintf("%s-backup-secret", name1),
Expand Down Expand Up @@ -114,7 +114,7 @@ func main() {
TiDBImage: fmt.Sprintf("pingcap/tidb:%s", initTidbVersion),
StorageClassName: "local-storage",
Password: "admin",
InitSql: initSql,
InitSQL: initSQL,
UserName: "root",
InitSecretName: fmt.Sprintf("%s-set-secret", name2),
BackupSecretName: fmt.Sprintf("%s-backup-secret", name2),
Expand Down
Loading