From 351847e68c37307d1fa30bb1861422d275d41a2f Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Fri, 10 May 2019 13:58:19 +0800 Subject: [PATCH] fix `make lint` - fix `make lint` - rule.var-naming to warning, change it to error in future --- Makefile | 3 +- pkg/discovery/server/mux.go | 14 +++---- pkg/tkctl/config/config.go | 16 ++++---- pkg/tkctl/executor/executor.go | 8 ++-- pkg/tkctl/readable/print_flags.go | 22 +++++----- pkg/tkctl/readable/printers.go | 14 +++---- revive.toml | 3 +- tests/actions.go | 49 +++++++++++------------ tests/cmd/e2e/main.go | 6 +-- tests/cmd/stability/main.go | 6 +-- tests/config.go | 8 +--- tests/failover.go | 8 ++-- tests/pkg/metrics/annotation_util.go | 8 ++-- tests/pkg/metrics/annotation_util_test.go | 7 ++-- tests/pkg/ops/common.go | 1 + tests/pkg/ops/exec.go | 1 + tests/pkg/ops/tikv.go | 1 + tests/pkg/util/misc.go | 1 + tests/pkg/webhook/pods.go | 9 ++--- tests/pkg/webhook/route.go | 2 +- tests/slack/slack.go | 24 +++++------ tests/util.go | 2 +- 22 files changed, 102 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index ff399bb8db..a985090f31 100644 --- a/Makefile +++ b/Makefile @@ -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 } }' @@ -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" diff --git a/pkg/discovery/server/mux.go b/pkg/discovery/server/mux.go index 3d701ec9d9..ecb6c7aa64 100644 --- a/pkg/discovery/server/mux.go +++ b/pkg/discovery/server/mux.go @@ -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) } diff --git a/pkg/tkctl/config/config.go b/pkg/tkctl/config/config.go index a6a5ff2879..acc26245db 100644 --- a/pkg/tkctl/config/config.go +++ b/pkg/tkctl/config/config.go @@ -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" restclient "k8s.io/client-go/rest" ) @@ -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 { diff --git a/pkg/tkctl/executor/executor.go b/pkg/tkctl/executor/executor.go index 11805dc4ff..e43c65f1b1 100644 --- a/pkg/tkctl/executor/executor.go +++ b/pkg/tkctl/executor/executor.go @@ -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" @@ -30,7 +32,6 @@ import ( "k8s.io/kubernetes/pkg/kubectl" "k8s.io/kubernetes/pkg/kubectl/cmd" "k8s.io/kubernetes/pkg/util/interrupt" - "time" ) const ( @@ -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 { diff --git a/pkg/tkctl/readable/print_flags.go b/pkg/tkctl/readable/print_flags.go index ff1808418f..f18890983f 100644 --- a/pkg/tkctl/readable/print_flags.go +++ b/pkg/tkctl/readable/print_flags.go @@ -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 { @@ -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 } diff --git a/pkg/tkctl/readable/printers.go b/pkg/tkctl/readable/printers.go index 3392f833fd..dc4d1b34e2 100644 --- a/pkg/tkctl/readable/printers.go +++ b/pkg/tkctl/readable/printers.go @@ -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) { @@ -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 } @@ -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, } } diff --git a/revive.toml b/revive.toml index 84cf77d5df..dc3d225c24 100644 --- a/revive.toml +++ b/revive.toml @@ -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] @@ -21,6 +20,8 @@ warningCode = 0 [rule.modifies-parameter] # Add these once issues are fixed +[rule.var-naming] + severity = "warning" [rule.confusing-naming] severity = "warning" [rule.confusing-results] diff --git a/tests/actions.go b/tests/actions.go index 4b97612efe..2a90516dde 100644 --- a/tests/actions.go +++ b/tests/actions.go @@ -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" @@ -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 @@ -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), } @@ -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)) @@ -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 } @@ -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 } @@ -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) } @@ -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) @@ -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 { @@ -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 { @@ -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 { @@ -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) diff --git a/tests/cmd/e2e/main.go b/tests/cmd/e2e/main.go index 464462b42f..d3221e2f4b 100644 --- a/tests/cmd/e2e/main.go +++ b/tests/cmd/e2e/main.go @@ -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" @@ -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), @@ -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), diff --git a/tests/cmd/stability/main.go b/tests/cmd/stability/main.go index 1f544bc593..f583489e2c 100644 --- a/tests/cmd/stability/main.go +++ b/tests/cmd/stability/main.go @@ -59,7 +59,7 @@ func main() { // TODO remove this // 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))"` // two clusters in different namespaces clusterName1 := "stability-cluster1" @@ -73,7 +73,7 @@ func main() { TiDBImage: fmt.Sprintf("pingcap/tidb:%s", tidbVersion), StorageClassName: "local-storage", Password: "admin", - InitSql: initSql, + InitSQL: initSQL, UserName: "root", InitSecretName: fmt.Sprintf("%s-set-secret", clusterName1), BackupSecretName: fmt.Sprintf("%s-backup-secret", clusterName1), @@ -110,7 +110,7 @@ func main() { TiDBImage: fmt.Sprintf("pingcap/tidb:%s", tidbVersion), StorageClassName: "local-storage", Password: "admin", - InitSql: initSql, + InitSQL: initSQL, UserName: "root", InitSecretName: fmt.Sprintf("%s-set-secret", clusterName2), BackupSecretName: fmt.Sprintf("%s-backup-secret", clusterName2), diff --git a/tests/config.go b/tests/config.go index 817f1e5ed3..1fed05a369 100644 --- a/tests/config.go +++ b/tests/config.go @@ -78,7 +78,7 @@ func NewConfig() (*Config, error) { flag.StringVar(&cfg.OperatorTag, "operator-tag", "master", "operator tag used to choose charts") flag.StringVar(&cfg.OperatorImage, "operator-image", "pingcap/tidb-operator:latest", "operator image") flag.StringVar(&cfg.OperatorRepoDir, "operator-repo-dir", "/tidb-operator", "local directory to which tidb-operator cloned") - flag.StringVar(&slack.WebhookUrl, "slack-webhook-url", "", "slack webhook url") + flag.StringVar(&slack.WebhookURL, "slack-webhook-url", "", "slack webhook url") flag.Parse() operatorRepo, err := ioutil.TempDir("", "tidb-operator") @@ -131,11 +131,7 @@ func (c *Config) configFromFile(path string) error { return err } - if err = yaml.Unmarshal(data, c); err != nil { - return err - } - - return nil + return yaml.Unmarshal(data, c) } func (c *Config) GetTiDBVersion() (string, error) { diff --git a/tests/failover.go b/tests/failover.go index 2e59734d87..aeb9285d20 100644 --- a/tests/failover.go +++ b/tests/failover.go @@ -9,6 +9,7 @@ import ( "github.com/pingcap/tidb-operator/tests/slack" + // To register MySQL driver _ "github.com/go-sql-driver/mysql" "github.com/golang/glog" "github.com/pingcap/errors" @@ -57,9 +58,8 @@ func (oa *operatorActions) TruncateSSTFileThenCheckFailover(info *TidbClusterCon if len(store.ID) == 0 { glog.Errorf("failed to find an up store") return errors.New("no up store for truncating sst file") - } else { - glog.Infof("truncate sst file target store: id=%s pod=%s", store.ID, store.PodName) } + glog.Infof("truncate sst file target store: id=%s pod=%s", store.ID, store.PodName) oa.EmitEvent(info, fmt.Sprintf("TruncateSSTFile: tikv: %s", store.PodName)) glog.Infof("deleting pod: [%s/%s] and wait 1 minute for the pod to terminate", info.Namespace, store.PodName) @@ -478,7 +478,7 @@ func (oa *operatorActions) CheckOneApiserverDownOrDie(operatorConfig *OperatorCo if schedulerPod != nil { affectedPods[schedulerPod.GetName()] = schedulerPod } - dnsPod, err := GetDnsPod(oa.kubeCli, faultNode) + dnsPod, err := GetDNSPod(oa.kubeCli, faultNode) if err != nil { slack.NotifyAndPanic(fmt.Errorf("can't find controller-manager in node:%s", faultNode)) } @@ -586,7 +586,7 @@ func (oa *operatorActions) CheckTidbClustersAvailable(infos []*TidbClusterConfig var testTableName = "testTable" -func (op *operatorActions) addDataToCluster(info *TidbClusterConfig) (bool, error) { +func (oa *operatorActions) addDataToCluster(info *TidbClusterConfig) (bool, error) { db, err := sql.Open("mysql", getDSN(info.Namespace, info.ClusterName, "test", info.Password)) if err != nil { glog.Errorf("cluster:[%s] can't open connection to mysql: %v", info.FullName(), err) diff --git a/tests/pkg/metrics/annotation_util.go b/tests/pkg/metrics/annotation_util.go index 9d6023e806..85d4acf243 100644 --- a/tests/pkg/metrics/annotation_util.go +++ b/tests/pkg/metrics/annotation_util.go @@ -48,16 +48,16 @@ type Annotation struct { //AnnotationOptions is the query options to a standard REST list call. type AnnotationOptions struct { - DashboardId int `json:"dashboardId,omitempty"` - PanelId int `json:"panelId,omitempty"` + DashboardID int `json:"dashboardId,omitempty"` + PanelID int `json:"panelId,omitempty"` IsRegin bool `json:"isRegion,omitempty"` TimeEnd int64 `json:"timeEnd,omitempty"` } //NewClient creats a new grafanaClient. This client performs rest functions //such as Get, Post on specified paths. -func NewClient(grafanaUrl string, userName string, password string, prometheusExporterPort int) (*Client, error) { - u, err := url.Parse(grafanaUrl) +func NewClient(grafanaURL string, userName string, password string, prometheusExporterPort int) (*Client, error) { + u, err := url.Parse(grafanaURL) if err != nil { return nil, err } diff --git a/tests/pkg/metrics/annotation_util_test.go b/tests/pkg/metrics/annotation_util_test.go index fa5bbce402..7e3b160ced 100644 --- a/tests/pkg/metrics/annotation_util_test.go +++ b/tests/pkg/metrics/annotation_util_test.go @@ -15,16 +15,17 @@ package metrics import ( "encoding/json" "fmt" - "github.com/onsi/gomega" "testing" + + "github.com/onsi/gomega" ) func TestAnnotationGetBody(t *testing.T) { tags := []string{"1", "2", "3"} options := AnnotationOptions{ - DashboardId: 1, - PanelId: 2, + DashboardID: 1, + PanelID: 2, } annotation := Annotation{ diff --git a/tests/pkg/ops/common.go b/tests/pkg/ops/common.go index 69239a8113..e68a111a80 100644 --- a/tests/pkg/ops/common.go +++ b/tests/pkg/ops/common.go @@ -10,6 +10,7 @@ // distributed under the License is distributed on an "AS IS" BASIS, // See the License for the specific language governing permissions and // limitations under the License. + package ops import ( diff --git a/tests/pkg/ops/exec.go b/tests/pkg/ops/exec.go index e97767a941..fff35b6357 100644 --- a/tests/pkg/ops/exec.go +++ b/tests/pkg/ops/exec.go @@ -10,6 +10,7 @@ // distributed under the License is distributed on an "AS IS" BASIS, // See the License for the specific language governing permissions and // limitations under the License. + package ops import ( diff --git a/tests/pkg/ops/tikv.go b/tests/pkg/ops/tikv.go index 0e06e264cd..ddf1da4903 100644 --- a/tests/pkg/ops/tikv.go +++ b/tests/pkg/ops/tikv.go @@ -10,6 +10,7 @@ // distributed under the License is distributed on an "AS IS" BASIS, // See the License for the specific language governing permissions and // limitations under the License. + package ops import ( diff --git a/tests/pkg/util/misc.go b/tests/pkg/util/misc.go index 0540924bb7..6c1d9111e8 100644 --- a/tests/pkg/util/misc.go +++ b/tests/pkg/util/misc.go @@ -10,6 +10,7 @@ // distributed under the License is distributed on an "AS IS" BASIS, // See the License for the specific language governing permissions and // limitations under the License. + package util import ( diff --git a/tests/pkg/webhook/pods.go b/tests/pkg/webhook/pods.go index b604d881db..4d592a1a2b 100644 --- a/tests/pkg/webhook/pods.go +++ b/tests/pkg/webhook/pods.go @@ -127,9 +127,8 @@ func admitPods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse { } // TODO use context instead os.Exit(3) - } else { - glog.Infof("savely delete pod namespace %s name %s isowner %t", namespace, name, info.IsOwner) } + glog.Infof("savely delete pod namespace %s name %s isowner %t", namespace, name, info.IsOwner) } else if pod.Labels[label.ComponentLabelKey] == "pd" { @@ -149,9 +148,8 @@ func admitPods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse { } // TODO use context instead os.Exit(3) - } else { - glog.Infof("savely delete pod namespace %s name %s leader name %s", namespace, name, leader.Name) } + glog.Infof("savely delete pod namespace %s name %s leader name %s", namespace, name, leader.Name) } else if pod.Labels[label.ComponentLabelKey] == "tikv" { @@ -194,9 +192,8 @@ func admitPods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse { } // TODO use context instead os.Exit(3) - } else { - glog.Infof("savely delete pod namespace %s name %s before count %d after count %d", namespace, name, beforeCount, afterCount) } + glog.Infof("savely delete pod namespace %s name %s before count %d after count %d", namespace, name, beforeCount, afterCount) } reviewResponse.Allowed = true return &reviewResponse diff --git a/tests/pkg/webhook/route.go b/tests/pkg/webhook/route.go index e6536c2380..dd7a7baf8b 100644 --- a/tests/pkg/webhook/route.go +++ b/tests/pkg/webhook/route.go @@ -42,7 +42,7 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) { goto returnData } } else { - err := errors.New("request body is nil!") + err := errors.New("request body is nil") responseAdmissionReview.Response = toAdmissionResponse(err) goto returnData } diff --git a/tests/slack/slack.go b/tests/slack/slack.go index 14a34dd62c..def46d5c14 100644 --- a/tests/slack/slack.go +++ b/tests/slack/slack.go @@ -12,7 +12,7 @@ import ( var ( Channel string - WebhookUrl string + WebhookURL string ) type Field struct { @@ -31,7 +31,7 @@ type Attachment struct { Title string `json:"title"` TitleLink string `json:"title_link"` Text string `json:"text"` - ImageUrl string `json:"image_url"` + ImageURL string `json:"image_url"` Fields []*Field `json:"fields"` Footer string `json:"footer"` FooterIcon string `json:"footer_icon"` @@ -42,7 +42,7 @@ type Attachment struct { type Payload struct { Parse string `json:"parse,omitempty"` Username string `json:"username,omitempty"` - IconUrl string `json:"icon_url,omitempty"` + IconURL string `json:"icon_url,omitempty"` IconEmoji string `json:"icon_emoji,omitempty"` Channel string `json:"channel,omitempty"` Text string `json:"text,omitempty"` @@ -57,15 +57,15 @@ func (attachment *Attachment) AddField(field Field) *Attachment { return attachment } -func Send(webhookUrl string, proxy string, payload Payload) error { - if webhookUrl == "" { - return fmt.Errorf("the webhookUrl have not set") +func Send(webhookURL string, proxy string, payload Payload) error { + if webhookURL == "" { + return fmt.Errorf("the webhookURL have not set") } body, err := json.Marshal(payload) if err != nil { return err } - req, err := http.NewRequest("POST", webhookUrl, bytes.NewBuffer(body)) + req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(body)) if err != nil { return err } @@ -99,7 +99,7 @@ func SendErrMsg(msg string) error { IconEmoji: ":ghost:", Attachments: []Attachment{attachment}, } - err := Send(WebhookUrl, "", payload) + err := Send(WebhookURL, "", payload) if err != nil { return err } @@ -118,7 +118,7 @@ func SendGoodMsg(msg string) error { IconEmoji: ":sun_with_face:", Attachments: []Attachment{attachment}, } - err := Send(WebhookUrl, "", payload) + err := Send(WebhookURL, "", payload) if err != nil { return err } @@ -138,7 +138,7 @@ func SendWarnMsg(msg string) error { IconEmoji: ":imp:", Attachments: []Attachment{attachment}, } - err := Send(WebhookUrl, "", payload) + err := Send(WebhookURL, "", payload) if err != nil { return err } @@ -148,7 +148,7 @@ func SendWarnMsg(msg string) error { func NotifyAndPanic(err error) { sendErr := SendErrMsg(err.Error()) if sendErr != nil { - glog.Warningf("failed to notify slack[%s] the massage: %v,error: %v", WebhookUrl, err, sendErr) + glog.Warningf("failed to notify slack[%s] the massage: %v,error: %v", WebhookURL, err, sendErr) } time.Sleep(3 * time.Second) panic(err) @@ -157,7 +157,7 @@ func NotifyAndPanic(err error) { func NotifyAndCompleted(msg string) { sendErr := SendGoodMsg(msg) if sendErr != nil { - glog.Warningf("failed to notify slack[%s] the massage: %s,error: %v", WebhookUrl, msg, sendErr) + glog.Warningf("failed to notify slack[%s] the massage: %s,error: %v", WebhookURL, msg, sendErr) } glog.Infof(msg) } diff --git a/tests/util.go b/tests/util.go index 274045f8b0..34ccab0081 100644 --- a/tests/util.go +++ b/tests/util.go @@ -56,7 +56,7 @@ func GetSchedulerPod(kubeCli kubernetes.Interface, node string) (*corev1.Pod, er return GetKubeComponent(kubeCli, node, "kube-scheduler") } -func GetDnsPod(kubeCli kubernetes.Interface, node string) (*corev1.Pod, error) { +func GetDNSPod(kubeCli kubernetes.Interface, node string) (*corev1.Pod, error) { return GetKubeComponent(kubeCli, node, "kube-dns") }