Skip to content

Commit

Permalink
bump golang version and update the linter
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer committed Feb 3, 2025
1 parent e174457 commit 1be9d97
Show file tree
Hide file tree
Showing 27 changed files with 31 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM golang:1.23.4
FROM golang:1.23.5

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
id-token: write # needed for signing the images with GitHub OIDC Token **not production ready**

# keda-tools is built from github.com/test-tools/tools/Dockerfile
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
triage:
runs-on: ubuntu-latest
name: Comment evaluate
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
outputs:
run-e2e: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }}
pr_num: ${{ steps.parser.outputs.pr_num }}
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
needs: triage
runs-on: ubuntu-latest
name: Build images
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
if: needs.triage.outputs.run-e2e == 'true'
steps:
- name: Set status in-progress
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
needs: [triage, build-test-images]
runs-on: e2e
name: Execute e2e tests
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
if: needs.triage.outputs.run-e2e == 'true'
steps:
- name: Set status in-progress
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
validate:
name: validate - ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
strategy:
matrix:
include:
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
pull-requests: read # for dorny/paths-filter to read pull requests
name: validate-dockerfiles - ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
strategy:
matrix:
include:
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
pull-requests: read # for dorny/paths-filter to read pull requests
name: Validate dev-container - ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
strategy:
matrix:
include:
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
with:
go-version: "1.23"
- name: Get golangci
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin 1.63.4
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

trivy-scan:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
id-token: write # needed for signing the images with GitHub OIDC Token **not production ready**

