Skip to content

Commit

Permalink
enable gofumpt, goimports, misspell 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 13ae90c
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 56 deletions.
13 changes: 10 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
issues:
exclude-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- errorlint
- gofumpt
- goimports
- gomodguard
- misspell
- whitespace

linters-settings:
goimports:
local-prefixes: github.com/prometheus/test-infra
gomodguard:
blocked:
modules:
Expand All @@ -19,7 +29,4 @@ output:
sort-results: true

run:
skip-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
timeout: 5m
7 changes: 3 additions & 4 deletions infra/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
g := gke.New(dr)
k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`).
Action(g.SetupDeploymentResources)
k8sGKE.Flag("auth", "json authentication for the project. Accepts a filepath or an env variable that inlcudes tha json data. If not set the tool will use the GOOGLE_APPLICATION_CREDENTIALS env variable (export GOOGLE_APPLICATION_CREDENTIALS=service-account.json). https://cloud.google.com/iam/docs/creating-managing-service-account-keys.").
k8sGKE.Flag("auth", "json authentication for the project. Accepts a filepath or an env variable that includes tha json data. If not set the tool will use the GOOGLE_APPLICATION_CREDENTIALS env variable (export GOOGLE_APPLICATION_CREDENTIALS=service-account.json). https://cloud.google.com/iam/docs/creating-managing-service-account-keys.").
PlaceHolder("service-account.json").
Short('a').
StringVar(&g.Auth)
Expand Down 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 @@ -137,7 +137,7 @@ func main() {
Action(e.NodeGroupCreate)
k8sEKSNodeGroup.Command("delete", "eks nodes delete -a authFile -f FileOrFolder -v ZONE:eu-west-1 -v CLUSTER_NAME:test -v EKS_SUBNET_IDS: subnetId1,subnetId2,subnetId3").
Action(e.NodeGroupDelete)
k8sEKSNodeGroup.Command("check-running", "eks nodes check-running -a credentails -f FileOrFolder -v ZONE:eu-west-1 -v CLUSTER_NAME:test -v EKS_SUBNET_IDS: subnetId1,subnetId2,subnetId3").
k8sEKSNodeGroup.Command("check-running", "eks nodes check-running -a credentials -f FileOrFolder -v ZONE:eu-west-1 -v CLUSTER_NAME:test -v EKS_SUBNET_IDS: subnetId1,subnetId2,subnetId3").
Action(e.AllNodeGroupsRunning)
k8sEKSNodeGroup.Command("check-deleted", "eks nodes check-deleted -a authFile -f FileOrFolder -v ZONE:eu-west-1 -v CLUSTER_NAME:test -v EKS_SUBNET_IDS: subnetId1,subnetId2,subnetId3").
Action(e.AllNodeGroupsDeleted)
Expand All @@ -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])
}
}

}
3 changes: 2 additions & 1 deletion tools/commentMonitor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *commentMonitorClient) extractArgs(command string) error {
return fmt.Errorf("%w: could not fetch SHA", err)
}

// TODO (geekodour) : We could run this in a seperate method.
// TODO (geekodour) : We could run this in a separate method.
err = c.ghClient.createRepositoryDispatch(c.eventType, c.allArgs)
if err != nil {
return fmt.Errorf("%w: could not create repository_dispatch event", err)
Expand All @@ -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
Loading

0 comments on commit 13ae90c

Please sign in to comment.