diff --git a/.golangci.yml b/.golangci.yml index 14c00dfbe..8e4546291 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,21 @@ issues: + exclude-files: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ + max-issues-per-linter: 0 max-same-issues: 0 linters: enable: - errorlint + - gofumpt + - goimports - gomodguard + - whitespace linters-settings: + goimports: + local-prefixes: github.com/prometheus/test-infra gomodguard: blocked: modules: @@ -19,7 +28,4 @@ output: sort-results: true run: - skip-files: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ timeout: 5m diff --git a/infra/infra.go b/infra/infra.go index 667916c7f..656b0bc7f 100644 --- a/infra/infra.go +++ b/infra/infra.go @@ -91,7 +91,7 @@ func main() { k8sKIND.Command("info", "kind info -v hashStable:COMMIT1 -v hashTesting:COMMIT2"). Action(k.GetDeploymentVars) - //Cluster operations. + // Cluster operations. k8sKINDCluster := k8sKIND.Command("cluster", "manage KIND clusters"). Action(k.KINDDeploymentsParse) k8sKINDCluster.Command("create", "kind cluster create -f File -v PR_NUMBER:$PR_NUMBER -v CLUSTER_NAME:$CLUSTER_NAME"). @@ -157,5 +157,4 @@ func main() { app.Usage(os.Args[1:]) os.Exit(2) } - } diff --git a/pkg/provider/eks/eks.go b/pkg/provider/eks/eks.go index 6af31b5cb..bf95cc249 100644 --- a/pkg/provider/eks/eks.go +++ b/pkg/provider/eks/eks.go @@ -174,7 +174,6 @@ func (c *EKS) K8SDeploymentsParse(*kingpin.ParseContext) error { } for _, deployment := range deploymentResource { - decode := scheme.Codecs.UniversalDeserializer().Decode k8sObjects := make([]runtime.Object, 0) @@ -185,7 +184,6 @@ func (c *EKS) K8SDeploymentsParse(*kingpin.ParseContext) error { } resource, _, err := decode([]byte(text), nil, nil) - if err != nil { return fmt.Errorf("decoding the resource file:%v, section:%v...: %w", deployment.FileName, text[:100], err) } @@ -205,7 +203,6 @@ func (c *EKS) K8SDeploymentsParse(*kingpin.ParseContext) error { func (c *EKS) ClusterCreate(*kingpin.ParseContext) error { req := &eksCluster{} for _, deployment := range c.eksResources { - if err := yamlGo.UnmarshalStrict(deployment.Content, req); err != nil { return fmt.Errorf("Error parsing the cluster deployment file %s: %w", deployment.FileName, err) } @@ -221,7 +218,6 @@ func (c *EKS) ClusterCreate(*kingpin.ParseContext) error { provider.EKSRetryCount, func() (bool, error) { return c.clusterRunning(*req.Cluster.Name) }, ) - if err != nil { return fmt.Errorf("creating cluster err: %w", err) } @@ -239,7 +235,6 @@ func (c *EKS) ClusterCreate(*kingpin.ParseContext) error { provider.EKSRetryCount, func() (bool, error) { return c.nodeGroupCreated(*nodegroupReq.NodegroupName, *req.Cluster.Name) }, ) - if err != nil { return fmt.Errorf("creating nodegroup err: %w", err) } @@ -252,7 +247,6 @@ func (c *EKS) ClusterCreate(*kingpin.ParseContext) error { func (c *EKS) ClusterDelete(*kingpin.ParseContext) error { req := &eksCluster{} for _, deployment := range c.eksResources { - if err := yamlGo.UnmarshalStrict(deployment.Content, req); err != nil { return fmt.Errorf("Error parsing the cluster deployment file %s: %w", deployment.FileName, err) } @@ -288,7 +282,6 @@ func (c *EKS) ClusterDelete(*kingpin.ParseContext) error { provider.GlobalRetryCount, func() (bool, error) { return c.nodeGroupDeleted(*nodegroup, *req.Cluster.Name) }, ) - if err != nil { return fmt.Errorf("deleting nodegroup err: %w", err) } @@ -315,7 +308,6 @@ func (c *EKS) ClusterDelete(*kingpin.ParseContext) error { fmt.Sprintf("deleting cluster:%v", *reqD.Name), provider.GlobalRetryCount, func() (bool, error) { return c.clusterDeleted(*reqD.Name) }) - if err != nil { return fmt.Errorf("removing cluster err: %w", err) } @@ -367,7 +359,6 @@ func (c *EKS) clusterDeleted(name string) (bool, error) { func (c *EKS) NodeGroupCreate(*kingpin.ParseContext) error { req := &eksCluster{} for _, deployment := range c.eksResources { - if err := yamlGo.UnmarshalStrict(deployment.Content, req); err != nil { return fmt.Errorf("Error parsing the cluster deployment file %s: %w", deployment.FileName, err) } @@ -385,7 +376,6 @@ func (c *EKS) NodeGroupCreate(*kingpin.ParseContext) error { provider.GlobalRetryCount, func() (bool, error) { return c.nodeGroupCreated(*nodegroupReq.NodegroupName, *req.Cluster.Name) }, ) - if err != nil { return fmt.Errorf("creating nodegroup err: %w", err) } @@ -418,11 +408,9 @@ func (c *EKS) NodeGroupDelete(*kingpin.ParseContext) error { provider.GlobalRetryCount, func() (bool, error) { return c.nodeGroupDeleted(*nodegroupReq.NodegroupName, *req.Cluster.Name) }, ) - if err != nil { return fmt.Errorf("deleting nodegroup err: %w", err) } - } } return nil @@ -447,7 +435,6 @@ func (c *EKS) nodeGroupCreated(nodegroupName, clusterName string) (bool, error) log.Printf("Nodegroup '%v' for Cluster '%v' status: %v", nodegroupName, clusterName, *nodegroupRes.Nodegroup.Status) return false, nil - } func (c *EKS) nodeGroupDeleted(nodegroupName, clusterName string) (bool, error) { @@ -510,9 +497,7 @@ func (c *EKS) AllNodeGroupsDeleted(*kingpin.ParseContext) error { // EKSK8sToken returns aws iam authenticator token which is used to access eks k8s cluster from outside. func (c *EKS) EKSK8sToken(clusterName, region string) awsToken.Token { - gen, err := awsToken.NewGenerator(true, false) - if err != nil { log.Fatalf("Token abstraction error: %v", err) } @@ -523,7 +508,6 @@ func (c *EKS) EKSK8sToken(clusterName, region string) awsToken.Token { } tok, err := gen.GetWithOptions(opts) - if err != nil { log.Fatalf("Token abstraction error: %v", err) } @@ -533,7 +517,6 @@ func (c *EKS) EKSK8sToken(clusterName, region string) awsToken.Token { // NewK8sProvider sets the k8s provider used for deploying k8s manifests func (c *EKS) NewK8sProvider(*kingpin.ParseContext) error { - clusterName := c.DeploymentVars["CLUSTER_NAME"] region := c.DeploymentVars["ZONE"] diff --git a/pkg/provider/gke/gke.go b/pkg/provider/gke/gke.go index 13137c5aa..1e5857aa6 100644 --- a/pkg/provider/gke/gke.go +++ b/pkg/provider/gke/gke.go @@ -165,7 +165,6 @@ func (c *GKE) K8SDeploymentsParse(*kingpin.ParseContext) error { } for _, deployment := range deploymentResource { - decode := scheme.Codecs.UniversalDeserializer().Decode k8sObjects := make([]runtime.Object, 0) @@ -209,7 +208,6 @@ func (c *GKE) checkDeploymentVarsAndFiles() error { func (c *GKE) ClusterCreate(*kingpin.ParseContext) error { req := &containerpb.CreateClusterRequest{} for _, deployment := range c.gkeResources { - if err := yamlGo.UnmarshalStrict(deployment.Content, req); err != nil { log.Fatalf("Error parsing the cluster deployment file %s:%v", deployment.FileName, err) } @@ -226,7 +224,6 @@ func (c *GKE) ClusterCreate(*kingpin.ParseContext) error { provider.GlobalRetryCount, //nolint:staticcheck // SA1019 - Ignore "Do not use.". func() (bool, error) { return c.clusterRunning(req.Zone, req.ProjectId, req.Cluster.Name) }) - if err != nil { log.Fatalf("creating cluster err:%v", err) } @@ -259,7 +256,6 @@ func (c *GKE) ClusterDelete(*kingpin.ParseContext) error { fmt.Sprintf("deleting cluster:%v", reqD.ClusterId), provider.GlobalRetryCount, func() (bool, error) { return c.clusterDeleted(reqD) }) - if err != nil { log.Fatalf("removing cluster err:%v", err) } @@ -345,7 +341,6 @@ func (c *GKE) NodePoolCreate(*kingpin.ParseContext) error { func() (bool, error) { return c.nodePoolCreated(reqN) }) - if err != nil { log.Fatalf("Couldn't create cluster nodepool '%v', file:%v ,err: %v", node.Name, deployment.FileName, err) } @@ -357,7 +352,6 @@ func (c *GKE) NodePoolCreate(*kingpin.ParseContext) error { //nolint:staticcheck // SA1019 - Ignore "Do not use.". return c.nodePoolRunning(reqN.Zone, reqN.ProjectId, reqN.ClusterId, reqN.NodePool.Name) }) - if err != nil { log.Fatalf("Couldn't create cluster nodepool '%v', file:%v ,err: %v", node.Name, deployment.FileName, err) } @@ -369,7 +363,6 @@ func (c *GKE) NodePoolCreate(*kingpin.ParseContext) error { // nodePoolCreated checks if there is any ongoing NodePool operation on the cluster // when creating a NodePool. func (c *GKE) nodePoolCreated(req *containerpb.CreateNodePoolRequest) (bool, error) { - rep, err := c.clientGKE.CreateNodePool(c.ctx, req) if err != nil { st, ok := status.FromError(err) @@ -395,7 +388,6 @@ func (c *GKE) NodePoolDelete(*kingpin.ParseContext) error { // than use the result to create the DeleteNodePoolRequest reqC := &containerpb.CreateClusterRequest{} for _, deployment := range c.gkeResources { - if err := yamlGo.UnmarshalStrict(deployment.Content, reqC); err != nil { log.Fatalf("Error parsing the cluster deployment file %s:%v", deployment.FileName, err) } @@ -417,7 +409,6 @@ func (c *GKE) NodePoolDelete(*kingpin.ParseContext) error { fmt.Sprintf("deleting nodepool:%v", reqD.NodePoolId), provider.GlobalRetryCount, func() (bool, error) { return c.nodePoolDeleted(reqD) }) - if err != nil { log.Fatalf("Couldn't delete cluster nodepool '%v', file:%v ,err: %v", node.Name, deployment.FileName, err) } @@ -428,7 +419,6 @@ func (c *GKE) NodePoolDelete(*kingpin.ParseContext) error { // nodePoolDeleted checks whether a nodepool has been deleted. func (c *GKE) nodePoolDeleted(req *containerpb.DeleteNodePoolRequest) (bool, error) { - rep, err := c.clientGKE.DeleteNodePool(c.ctx, req) if err != nil { st, ok := status.FromError(err) @@ -460,7 +450,6 @@ func (c *GKE) nodePoolRunning(zone, projectID, clusterID, poolName string) (bool NodePoolId: poolName, } rep, err := c.clientGKE.GetNodePool(c.ctx, req) - if err != nil { // We don't consider none existing cluster node pool a failure. So don't return an error here. if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound { diff --git a/pkg/provider/k8s/k8s.go b/pkg/provider/k8s/k8s.go index 8188ef479..71bdef63b 100644 --- a/pkg/provider/k8s/k8s.go +++ b/pkg/provider/k8s/k8s.go @@ -114,7 +114,6 @@ func (c *K8s) DeploymentsParse(*kingpin.ParseContext) error { } for _, deployment := range deploymentResource { - decode := scheme.Codecs.UniversalDeserializer().Decode k8sObjects := make([]runtime.Object, 0) @@ -1405,7 +1404,6 @@ func (c *K8s) serviceExists(resource runtime.Object) (bool, error) { if len(res.Status.LoadBalancer.Ingress) > 0 { log.Printf("\tService %s Details", req.Name) for _, x := range res.Status.LoadBalancer.Ingress { - ingressHostAddr := "" if len(x.IP) != 0 { ingressHostAddr = x.IP diff --git a/pkg/provider/kind/kind.go b/pkg/provider/kind/kind.go index b8f37b9dd..a0a43998a 100644 --- a/pkg/provider/kind/kind.go +++ b/pkg/provider/kind/kind.go @@ -34,7 +34,6 @@ type Resource = provider.Resource // KIND holds the fields used to generate an API request. type KIND struct { - // The k8s provider used when we work with the manifest files. k8sProvider *k8sProvider.K8s // The kind provider used to instantiate a new provider. @@ -108,7 +107,6 @@ func (c *KIND) K8SDeploymentsParse(*kingpin.ParseContext) error { return err } for _, deployment := range deploymentResource { - decode := scheme.Codecs.UniversalDeserializer().Decode k8sObjects := make([]runtime.Object, 0) diff --git a/tools/amGithubNotifier/main.go b/tools/amGithubNotifier/main.go index 66cabad75..281e43ac7 100644 --- a/tools/amGithubNotifier/main.go +++ b/tools/amGithubNotifier/main.go @@ -127,7 +127,6 @@ func (hl ghWebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func newGhWebhookReceiver(cfg ghWebhookReceiverConfig) (*ghWebhookReceiver, error) { - if cfg.dryRun { return &ghWebhookReceiver{ ghClient: github.NewClient(nil), @@ -175,7 +174,6 @@ func (g ghWebhookReceiver) processAlert(ctx context.Context, alert template.Aler } func (g ghWebhookReceiver) processAlerts(ctx context.Context, msg *webhook.Message) ([]string, error) { - var alertcomments []string // Each alert will have its own comment. diff --git a/tools/amGithubNotifier/main_test.go b/tools/amGithubNotifier/main_test.go index 09a789b91..7a1c83f61 100644 --- a/tools/amGithubNotifier/main_test.go +++ b/tools/amGithubNotifier/main_test.go @@ -95,5 +95,4 @@ func TestFormatIssueCommentBody(t *testing.T) { t.Errorf("Output did not match.\ngot:\n%#v\nwant:\n%#v", c, output[i]) } } - } diff --git a/tools/commentMonitor/client.go b/tools/commentMonitor/client.go index 20038a6bd..407e55815 100644 --- a/tools/commentMonitor/client.go +++ b/tools/commentMonitor/client.go @@ -129,6 +129,7 @@ func (c commentMonitorClient) postLabel() error { func (c commentMonitorClient) generateAndPostSuccessComment() error { return c.generateAndPostComment(c.commentTemplate) } + func (c commentMonitorClient) generateAndPostErrorComment() error { return c.generateAndPostComment(c.helpTemplate) } diff --git a/tools/commentMonitor/main_test.go b/tools/commentMonitor/main_test.go index c459b18aa..f0c17be48 100644 --- a/tools/commentMonitor/main_test.go +++ b/tools/commentMonitor/main_test.go @@ -30,6 +30,7 @@ func TestExtractCommand(t *testing.T) { } } } + func TestCheckCommandPrefix(t *testing.T) { cmClient := commentMonitorClient{ prefixes: []commandPrefix{ diff --git a/tools/fake-webserver/server.go b/tools/fake-webserver/server.go index e11f8936b..d5b42d250 100644 --- a/tools/fake-webserver/server.go +++ b/tools/fake-webserver/server.go @@ -88,49 +88,49 @@ type responseOpts struct { } var opts = map[string]map[string]responseOpts{ - "/api/foo": map[string]responseOpts{ - "GET": responseOpts{ + "/api/foo": { + "GET": { baseLatency: 10 * time.Millisecond, errorRatio: 0.005, outageDuration: 23 * time.Second, }, - "POST": responseOpts{ + "POST": { baseLatency: 20 * time.Millisecond, errorRatio: 0.02, outageDuration: time.Minute, }, }, - "/api/bar": map[string]responseOpts{ - "GET": responseOpts{ + "/api/bar": { + "GET": { baseLatency: 15 * time.Millisecond, errorRatio: 0.0025, outageDuration: 13 * time.Second, }, - "POST": responseOpts{ + "POST": { baseLatency: 50 * time.Millisecond, errorRatio: 0.01, outageDuration: 47 * time.Second, }, }, - "/api/baz": map[string]responseOpts{ - "GET": responseOpts{ + "/api/baz": { + "GET": { baseLatency: 2 * time.Millisecond, errorRatio: 0.01, outageDuration: 1 * time.Second, }, - "POST": responseOpts{ + "POST": { baseLatency: 4 * time.Millisecond, errorRatio: 0.02, outageDuration: 2 * time.Second, }, }, - "/api/boom": map[string]responseOpts{ - "GET": responseOpts{ + "/api/boom": { + "GET": { baseLatency: 5 * time.Millisecond, errorRatio: 0.01, outageDuration: 1 * time.Second, }, - "POST": responseOpts{ + "POST": { baseLatency: 14 * time.Millisecond, errorRatio: 0.02, outageDuration: 2 * time.Second, diff --git a/tools/scaler/scaler.go b/tools/scaler/scaler.go index 49d88d245..52f393d2a 100644 --- a/tools/scaler/scaler.go +++ b/tools/scaler/scaler.go @@ -90,7 +90,6 @@ func (s *scale) scale(*kingpin.ParseContext) error { } func main() { - app := kingpin.New(filepath.Base(os.Args[0]), "The Prombench-Scaler tool") app.HelpFlag.Short('h')