diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 32d5b780..392b49b3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,6 @@ jobs: runs-on: ubuntu-latest strategy: - fail-fast: false matrix: target: ["verify", "lint", "test"] diff --git a/.golangci.yml b/.golangci.yml index cd29478b..b67fab78 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,6 @@ linters: - asciicheck - bodyclose - cyclop - - deadcode #- depguard - dogsled - dupl @@ -27,17 +26,15 @@ linters: - gocyclo - godot # - godox - - goerr113 + - err113 - gofmt - gofumpt - goheader - goimports - - gomnd - gomodguard - goprintffuncname - gosec - gosimple - - ifshort - importas - ineffassign # - interfacer @@ -59,7 +56,6 @@ linters: # - scopelint - sqlclosecheck - staticcheck - - structcheck - stylecheck - testpackage - thelper @@ -68,7 +64,6 @@ linters: - unconvert - unparam - unused - - varcheck - wastedassign - whitespace - wrapcheck @@ -90,6 +85,9 @@ issues: - linters: - lll path: "controllers/(.+)_test.go" + exclude-files: + - "zz_generated.*\\.go$" + - ".*conversion.*\\.go$" linters-settings: importas: @@ -110,13 +108,15 @@ linters-settings: - pkg: sigs.k8s.io/controller-runtime alias: ctrl gosimple: - go: "1.21" + checks: ["all"] staticcheck: - go: "1.21" + checks: ["all"] stylecheck: - go: "1.21" + checks: ["all"] unused: - go: "1.21" + # Mark all struct fields that have been written to as used. + # Default: true + field-writes-are-uses: true tagliatelle: case: # use-field-name: true @@ -133,10 +133,26 @@ linters-settings: # Forbid the use of the `exclude` directives. Default is false. exclude-forbidden: false gci: - # put imports beginning with prefix after 3rd-party packages; - # only support one prefix - # if not set, use goimports.local-prefixes - local-prefixes: github.com/tinkerbell/cluster-api-provider-tinkerbell + # Section configuration to compare against. + # Section names are case-insensitive and may contain parameters in (). + # The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`, + # If `custom-order` is `true`, it follows the order of `sections` option. + # Default: ["standard", "default"] + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/tinkerbell/cluster-api-provider-tinkerbell) # Custom section: groups all imports with the specified Prefix. + - blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled. + - dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled. + - alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled. + - localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled. + # Skip generated files. + # Default: true + skip-generated: false + # Enable custom order of sections. + # If `true`, make the section order the same as the order of `sections`. + # Default: false + custom-order: true goimports: # put imports beginning with prefix after 3rd-party packages; # it's a comma-separated list of prefixes @@ -157,9 +173,4 @@ linters-settings: run: timeout: 10m - skip-files: - - "zz_generated.*\\.go$" - - ".*conversion.*\\.go$" - allow-parallel-runners: true - skip-dirs: - - tink/ # TODO: remove this line after #160 is merged. The /tink dir is going away + allow-parallel-runners: true \ No newline at end of file diff --git a/Makefile b/Makefile index 9e7473c8..2a365557 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ GO_INSTALL = ./scripts/go_install.sh # Binaries. CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14 -GOLANGCI_LINT_VER := v1.54.2 +GOLANGCI_LINT_VER := v1.59.1 GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER) diff --git a/api/v1beta1/tinkerbellmachine_webhook_test.go b/api/v1beta1/tinkerbellmachine_webhook_test.go index b5f9ca8d..af1b89c7 100644 --- a/api/v1beta1/tinkerbellmachine_webhook_test.go +++ b/api/v1beta1/tinkerbellmachine_webhook_test.go @@ -19,7 +19,7 @@ package v1beta1_test import ( "testing" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:revive // one day we will remove gomega metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1" diff --git a/controllers/machine_reconcile_scope.go b/controllers/machine_reconcile_scope.go index 02ead052..23fd8d5e 100644 --- a/controllers/machine_reconcile_scope.go +++ b/controllers/machine_reconcile_scope.go @@ -734,7 +734,8 @@ func (scope *machineReconcileScope) releaseHardware(hardware *tinkv1.Hardware) e // setting the AllowPXE=true indicates to Smee that this hardware should be allowed // to netboot. FYI, this is not authoritative. // Other hardware values can be set to prohibit netbooting of a machine. - // See this Boots function for the logic around this: https://github.com/tinkerbell/smee/blob/main/internal/ipxe/script/ipxe.go#L112 + // See this Boots function for the logic around this: + // https://github.com/tinkerbell/smee/blob/main/internal/ipxe/script/ipxe.go#L112 for _, ifc := range hardware.Spec.Interfaces { if ifc.Netboot != nil { ifc.Netboot.AllowPXE = ptr.To(true) diff --git a/controllers/machine_reconcile_scope_test.go b/controllers/machine_reconcile_scope_test.go index 2561ebf0..a52b5f68 100644 --- a/controllers/machine_reconcile_scope_test.go +++ b/controllers/machine_reconcile_scope_test.go @@ -19,7 +19,7 @@ package controllers //nolint:testpackage import ( "testing" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:revive // one day we will remove gomega clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) @@ -48,7 +48,7 @@ func Test_Machine(t *testing.T) { ready bool }{ "is_not_ready_when_it_is_nil": { - mutateF: func(m *clusterv1.Machine) *clusterv1.Machine { + mutateF: func(_ *clusterv1.Machine) *clusterv1.Machine { return nil }, }, diff --git a/controllers/tinkerbellcluster_controller_test.go b/controllers/tinkerbellcluster_controller_test.go index 7f173c4a..cdb928fd 100644 --- a/controllers/tinkerbellcluster_controller_test.go +++ b/controllers/tinkerbellcluster_controller_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/google/uuid" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:revive // one day we will remove gomega corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" diff --git a/controllers/tinkerbellmachine_controller_test.go b/controllers/tinkerbellmachine_controller_test.go index a3631a19..c9badabe 100644 --- a/controllers/tinkerbellmachine_controller_test.go +++ b/controllers/tinkerbellmachine_controller_test.go @@ -23,7 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/uuid" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:revive // one day we will remove gomega corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -431,6 +431,7 @@ func Test_Machine_reconciliation_with_available_hardware(t *testing.T) { updatedHardware := &tinkv1.Hardware{} g.Expect(client.Get(ctx, hardwareNamespacedName, updatedHardware)).To(Succeed()) + if diff := cmp.Diff(updatedHardware.Spec.Interfaces[0].Netboot.AllowPXE, ptr.To(true)); diff != "" { t.Errorf(diff) } @@ -565,6 +566,7 @@ func Test_Machine_reconciliation_workflow_complete(t *testing.T) { updatedHardware := &tinkv1.Hardware{} g.Expect(client.Get(ctx, hardwareNamespacedName, updatedHardware)).To(Succeed()) + if diff := cmp.Diff(updatedHardware.Spec.Interfaces[0].Netboot.AllowPXE, ptr.To(false)); diff != "" { t.Errorf(diff) } diff --git a/internal/templates/templates_test.go b/internal/templates/templates_test.go index daf05ca9..f65e3d73 100644 --- a/internal/templates/templates_test.go +++ b/internal/templates/templates_test.go @@ -19,7 +19,7 @@ package templates_test import ( "testing" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:revive // one day we will remove gomega "sigs.k8s.io/yaml" "github.com/tinkerbell/cluster-api-provider-tinkerbell/internal/templates" @@ -62,11 +62,11 @@ func Test_Cloud_config_template(t *testing.T) { }, "renders_with_valid_config": { - mutateF: func(wt *templates.WorkflowTemplate) {}, + mutateF: func(_ *templates.WorkflowTemplate) {}, }, "rendered_output_should_be_valid_YAML": { - validateF: func(t *testing.T, wt *templates.WorkflowTemplate, renderResult string) { //nolint:thelper + validateF: func(t *testing.T, _ *templates.WorkflowTemplate, renderResult string) { //nolint:thelper g := NewWithT(t) x := &map[string]interface{}{} diff --git a/main.go b/main.go index 8c469e7f..bb0473f6 100644 --- a/main.go +++ b/main.go @@ -295,11 +295,13 @@ func main() { //nolint:funlen HealthProbeBindAddress: healthAddr, EventBroadcaster: broadcaster, } + if watchNamespace != "" { opts.Cache = cache.Options{ DefaultNamespaces: map[string]cache.Config{watchNamespace: {}}, } } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts) if err != nil { setupLog.Error(err, "unable to start manager")