diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index a4624b16f03..ce133d9c40c 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -145,7 +145,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.59.1 + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0 - uses: pre-commit/action@v3.0.0 trivy-scan: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a512322e9f6..efb952324aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,14 +1,14 @@ -default_stages: [commit, push] -minimum_pre_commit_version: "1.20.0" +default_stages: [pre-commit, pre-push] +minimum_pre_commit_version: "4.0.0" exclude: (^vendor/|^pkg/generated/) repos: - repo: https://github.com/dnephin/pre-commit-golang - rev: v0.3.5 + rev: v0.5.1 hooks: - id: go-fmt name: Run go fmt against the code - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: detect-private-key @@ -17,7 +17,7 @@ repos: - id: check-merge-conflict - id: mixed-line-ending - repo: https://github.com/thlorenz/doctoc.git - rev: v2.0.0 + rev: v2.2.0 hooks: - id: doctoc name: Add TOC for md files diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 37d7ab508f3..87362c08e13 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -105,18 +105,6 @@ rules: resources: - cloudeventsources - cloudeventsources/status -<<<<<<< HEAD - verbs: - - get - - list - - patch - - update - - watch -- apiGroups: - - eventing.keda.sh - resources: -======= ->>>>>>> 215a6d877 (bump more deps) - clustercloudeventsources - clustercloudeventsources/status verbs: @@ -130,48 +118,12 @@ rules: resources: - clustertriggerauthentications - clustertriggerauthentications/status -<<<<<<< HEAD - verbs: - - get - - list - - patch - - update - - watch -- apiGroups: - - keda.sh - resources: - - scaledjobs - - scaledjobs/finalizers - - scaledjobs/status - verbs: - - get - - list - - patch - - update - - watch -- apiGroups: - - keda.sh - resources: - - scaledobjects - - scaledobjects/finalizers - - scaledobjects/status - verbs: - - get - - list - - patch - - update - - watch -- apiGroups: - - keda.sh - resources: -======= - scaledjobs - scaledjobs/finalizers - scaledjobs/status - scaledobjects - scaledobjects/finalizers - scaledobjects/status ->>>>>>> 215a6d877 (bump more deps) - triggerauthentications - triggerauthentications/status verbs: diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index fabc5d446c7..9fca0b4b424 100755 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -143,7 +143,7 @@ func (r *ScaledJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( // Check jobTargetRef is specified if scaledJob.Spec.JobTargetRef == nil { errMsg := "ScaledJob.spec.jobTargetRef not found" - err := fmt.Errorf(errMsg) + err := fmt.Errorf("%s", errMsg) reqLogger.Error(err, errMsg) r.EventEmitter.Emit(scaledJob, req.NamespacedName.Namespace, corev1.EventTypeWarning, eventingv1alpha1.ScaledJobFailedType, eventreason.ScaledJobCheckFailed, errMsg) return ctrl.Result{}, err diff --git a/pkg/metricscollector/opentelemetry.go b/pkg/metricscollector/opentelemetry.go index db64edde67d..fb6cb3a26c2 100644 --- a/pkg/metricscollector/opentelemetry.go +++ b/pkg/metricscollector/opentelemetry.go @@ -79,7 +79,7 @@ func NewOtelMetrics(options ...metric.Option) *OtelMetrics { } if err != nil { - fmt.Printf("Error:" + err.Error()) + fmt.Printf("Error: %s", err.Error()) return nil } options = []metric.Option{metric.WithReader(metric.NewPeriodicReader(exporter))} diff --git a/pkg/scalers/apache_kafka_scaler.go b/pkg/scalers/apache_kafka_scaler.go index d2b0d3f51c9..8704531e28a 100644 --- a/pkg/scalers/apache_kafka_scaler.go +++ b/pkg/scalers/apache_kafka_scaler.go @@ -402,7 +402,7 @@ func (s *apacheKafkaScaler) Close(context.Context) error { func (s *apacheKafkaScaler) GetMetricSpecForScaling(context.Context) []v2.MetricSpec { var metricName string - if s.metadata.Topic != nil && len(s.metadata.Topic) > 0 { + if len(s.metadata.Topic) > 0 { metricName = fmt.Sprintf("kafka-%s", strings.Join(s.metadata.Topic, ",")) } else { metricName = fmt.Sprintf("kafka-%s-topics", s.metadata.Group) diff --git a/pkg/scalers/aws_cloudwatch_scaler.go b/pkg/scalers/aws_cloudwatch_scaler.go index a07db246f80..cf503c758d4 100644 --- a/pkg/scalers/aws_cloudwatch_scaler.go +++ b/pkg/scalers/aws_cloudwatch_scaler.go @@ -286,7 +286,7 @@ func (s *awsCloudwatchScaler) GetCloudwatchMetrics(ctx context.Context) (float64 if len(output.MetricDataResults) > 0 && len(output.MetricDataResults[0].Values) == 0 && !s.metadata.IgnoreNullValues { emptyMetricsErrMsg := "empty metric data received, ignoreNullValues is false, returning error" s.logger.Error(nil, emptyMetricsErrMsg) - return -1, fmt.Errorf(emptyMetricsErrMsg) + return -1, fmt.Errorf("%s", emptyMetricsErrMsg) } var metricValue float64 diff --git a/pkg/scalers/azure_monitor_scaler.go b/pkg/scalers/azure_monitor_scaler.go index 71050b5063a..aa489fa9ff3 100644 --- a/pkg/scalers/azure_monitor_scaler.go +++ b/pkg/scalers/azure_monitor_scaler.go @@ -348,7 +348,7 @@ func (s *azureMonitorScaler) requestMetric(ctx context.Context) (float64, error) return -1, err } - if response.Value == nil || len(response.Value) == 0 { + if len(response.Value) == 0 { err := fmt.Errorf("got an empty response for metric %s/%s and aggregate type %s", "azMetricRequest.ResourceProviderNamespace", "azMetricRequest.MetricName", "azMetricRequest.Aggregation") return -1, err } diff --git a/pkg/scalers/huawei_cloudeye_scaler.go b/pkg/scalers/huawei_cloudeye_scaler.go index 528806f5b44..7b3e75ea465 100644 --- a/pkg/scalers/huawei_cloudeye_scaler.go +++ b/pkg/scalers/huawei_cloudeye_scaler.go @@ -329,7 +329,7 @@ func (s *huaweiCloudeyeScaler) GetCloudeyeMetrics() (float64, error) { var metricValue float64 - if metricdatas[0].Datapoints != nil && len(metricdatas[0].Datapoints) > 0 { + if len(metricdatas[0].Datapoints) > 0 { v, ok := metricdatas[0].Datapoints[0][s.metadata.metricFilter].(float64) if ok { metricValue = v diff --git a/pkg/scalers/ibmmq_scaler.go b/pkg/scalers/ibmmq_scaler.go index 0b0b4c893f4..ecae97c5e8a 100644 --- a/pkg/scalers/ibmmq_scaler.go +++ b/pkg/scalers/ibmmq_scaler.go @@ -159,7 +159,7 @@ func (s *ibmmqScaler) getQueueDepthViaHTTP(ctx context.Context) (int64, error) { return 0, fmt.Errorf("failed to parse JSON: %w", err) } - if response.CommandResponse == nil || len(response.CommandResponse) == 0 { + if len(response.CommandResponse) == 0 { return 0, fmt.Errorf("failed to parse response from REST call") } diff --git a/pkg/scalers/kafka_scaler_test.go b/pkg/scalers/kafka_scaler_test.go index fe42e28995c..b09a810a18a 100644 --- a/pkg/scalers/kafka_scaler_test.go +++ b/pkg/scalers/kafka_scaler_test.go @@ -429,13 +429,13 @@ func TestKafkaAuthParamsInTriggerAuthentication(t *testing.T) { if testData.authParams["keytab"] != "" { err := testFileContents(testData, meta, "keytab") if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } } if !testData.isError { err := testFileContents(testData, meta, "kerberosConfig") if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } } if meta.kerberosServiceName != testData.authParams["kerberosServiceName"] { diff --git a/pkg/scalers/openstack/keystone_authentication.go b/pkg/scalers/openstack/keystone_authentication.go index b1106bd2786..68322cceabb 100644 --- a/pkg/scalers/openstack/keystone_authentication.go +++ b/pkg/scalers/openstack/keystone_authentication.go @@ -294,7 +294,7 @@ func (keystone *KeystoneAuthRequest) getToken(ctx context.Context) (string, erro return "", err } - return "", fmt.Errorf(string(errBody)) + return "", fmt.Errorf("%s", string(errBody)) } // getCatalog retrives the OpenStack catalog according to the current authorization @@ -343,7 +343,7 @@ func (keystone *KeystoneAuthRequest) getCatalog(ctx context.Context, token strin return nil, err } - return nil, fmt.Errorf(string(errBody)) + return nil, fmt.Errorf("%s", string(errBody)) } // getServiceURL retrieves a public URL for an OpenStack project from the OpenStack catalog diff --git a/pkg/scalers/openstack_metrics_scaler.go b/pkg/scalers/openstack_metrics_scaler.go index da98d2fdabc..65461e5990d 100644 --- a/pkg/scalers/openstack_metrics_scaler.go +++ b/pkg/scalers/openstack_metrics_scaler.go @@ -329,7 +329,7 @@ func (s *openstackMetricScaler) readOpenstackMetrics(ctx context.Context) (float return defaultValueWhenError, readError } - return defaultValueWhenError, fmt.Errorf(string(bodyError)) + return defaultValueWhenError, fmt.Errorf("%s", string(bodyError)) } m := measureResult{} diff --git a/pkg/scalers/rabbitmq_scaler.go b/pkg/scalers/rabbitmq_scaler.go index f7ed365f52d..43a62a404ee 100644 --- a/pkg/scalers/rabbitmq_scaler.go +++ b/pkg/scalers/rabbitmq_scaler.go @@ -604,7 +604,7 @@ func getMaximum(q []queueInfo) (int, int, float64) { // Mask host for log purposes func (s *rabbitMQScaler) anonymizeRabbitMQError(err error) error { errorMessage := fmt.Sprintf("error inspecting rabbitMQ: %s", err) - return fmt.Errorf(rabbitMQAnonymizePattern.ReplaceAllString(errorMessage, "user:password@")) + return fmt.Errorf("%s", rabbitMQAnonymizePattern.ReplaceAllString(errorMessage, "user:password@")) } // connectionName is used to provide a deterministic AMQP connection name when diff --git a/pkg/scaling/resolver/scale_resolvers.go b/pkg/scaling/resolver/scale_resolvers.go index 54976381aee..6ca40672fc6 100644 --- a/pkg/scaling/resolver/scale_resolvers.go +++ b/pkg/scaling/resolver/scale_resolvers.go @@ -134,7 +134,7 @@ func ResolveScaleTargetPodSpec(ctx context.Context, kubeClient client.Client, sc podTemplateSpec.Spec = withPods.Spec.Template.Spec } - if podTemplateSpec.Spec.Containers == nil || len(podTemplateSpec.Spec.Containers) == 0 { + if len(podTemplateSpec.Spec.Containers) == 0 { logger.V(1).Info("There aren't any containers found in the ScaleTarget, therefore it is no possible to inject environment properties", "scaleTargetRef.Name", obj.Spec.ScaleTargetRef.Name) return nil, "", nil } diff --git a/pkg/scaling/scale_handler.go b/pkg/scaling/scale_handler.go index 5a955e48e66..a8c50a057d0 100644 --- a/pkg/scaling/scale_handler.go +++ b/pkg/scaling/scale_handler.go @@ -580,7 +580,7 @@ func (h *scaleHandler) GetScaledObjectMetrics(ctx context.Context, scaledObjectN } if len(matchingMetrics) == 0 { - return nil, fmt.Errorf("no matching metrics found for " + metricsName) + return nil, fmt.Errorf("no matching metrics found for %s", metricsName) } // handle scalingModifiers here and simply return the matchingMetrics