# keda-tools is built from github.com/test-tools/tools/Dockerfile
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
codeQl:
name: Analyze CodeQL Go
runs-on: ubuntu-latest
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
if: (github.actor != 'dependabot[bot]')
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/template-main-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Run e2e test
runs-on: ARM64
# keda-tools is built from github.com/test-tools/tools/Dockerfile
container: ghcr.io/kedacore/keda-tools:1.23.3
container: ghcr.io/kedacore/keda-tools:1.23.5
concurrency: e2e-tests
steps:
- name: Check out code
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ linters:
- unconvert
- ineffassign
- staticcheck
- exportloopref
- copyloopvar
- depguard
- dogsled
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ For more installation options visit the [pre-commits](https://pre-commit.com).

Before running pre-commit, you must install the [golangci-lint](https://golangci-lint.run/) tool as a static check tool for golang code (contains a series of linter)
```shell script
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.63.4
# or
brew install golangci/tap/golangci-lint
```
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/keda-tools:1.23.4 AS builder
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/keda-tools:1.23.5 AS builder

ARG BUILD_VERSION=main
ARG GIT_COMMIT=HEAD
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.adapter
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the adapter binary
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/keda-tools:1.23.4 AS builder
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/keda-tools:1.23.5 AS builder

ARG BUILD_VERSION=main
ARG GIT_COMMIT=HEAD
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.webhooks
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/keda-tools:1.23.4 AS builder
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/keda-tools:1.23.5 AS builder

ARG BUILD_VERSION=main
ARG GIT_COMMIT=HEAD
Expand Down
1 change: 0 additions & 1 deletion apis/keda/v1alpha1/scaledjob_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestScaledJob(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
scaledJob := &ScaledJob{
Spec: ScaledJobSpec{
Expand Down
14 changes: 7 additions & 7 deletions apis/keda/v1alpha1/scaledobject_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,18 @@ func (so *ScaledObject) GetHPAMaxReplicas() int32 {
// checkReplicaCountBoundsAreValid checks that Idle/Min/Max ReplicaCount defined in ScaledObject are correctly specified
// i.e. that Min is not greater than Max or Idle greater or equal to Min
func CheckReplicaCountBoundsAreValid(scaledObject *ScaledObject) error {
min := int32(0)
minReplicas := int32(0)
if scaledObject.Spec.MinReplicaCount != nil {
min = *scaledObject.GetHPAMinReplicas()
minReplicas = *scaledObject.GetHPAMinReplicas()
}
max := scaledObject.GetHPAMaxReplicas()
maxReplicas := scaledObject.GetHPAMaxReplicas()

if min > max {
return fmt.Errorf("MinReplicaCount=%d must be less than MaxReplicaCount=%d", min, max)
if minReplicas > maxReplicas {
return fmt.Errorf("MinReplicaCount=%d must be less than MaxReplicaCount=%d", minReplicas, maxReplicas)
}

if scaledObject.Spec.IdleReplicaCount != nil && *scaledObject.Spec.IdleReplicaCount >= min {
return fmt.Errorf("IdleReplicaCount=%d must be less than MinReplicaCount=%d", *scaledObject.Spec.IdleReplicaCount, min)
if scaledObject.Spec.IdleReplicaCount != nil && *scaledObject.Spec.IdleReplicaCount >= minReplicas {
return fmt.Errorf("IdleReplicaCount=%d must be less than MinReplicaCount=%d", *scaledObject.Spec.IdleReplicaCount, minReplicas)
}

return nil
Expand Down
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/kedacore/keda/v2

go 1.23.4
go 1.23.5

require (
cloud.google.com/go/compute/metadata v0.6.0
Expand Down
1 change: 0 additions & 1 deletion pkg/scalers/beanstalkd_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func TestBeanstalkdGetMetricSpecForScaling(t *testing.T) {

func TestGetTubeStats(t *testing.T) {
for _, testData := range testTubeStatsTestData {
testData := testData
yamlData, err := yaml.Marshal(testData.response)
if err != nil {
t.Fatal(err)
Expand Down
14 changes: 2 additions & 12 deletions pkg/scalers/datadog_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -564,7 +565,7 @@ func (s *datadogScaler) getQueryResult(ctx context.Context) (float64, error) {
return AvgFloatFromSlice(results), nil
default:
// Aggregate Results - default Max value:
return MaxFloatFromSlice(results), nil
return slices.Max(results), nil
}
}

Expand Down Expand Up @@ -674,17 +675,6 @@ func (s *datadogScaler) GetMetricsAndActivity(ctx context.Context, metricName st
return []external_metrics.ExternalMetricValue{metric}, num > s.metadata.activationQueryValue, nil
}

// MaxFloatFromSlice finds the largest value in a slice of floats
func MaxFloatFromSlice(results []float64) float64 {
max := results[0]
for _, result := range results {
if result > max {
max = result
}
}
return max
}

// AvgFloatFromSlice finds the average value in a slice of floats
func AvgFloatFromSlice(results []float64) float64 {
total := 0.0
Expand Down
3 changes: 2 additions & 1 deletion pkg/scalers/datadog_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scalers

import (
"context"
"slices"
"testing"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestMaxFloatFromSlice(t *testing.T) {
input := []float64{1.0, 2.0, 3.0, 4.0}
expectedOutput := float64(4.0)

output := MaxFloatFromSlice(input)
output := slices.Max(input)

assertEqual(t, output, expectedOutput)
}
Expand Down
16 changes: 2 additions & 14 deletions pkg/scalers/ibmmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"slices"

"github.com/go-logr/logr"
v2 "k8s.io/api/autoscaling/v2"
Expand Down Expand Up @@ -211,7 +212,7 @@ func calculateDepth(depths []int64, operation string) int64 {
case avgOperation:
return avgDepths(depths)
case maxOperation:
return maxDepths(depths)
return slices.Max(depths)
default:
return 0
}
Expand All @@ -232,19 +233,6 @@ func avgDepths(depths []int64) int64 {
return sumDepths(depths) / int64(len(depths))
}

func maxDepths(depths []int64) int64 {
if len(depths) == 0 {
return 0
}
max := depths[0]
for _, depth := range depths[1:] {
if depth > max {
max = depth
}
}
return max
}

func (s *ibmmqScaler) GetMetricSpecForScaling(context.Context) []v2.MetricSpec {
metricName := kedautil.NormalizeString(fmt.Sprintf("ibmmq-%s", s.metadata.QueueName[0]))
externalMetric := &v2.ExternalMetricSource{
Expand Down
3 changes: 0 additions & 3 deletions pkg/scalers/openstack_metrics_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func TestOpenstackMetricsGetMetricsForSpecScaling(t *testing.T) {
}

for _, testData := range testCases {
testData := testData
meta, err := parseOpenstackMetricMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}, logr.Discard())

if err != nil {
Expand Down Expand Up @@ -144,7 +143,6 @@ func TestOpenstackMetricsGetMetricsForSpecScalingInvalidMetaData(t *testing.T) {
}

for _, testData := range testCases {
testData := testData
t.Run(testData.name, func(pt *testing.T) {
_, err := parseOpenstackMetricMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}, logr.Discard())
assert.NotNil(t, err)
Expand All @@ -163,7 +161,6 @@ func TestOpenstackMetricAuthenticationInvalidAuthMetadata(t *testing.T) {
}

for _, testData := range testCases {
testData := testData
t.Run(testData.name, func(ptr *testing.T) {
_, err := parseOpenstackMetricAuthenticationMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex})
assert.NotNil(t, err)
Expand Down
3 changes: 0 additions & 3 deletions pkg/scalers/openstack_swift_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func TestOpenstackSwiftGetMetricSpecForScaling(t *testing.T) {
}

for _, testData := range testCases {
testData := testData
meta, err := parseOpenstackSwiftMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex})
if err != nil {
t.Fatal("Could not parse metadata:", err)
Expand Down Expand Up @@ -135,7 +134,6 @@ func TestParseOpenstackSwiftMetadataForInvalidCases(t *testing.T) {
}

for _, testData := range testCases {
testData := testData
t.Run(testData.name, func(pt *testing.T) {
_, err := parseOpenstackSwiftMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex})
assert.NotNil(t, err)
Expand All @@ -155,7 +153,6 @@ func TestParseOpenstackSwiftAuthenticationMetadataForInvalidCases(t *testing.T)
}

for _, testData := range testCases {
testData := testData
t.Run(testData.name, func(pt *testing.T) {
_, err := parseOpenstackSwiftAuthenticationMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex})
assert.NotNil(t, err)
Expand Down
2 changes: 0 additions & 2 deletions pkg/scalers/rabbitmq_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ func TestGetQueueInfo(t *testing.T) {
}

for _, testData := range allTestData {
testData := testData
vhost, path := getVhostAndPathFromURL(testData.urlPath, testData.extraMetadata["vhostName"])
var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
expectedPath := fmt.Sprintf("%s/api/queues%s/evaluate_trials", path, vhost)
Expand Down Expand Up @@ -512,7 +511,6 @@ func TestGetQueueInfoWithRegex(t *testing.T) {
}

for _, testData := range allTestData {
testData := testData
vhost, path := getVhostAndPathFromURL(testData.urlPath, testData.extraMetadata["vhostName"])
var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
expectedPath := fmt.Sprintf("%s/api/queues%s?page=1&use_regex=true&pagination=false&name=%%5Eevaluate_trials%%24&page_size=100", path, vhost)
Expand Down
3 changes: 0 additions & 3 deletions pkg/scalers/redis_streams_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestParseRedisStreamsMetadata(t *testing.T) {
}

for _, tc := range testCasesPending {
tc := tc
t.Run(tc.name, func(te *testing.T) {
m, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: tc.authParams})
assert.Nil(t, err)
Expand Down Expand Up @@ -97,7 +96,6 @@ func TestParseRedisStreamsMetadata(t *testing.T) {
}

for _, tc := range testCasesLag {
tc := tc
t.Run(tc.name, func(te *testing.T) {
m, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: tc.authParams})
assert.Nil(t, err)
Expand Down Expand Up @@ -158,7 +156,6 @@ func TestParseRedisStreamsMetadataForInvalidCases(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(te *testing.T) {
_, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: map[string]string{}})
assert.NotNil(t, err)
Expand Down
Loading

0 comments on commit 1be9d97

Please sign in to comment.