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

Upgraded go and golangci-lint #963

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- funlen
- goconst
Expand All @@ -75,7 +73,6 @@ linters:
- gofmt
- goimports
- revive
- gomnd
- goprintffuncname
- gosec
- gosimple
Expand All @@ -88,13 +85,11 @@ linters:
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

# don't enable:
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This repo contains the following directories and files:
Before you begin, you must manually install the following software:

- [docker](https://docs.docker.com/get-docker/) (version 23.0)
- [go](https://golang.org/doc/install) (version 1.22.5)
- [go](https://golang.org/doc/install) (version 1.23.2)
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) (version 1.20.1)
- [helm](https://helm.sh/docs/intro/install/) (version 3.5.0)
- [kubectx](https://github.com/ahmetb/kubectx/releases/download/v0.9.1/kubectx) (version 0.9.1)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ OLM_TEST_CATALOG_SOURCE=e2e-test-catalog
NAMESPACE?=verticadb-operator

# The Go version that we will build the operator with
GO_VERSION?=1.22.5
GO_VERSION?=1.23.2
GOPATH?=${HOME}/go
TMPDIR?=$(PWD)
HELM_UNITTEST_VERSION?=3.9.3-0.2.11
Expand Down Expand Up @@ -646,7 +646,7 @@ KUSTOMIZE_VERSION ?= v4.5.5
CONTROLLER_TOOLS_VERSION ?= v0.14.0
KIND_VERSION ?= v0.20.0
KUBERNETES_SPLIT_YAML_VERSION ?= v0.3.0
GOLANGCI_LINT_VER ?= 1.54.2
GOLANGCI_LINT_VER ?= 1.61.0

## Tool architecture
GOOS ?= $(shell go env GOOS)
Expand Down
5 changes: 5 additions & 0 deletions changes/unreleased/Security-20241017-160709.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Security
body: Fix for CVE-2022-30635, CVE-2024-34156, and CVE-2024-34158.
time: 2024-10-17T16:07:09.266021465-04:00
custom:
Issue: "963"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vertica/vertica-kubernetes

go 1.22.5
go 1.23.2

require (
cloud.google.com/go/secretmanager v1.11.4
Expand Down
4 changes: 2 additions & 2 deletions pkg/catalog/fetch_node_details_vcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (nodeDetails *NodeDetails) parseVNodeDetails(vnodeDetails *vclusterops.Node
nodeDetails.SubclusterOid = strconv.FormatUint(vnodeDetails.SubclusterID, 10)
nodeDetails.ReadOnly = vnodeDetails.IsReadOnly
nodeDetails.SandboxName = vnodeDetails.SandboxName
nodeDetails.ShardSubscriptions = int(vnodeDetails.NumberShardSubscriptions)
nodeDetails.ShardSubscriptions = int(vnodeDetails.NumberShardSubscriptions) //nolint:gosec
// The shard subscriptions we get from vcluster includes the replica shard.
// We decrement that by one to account for that. We want to know when there
// are 0 shard subscriptions in order to drive a shard rebalance.
Expand All @@ -55,7 +55,7 @@ func (nodeDetails *NodeDetails) parseVNodeDetails(vnodeDetails *vclusterops.Node
}
for _, storageLoc := range vnodeDetails.StorageLocList {
if storageLoc.UsageType == "DEPOT" {
nodeDetails.MaxDepotSize = int(storageLoc.MaxSize)
nodeDetails.MaxDepotSize = storageLoc.MaxSize
nodeDetails.DepotDiskPercentSize = storageLoc.DiskPercent
break
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/catalog/fetch_node_details_vcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("nodedetailsvcluster", func() {
Expect(nodeDetails.ReadOnly).Should(BeFalse())
Expect(nodeDetails.SandboxName).Should(Equal("sandbox1"))
Expect(nodeDetails.ShardSubscriptions).Should(Equal(2))
Expect(nodeDetails.MaxDepotSize).Should(Equal(8215897325568))
Expect(nodeDetails.MaxDepotSize).Should(Equal(uint64(8215897325568)))
Expect(nodeDetails.DepotDiskPercentSize).Should(Equal("60%"))
})
})
2 changes: 1 addition & 1 deletion pkg/catalog/fetch_node_details_vsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (nodeDetails *NodeDetails) parseDepotDetails(op string) error {
return fmt.Errorf("expected %d columns from storage_locations query but only got %d", ExpectedCols, len(cols))
}
var err error
nodeDetails.MaxDepotSize, err = strconv.Atoi(cols[0])
nodeDetails.MaxDepotSize, err = strconv.ParseUint(cols[0], 10, 64)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/catalog/fetch_node_details_vsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ var _ = Describe("nodedetailsvsql", func() {
It("should parse query output of depot details correctly", func() {
nodeDetails := &NodeDetails{}
Expect(nodeDetails.parseDepotDetails("1248116736|60%\n")).Should(Succeed())
Expect(nodeDetails.MaxDepotSize).Should(Equal(1248116736))
Expect(nodeDetails.MaxDepotSize).Should(Equal(uint64(1248116736)))
Expect(nodeDetails.DepotDiskPercentSize).Should(Equal("60%"))
Expect(nodeDetails.parseDepotDetails("3248116736|\n")).Should(Succeed())
Expect(nodeDetails.MaxDepotSize).Should(Equal(3248116736))
Expect(nodeDetails.MaxDepotSize).Should(Equal(uint64(3248116736)))
Expect(nodeDetails.DepotDiskPercentSize).Should(Equal(""))
Expect(nodeDetails.parseDepotDetails("a|b|c")).ShouldNot(Succeed())
Expect(nodeDetails.parseDepotDetails("not-a-number|blah")).ShouldNot(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion pkg/catalog/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type NodeDetails struct {
ReadOnly bool
SandboxName string
ShardSubscriptions int
MaxDepotSize int
MaxDepotSize uint64
DepotDiskPercentSize string
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/vdb/podfacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type PodFact struct {
depotDiskPercentSize string

// The size of the depot in bytes. This is only valid if the database is up.
maxDepotSize int
maxDepotSize uint64

// The size, in bytes, of the local PV.
localDataSize int
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/vdb/resizepv_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r *ResizePVReconcile) updateDepotSize(ctx context.Context, pvc *corev1.Per
// fudge is here in case Vertica and our operator calculate the expected
// depot size differently (i.e. rounding, etc.)
depotSizeLB := (curLocalDataSize * int64(dpAsInt) / 100) - (5 * 1024 * 1024)
if int64(pf.maxDepotSize) >= depotSizeLB {
if depotSizeLB >= 0 && pf.maxDepotSize >= uint64(depotSizeLB) {
r.Log.Info("Depot resize isn't needed in Vertica",
"cur depot size", pf.maxDepotSize, "expected depot size", depotSizeLB)
return ctrl.Result{}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/vdb/revivedb_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (r *ReviveDBReconciler) getPodList() ([]*PodFact, bool) {
return nil, false
}

podsToAdd := int32(cur.PodCount)
podsToAdd := int32(cur.PodCount) //nolint:gosec
podsLeft := scPodCounts[cur.SubclusterIndex]
if podsLeft < podsToAdd || podsToAdd <= 0 {
podsToAdd = podsLeft
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/vdb/status_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (s *StatusReconciler) calculateSubclusterStatus(ctx context.Context, sc *va
return err
}

for podIndex := int32(0); podIndex < int32(len(curStat.Detail)); podIndex++ {
for podIndex := int32(0); podIndex < int32(len(curStat.Detail)); podIndex++ { //nolint:gosec
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see many occurrences of //nolint:gosec. Why is that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version of golangci-lint has a more strict type check. The type conversion int32(xxx) will be reported by go lint.

podName := names.GenPodName(s.Vdb, sc, podIndex)
pf, ok := s.PFacts.Detail[podName]
if !ok {
Expand Down Expand Up @@ -211,11 +211,11 @@ func (s *StatusReconciler) resizeSubclusterStatus(ctx context.Context, sc *vapi.
return err
}
// Grow the detail if needed
for ok := true; ok; ok = int32(len(curStat.Detail)) < scSize {
for ok := true; ok; ok = int32(len(curStat.Detail)) < scSize { //nolint:gosec
curStat.Detail = append(curStat.Detail, vapi.VerticaDBPodStatus{})
}
// Or shrink the size
if int32(len(curStat.Detail)) > scSize {
if int32(len(curStat.Detail)) > scSize { //nolint:gosec
curStat.Detail = curStat.Detail[0:scSize]
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func CreatePods(ctx context.Context, c client.Client, vdb *vapi.VerticaDB, podRu
for i := range vdb.Spec.Subclusters {
sc := &vdb.Spec.Subclusters[i]
const ExpectOffset = 2
CreateSts(ctx, c, vdb, sc, ExpectOffset, int32(i), podRunningState)
CreateSts(ctx, c, vdb, sc, ExpectOffset, int32(i), podRunningState) //nolint:gosec
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vdbgen/vdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (d *DBGenerator) queryLocalPath(ctx context.Context, usage string) (string,
curCommonPrefix := path.Dir(path.Dir(workingDir))
// Check if the prefix matches. If it doesn't then an error is returned
// as paths across all nodes must be homogenous.
if len(commonPrefix) > 0 && commonPrefix != curCommonPrefix {
if commonPrefix != "" && commonPrefix != curCommonPrefix {
return false, fmt.Errorf(
"catalog location path must be the same across all nodes -- path %q does not share the common prefix from other nodes %q",
nodePath.String, commonPrefix)
Expand Down
Loading