Skip to content

Commit

Permalink
enable gofumpt, goimports and whitespace linters
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Oct 14, 2024
1 parent 8b082e4 commit 76bb586
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 53 deletions.
12 changes: 9 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -19,7 +28,4 @@ output:
sort-results: true

run:
skip-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
timeout: 5m
3 changes: 1 addition & 2 deletions infra/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -157,5 +157,4 @@ func main() {
app.Usage(os.Args[1:])
os.Exit(2)
}

}
17 changes: 0 additions & 17 deletions pkg/provider/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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"]

Expand Down
11 changes: 0 additions & 11 deletions pkg/provider/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/provider/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/provider/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions tools/amGithubNotifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion tools/amGithubNotifier/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ func TestFormatIssueCommentBody(t *testing.T) {
t.Errorf("Output did not match.\ngot:\n%#v\nwant:\n%#v", c, output[i])
}
}

}
1 change: 1 addition & 0 deletions tools/commentMonitor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions tools/commentMonitor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestExtractCommand(t *testing.T) {
}
}
}

func TestCheckCommandPrefix(t *testing.T) {
cmClient := commentMonitorClient{
prefixes: []commandPrefix{
Expand Down
24 changes: 12 additions & 12 deletions tools/fake-webserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tools/scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 76bb586

Please sign in to comment.