From 9f8a88ce164ae020d65016a6046609c9afc2dc9f Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 8 Nov 2024 11:01:56 -0700 Subject: [PATCH 1/2] Update linter version and fix linting errors: Signed-off-by: Jacob Weinstock --- .golangci.yml | 5 +---- Makefile | 2 +- internal/backend/flatfile/backend_test.go | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6b7695c0..51db2477 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,7 @@ linters: - asciicheck - bidichk - bodyclose + - copyloopvar - contextcheck - cyclop - dogsled @@ -26,7 +27,6 @@ linters: - errname - errorlint - exhaustive - - exportloopref - forcetypeassert - gci - gocognit @@ -112,9 +112,6 @@ linters-settings: - name: unconditional-recursion - name: waitgroup-by-value - unused: - go: "1.21" - issues: # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: diff --git a/Makefile b/Makefile index 6c89a8c7..f30b45df 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ help: # -- Tooling -GOLANGCI_LINT_VERSION ?= v1.55.2 +GOLANGCI_LINT_VERSION ?= v1.61.0 GOLANGCI_LINT := $(TOOLS_DIR)/golangci-lint $(GOLANGCI_LINT): curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \ diff --git a/internal/backend/flatfile/backend_test.go b/internal/backend/flatfile/backend_test.go index 594b9c85..ab7fc110 100644 --- a/internal/backend/flatfile/backend_test.go +++ b/internal/backend/flatfile/backend_test.go @@ -73,7 +73,7 @@ func TestGetEC2Instance(t *testing.T) { } if !cmp.Equal(&ec2Instance, tc.ExpectedInstance) { - t.Errorf(cmp.Diff(ec2Instance, tc.ExpectedInstance)) + t.Error(cmp.Diff(ec2Instance, tc.ExpectedInstance)) } } }) From a3b3716483fc737685d541158ee3270ee114e34e Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 8 Nov 2024 11:02:15 -0700 Subject: [PATCH 2/2] Handle nil pointer potential: As the Hardware spec.metadata and spec.metadata.instance are not required in the hardware object they could be nil. Handle checking this so we don't nil pointer panic. Signed-off-by: Jacob Weinstock --- internal/backend/kubernetes/backend.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/backend/kubernetes/backend.go b/internal/backend/kubernetes/backend.go index 6d6e5654..3abd513a 100644 --- a/internal/backend/kubernetes/backend.go +++ b/internal/backend/kubernetes/backend.go @@ -162,7 +162,7 @@ type listerClient interface { func toEC2Instance(hw tinkv1.Hardware) ec2.Instance { var i ec2.Instance - if hw.Spec.Metadata.Instance != nil { + if hw.Spec.Metadata != nil && hw.Spec.Metadata.Instance != nil { i.Metadata.InstanceID = hw.Spec.Metadata.Instance.ID i.Metadata.Hostname = hw.Spec.Metadata.Instance.Hostname i.Metadata.LocalHostname = hw.Spec.Metadata.Instance.Hostname @@ -195,7 +195,7 @@ func toEC2Instance(hw tinkv1.Hardware) ec2.Instance { } } - if hw.Spec.Metadata.Facility != nil { + if hw.Spec.Metadata != nil && hw.Spec.Metadata.Facility != nil { i.Metadata.Plan = hw.Spec.Metadata.Facility.PlanSlug i.Metadata.Facility = hw.Spec.Metadata.Facility.FacilityCode }