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

ci: add golang lint and fixed. #157 #320

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "golangci-lint"
yorugac marked this conversation as resolved.
Show resolved Hide resolved
on:
- push
- pull_request

jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
cache: false
- name: lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
yorugac marked this conversation as resolved.
Show resolved Hide resolved
args: --timeout=30m
5 changes: 1 addition & 4 deletions controllers/k6_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ func (r *K6Reconciler) SetupWithManager(mgr ctrl.Manager) error {
func(object client.Object) bool {
pod := object.(*v1.Pod)
_, ok := pod.GetLabels()[k6CrLabelName]
if !ok {
return false
}
return true
return ok
}))).
WithOptions(controller.Options{
MaxConcurrentReconciles: 1,
Expand Down
2 changes: 1 addition & 1 deletion controllers/k6_initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func SetupCloudTest(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
// If CloudTestRunCreated has just been updated, wait for a bit before
// acting, to avoid race condition between different reconcile loops.
t, _ := v1alpha1.LastUpdate(k6, v1alpha1.CloudTestRunCreated)
if time.Now().Sub(t) < 5*time.Second {
if time.Since(t) < 5*time.Second {
return ctrl.Result{RequeueAfter: time.Second * 2}, nil
}

Expand Down
6 changes: 2 additions & 4 deletions controllers/k6_stopped_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -32,7 +32,7 @@ func isJobRunning(log logr.Logger, service *v1.Service) bool {

defer resp.Body.Close()

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Error(err, fmt.Sprintf("Error on reading status of the runner job %v", service.ObjectMeta.Name))
return true
Expand Down Expand Up @@ -63,7 +63,6 @@ func StoppedJobs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI, r *

opts := &client.ListOptions{LabelSelector: selector, Namespace: k6.NamespacedName().Namespace}

var hostnames []string
sl := &v1.ServiceList{}

if err := r.List(ctx, sl, opts); err != nil {
Expand All @@ -73,7 +72,6 @@ func StoppedJobs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI, r *

var count int32
for _, service := range sl.Items {
hostnames = append(hostnames, service.Spec.ClusterIP)

if isJobRunning(log, &service) {
count++
Expand Down
9 changes: 3 additions & 6 deletions controllers/testrun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
// If TestRunRunning has just been updated, wait for a bit before
// acting, to avoid race condition between different reconcile loops.
t, _ := v1alpha1.LastUpdate(k6, v1alpha1.TestRunRunning)
if time.Now().Sub(t) < 5*time.Second {
if time.Since(t) < 5*time.Second {
return ctrl.Result{RequeueAfter: time.Second * 2}, nil
}

Expand Down Expand Up @@ -268,7 +268,7 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
// delete if configured
if k6.GetSpec().Cleanup == "post" {
log.Info("Cleaning up all resources")
r.Delete(ctx, k6)
r.Delete(ctx, k6) //nolint:errcheck
yorugac marked this conversation as resolved.
Show resolved Hide resolved
}
// notify if configured
return ctrl.Result{}, nil
Expand Down Expand Up @@ -302,10 +302,7 @@ func (r *TestRunReconciler) SetupWithManager(mgr ctrl.Manager) error {
func(object client.Object) bool {
pod := object.(*v1.Pod)
_, ok := pod.GetLabels()[k6CrLabelName]
if !ok {
return false
}
return true
return ok
}))).
WithOptions(controller.Options{
MaxConcurrentReconciles: 1,
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func main() {
os.Exit(1)
}

mgr.AddHealthzCheck("health", healthz.Ping)
mgr.AddReadyzCheck("ready", healthz.Ping)
mgr.AddHealthzCheck("health", healthz.Ping) //nolint:errcheck
mgr.AddReadyzCheck("ready", healthz.Ping) //nolint:errcheck

if err = (controllers.NewK6Reconciler(&controllers.TestRunReconciler{
Client: mgr.GetClient(),
Expand Down
4 changes: 1 addition & 3 deletions pkg/resources/jobs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ func newIstioCommand(istioEnabled string, inheritedCommands []string) ([]string,
command = append(command, "scuttle")
}

for _, inheritedCommand := range inheritedCommands {
command = append(command, inheritedCommand)
}
command = append(command, inheritedCommands...)

return command, istio
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewRunnerJob(k6 v1alpha1.TestRunI, index int, token string) (*batchv1.Job,

command = append(
command,
fmt.Sprintf(script.FullName()),
script.FullName(),
"--address=0.0.0.0:6565")

paused := true
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func SetIfNewer(cond *[]metav1.Condition,
}

if callbackF != nil {
if callbackResult := callbackF(proposedCondition); callbackResult == true {
if callbackResult := callbackF(proposedCondition); callbackResult {
isNewer = callbackResult
}
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/types/k6cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ type CLI struct {

func ParseCLI(arguments string) *CLI {
lastArgV := func(start int, args []string) (end int) {
var nextArg bool
end = start
for !nextArg && end < len(args) {
for end < len(args) {
yorugac marked this conversation as resolved.
Show resolved Hide resolved
args[end] = strings.TrimSpace(args[end])
if len(args[end]) > 0 && args[end][0] == '-' {
nextArg = true
break
}
end++
Expand Down
Loading