From 4a400398680c6ad552772328deab84e1180fa140 Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Sun, 18 Feb 2024 01:17:26 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20Bump=20golangci-lint=20from=20v1.45.2?= =?UTF-8?q?=20=E2=86=92=20v1.55.2=20(#133)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 5 +++- .golangci.yml | 19 +++++++++----- Makefile | 25 +++++++++++-------- pkg/cli/cmd/cmd_disable.go | 1 - pkg/cli/cmd/cmd_enable.go | 1 - pkg/cli/cmd/cmd_kill.go | 1 - .../controllers/croncontroller/cron_worker.go | 17 ------------- .../controllers/croncontroller/util.go | 7 ------ .../controllers/jobqueuecontroller/control.go | 1 - .../podtaskexecutor/pod_client_test.go | 4 +-- pkg/execution/util/job/condition.go | 1 + pkg/execution/util/job/task_test.go | 5 ++-- pkg/runtime/httphandler/listener.go | 5 ++-- pkg/runtime/httphandler/server.go | 6 +++-- pkg/runtime/testing/reconciler.go | 3 +-- 15 files changed, 44 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6ff87ac..b8bff04 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,10 +27,13 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ needs.get-go-version.outputs.go-version }} + - id: get-golangci-lint-version + name: Get golangci-lint version + run: echo "GOLANGCI_LINT_VERSION=$(grep '^GOLANGCI_LINT_VERSION' Makefile | cut -d' ' -f3)" >> "$GITHUB_OUTPUT" - name: Run golangci-lint uses: golangci/golangci-lint-action@v2.5.2 with: - version: v1.45.2 + version: ${{ steps.get-golangci-lint-version.outputs.GOLANGCI_LINT_VERSION }} args: --timeout=5m generate-lint: diff --git a/.golangci.yml b/.golangci.yml index 95cfa19..bd5b7a5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,18 +10,28 @@ linters-settings: issues: exclude-rules: + # Add default exclusions for test files. - path: '(.+)_test\.go' linters: + - dupl - gocognit - gocyclo - - dupl + + # Excludes nil error return unparam checks. + - text: "result .* is always nil" + linters: + - unparam + + # Excludes "always receives" unparam checks for test files. + - path: '(.+)_test\.go' + text: "`.*` always receives `.*`" + linters: + - unparam linters: enable: - asciicheck - bodyclose - - deadcode - - depguard - dupl - errcheck - exportloopref @@ -42,15 +52,12 @@ linters: - nakedret - noctx - prealloc - - revive - rowserrcheck - sqlclosecheck - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - unused - - varcheck - whitespace diff --git a/Makefile b/Makefile index 718b127..b2ea0fd 100644 --- a/Makefile +++ b/Makefile @@ -217,6 +217,15 @@ LOCALBIN ?= $(shell pwd)/bin $(LOCALBIN): ## Ensure that the directory exists mkdir -p $(LOCALBIN) +## Tool Versions +KUSTOMIZE_VERSION ?= v4.5.5 +CONTROLLER_TOOLS_VERSION ?= v0.8.0 +YQ_VERSION ?= v4.14.1 +GOIMPORTS_REVISER_VERSION ?= 32c80678d5d73a50b6966f06b346de58b1d018f1 +GOLANGCI_LINT_VERSION ?= v1.55.2 +LICENSEHEADERCHECKER_VERSION ?= v1.3.0 +GORELEASER_VERSION ?= v1.8.2 + ## Tool Binaries KUSTOMIZE ?= $(LOCALBIN)/kustomize CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen @@ -224,19 +233,10 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest GOIMPORTS ?= $(LOCALBIN)/goimports GOIMPORTS_REVISER ?= $(LOCALBIN)/goimports-reviser YQ ?= $(LOCALBIN)/yq -GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint@$(GOLANGCI_LINT_VERSION) LICENSE_HEADER_CHECKER ?= $(LOCALBIN)/license-header-checker GORELEASER ?= $(LOCALBIN)/goreleaser -## Tool Versions -KUSTOMIZE_VERSION ?= v4.5.5 -CONTROLLER_TOOLS_VERSION ?= v0.8.0 -YQ_VERSION ?= v4.14.1 -GOIMPORTS_REVISER_VERSION ?= 32c80678d5d73a50b6966f06b346de58b1d018f1 -GOLANGCILINT_VERSION ?= v1.45.2 -LICENSEHEADERCHECKER_VERSION ?= v1.3.0 -GORELEASER_VERSION ?= v1.8.2 - .PHONY: controller-gen controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. $(CONTROLLER_GEN): @@ -272,7 +272,10 @@ GOLANGCILINT_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/golangci/golan .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): - @[ -f $(GOLANGCI_LINT) ] || curl -sSfL $(GOLANGCILINT_INSTALL_SCRIPT) | sh -s $(GOLANGCILINT_VERSION) + # Downloads to ./bin/golangci-lint. + @[ -f $(GOLANGCI_LINT) ] || curl -sSfL $(GOLANGCILINT_INSTALL_SCRIPT) | sh -s $(GOLANGCI_LINT_VERSION) + # Move to versioned path. + mv ./bin/golangci-lint $(GOLANGCI_LINT) .PHONY: goreleaser goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary. diff --git a/pkg/cli/cmd/cmd_disable.go b/pkg/cli/cmd/cmd_disable.go index 548d6fa..be008c5 100644 --- a/pkg/cli/cmd/cmd_disable.go +++ b/pkg/cli/cmd/cmd_disable.go @@ -38,7 +38,6 @@ var ( type DisableCommand struct { streams *streams.Streams - name string } func NewDisableCommand(streams *streams.Streams) *cobra.Command { diff --git a/pkg/cli/cmd/cmd_enable.go b/pkg/cli/cmd/cmd_enable.go index dc0ad6f..e0005ed 100644 --- a/pkg/cli/cmd/cmd_enable.go +++ b/pkg/cli/cmd/cmd_enable.go @@ -38,7 +38,6 @@ var ( type EnableCommand struct { streams *streams.Streams - name string } func NewEnableCommand(streams *streams.Streams) *cobra.Command { diff --git a/pkg/cli/cmd/cmd_kill.go b/pkg/cli/cmd/cmd_kill.go index dabafe2..6e9dc25 100644 --- a/pkg/cli/cmd/cmd_kill.go +++ b/pkg/cli/cmd/cmd_kill.go @@ -48,7 +48,6 @@ var ( type KillCommand struct { streams *streams.Streams - name string override bool killAt time.Time } diff --git a/pkg/execution/controllers/croncontroller/cron_worker.go b/pkg/execution/controllers/croncontroller/cron_worker.go index 046a274..0377501 100644 --- a/pkg/execution/controllers/croncontroller/cron_worker.go +++ b/pkg/execution/controllers/croncontroller/cron_worker.go @@ -30,7 +30,6 @@ import ( "k8s.io/utils/clock" utiltrace "k8s.io/utils/trace" - configv1alpha1 "github.com/furiko-io/furiko/apis/config/v1alpha1" execution "github.com/furiko-io/furiko/apis/execution/v1alpha1" "github.com/furiko-io/furiko/pkg/config" "github.com/furiko-io/furiko/pkg/execution/util/cronschedule" @@ -266,22 +265,6 @@ func (w *CronWorker) syncOne(now time.Time, key string, ts time.Time, counts map return nil } -// getTimezone returns the timezone for the given JobConfig. -func (w *CronWorker) getTimezone(cronSchedule *execution.CronSchedule, cfg *configv1alpha1.CronExecutionConfig) string { - // Read from spec. - if cronSchedule.Timezone != "" { - return cronSchedule.Timezone - } - - // Use default timezone from config. - if tz := cfg.DefaultTimezone; tz != nil && len(*tz) > 0 { - return *tz - } - - // Fallback to controller default. - return defaultTimezone -} - type enqueueHandler struct { *Context } diff --git a/pkg/execution/controllers/croncontroller/util.go b/pkg/execution/controllers/croncontroller/util.go index 7bbf2b3..f3767b9 100644 --- a/pkg/execution/controllers/croncontroller/util.go +++ b/pkg/execution/controllers/croncontroller/util.go @@ -28,13 +28,6 @@ import ( "github.com/furiko-io/furiko/pkg/utils/cmp" ) -const ( - // defaultTimezone is the default timezone value that will be used if there is - // no timezone configuration for the JobConfig or a default value set for the - // controller. - defaultTimezone = "UTC" -) - // IsScheduleEqual returns true if the ScheduleSpec is not equal and should be updated. // This equality check is only true in the context of the CronController. func IsScheduleEqual(orig, updated *execution.ScheduleSpec) (bool, error) { diff --git a/pkg/execution/controllers/jobqueuecontroller/control.go b/pkg/execution/controllers/jobqueuecontroller/control.go index 5791b0d..fb39874 100644 --- a/pkg/execution/controllers/jobqueuecontroller/control.go +++ b/pkg/execution/controllers/jobqueuecontroller/control.go @@ -42,7 +42,6 @@ type JobControlInterface interface { type JobControl struct { client executionv1alpha1.ExecutionV1alpha1Interface recorder record.EventRecorder - name string } var _ JobControlInterface = (*JobControl)(nil) diff --git a/pkg/execution/taskexecutor/podtaskexecutor/pod_client_test.go b/pkg/execution/taskexecutor/podtaskexecutor/pod_client_test.go index 0dfe239..0604f87 100644 --- a/pkg/execution/taskexecutor/podtaskexecutor/pod_client_test.go +++ b/pkg/execution/taskexecutor/podtaskexecutor/pod_client_test.go @@ -99,11 +99,11 @@ func TestNewPodTaskClient(t *testing.T) { } func getPodIndexedName(name string, index int64) string { - name, err := jobutil.GenerateTaskName(fakeJob.Name, tasks.TaskIndex{ + taskName, err := jobutil.GenerateTaskName(name, tasks.TaskIndex{ Retry: index, }) if err != nil { panic(err) } - return name + return taskName } diff --git a/pkg/execution/util/job/condition.go b/pkg/execution/util/job/condition.go index 69a7f4a..8d08f31 100644 --- a/pkg/execution/util/job/condition.go +++ b/pkg/execution/util/job/condition.go @@ -90,6 +90,7 @@ func GetCondition(rj *execution.Job) (execution.JobCondition, error) { // Compute latest timestamps across all tasks. var latestCreated, latestRunning, latestFinished *metav1.Time for _, task := range rj.Status.Tasks { + task := task latestCreated = ktime.TimeMax(latestCreated, &task.CreationTimestamp) latestRunning = ktime.TimeMax(latestRunning, task.RunningTimestamp) latestFinished = ktime.TimeMax(latestFinished, task.FinishTimestamp) diff --git a/pkg/execution/util/job/task_test.go b/pkg/execution/util/job/task_test.go index fe46b2f..2535e90 100644 --- a/pkg/execution/util/job/task_test.go +++ b/pkg/execution/util/job/task_test.go @@ -45,9 +45,8 @@ var ( type stubTask struct { metav1.ObjectMeta - taskRef v1alpha1.TaskRef - retryIndex int64 - killable bool + taskRef v1alpha1.TaskRef + killable bool } func (t *stubTask) GetName() string { diff --git a/pkg/runtime/httphandler/listener.go b/pkg/runtime/httphandler/listener.go index b90ef25..190a329 100644 --- a/pkg/runtime/httphandler/listener.go +++ b/pkg/runtime/httphandler/listener.go @@ -88,8 +88,9 @@ func ListenAndServeWebhooks( mux := http.NewServeMux() server := newTLSServer(&http.Server{ - Addr: addr, - Handler: mux, + Addr: addr, + Handler: mux, + ReadHeaderTimeout: 10 * time.Second, }, config.TLSCertFile, config.TLSPrivateKeyFile) ServeWebhooks(mux, webhooks) diff --git a/pkg/runtime/httphandler/server.go b/pkg/runtime/httphandler/server.go index b9cfdc9..b6d8694 100644 --- a/pkg/runtime/httphandler/server.go +++ b/pkg/runtime/httphandler/server.go @@ -19,6 +19,7 @@ package httphandler import ( "context" "net/http" + "time" "github.com/prometheus/client_golang/prometheus" @@ -35,8 +36,9 @@ type Server struct { func NewServer(addr string) *Server { mux := http.NewServeMux() server := &http.Server{ - Addr: addr, - Handler: mux, + Addr: addr, + Handler: mux, + ReadHeaderTimeout: 10 * time.Second, } return &Server{ diff --git a/pkg/runtime/testing/reconciler.go b/pkg/runtime/testing/reconciler.go index 5eb6ac0..f6ccf3e 100644 --- a/pkg/runtime/testing/reconciler.go +++ b/pkg/runtime/testing/reconciler.go @@ -179,7 +179,7 @@ func (r *ReconcilerTest) RunTestCase(t testinginterface.T, tt ReconcilerTestCase recon := r.ReconcilerFunc(ctrlContext) // Initialize fixtures. - target, err := r.initClientset(ctx, c.MockClientsets(), tt, ctrlContext.GetHasSynced()) + target, err := r.initClientset(ctx, c.MockClientsets(), tt) if err != nil { t.Fatalf("cannot initialize fixtures: %v", err) } @@ -230,7 +230,6 @@ func (r *ReconcilerTest) initClientset( ctx context.Context, client *mock.Clientsets, tt ReconcilerTestCase, - hasSynced []cache.InformerSynced, ) (runtime.Object, error) { // Set up all fixtures. fixtures := tt.Fixtures