Skip to content

Commit

Permalink
enable golint:unconvert,unused,stylecheck (#1228)
Browse files Browse the repository at this point in the history
Signed-off-by: Michele <[email protected]>
  • Loading branch information
mdeggies authored Oct 9, 2020
1 parent b2abfaf commit c498970
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 127 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ linters:
#- gocyclo
- gosimple
#- staticcheck
#- stylecheck
#- unused
- stylecheck
- unused
- varcheck
- unparam
#- unconvert
- unconvert
- whitespace

issues:
Expand Down
2 changes: 1 addition & 1 deletion controllers/util/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func SetStatusConditions(client runtimeclient.Client, logger logr.Logger, object
patch = runtimeclient.MergeFrom(obj.DeepCopy())
obj.Status.Conditions = *conditions
default:
err := fmt.Errorf("Unknown scalable object type %v", obj)
err := fmt.Errorf("unknown scalable object type %v", obj)
logger.Error(err, "Failed to patch Objects Status with Conditions")
return err
}
Expand Down
11 changes: 4 additions & 7 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ type KedaProvider struct {
scaleHandler scaling.ScaleHandler
watchedNamespace string
}
type externalMetric struct {
info provider.ExternalMetricInfo
labels map[string]string
value external_metrics.ExternalMetricValue
}

type externalMetric struct{}

var logger logr.Logger
var metricsServer prommetrics.PrometheusMetricServer
Expand Down Expand Up @@ -75,15 +72,15 @@ func (p *KedaProvider) GetExternalMetric(namespace string, metricSelector labels
if err != nil {
return nil, err
} else if len(scaledObjects.Items) != 1 {
return nil, fmt.Errorf("Exactly one scaled object should match label %s", metricSelector.String())
return nil, fmt.Errorf("exactly one scaled object should match label %s", metricSelector.String())
}

scaledObject := &scaledObjects.Items[0]
matchingMetrics := []external_metrics.ExternalMetricValue{}
scalers, err := p.scaleHandler.GetScalers(scaledObject)
metricsServer.RecordScalerObjectError(scaledObject.Namespace, scaledObject.Name, err)
if err != nil {
return nil, fmt.Errorf("Error when getting scalers %s", err)
return nil, fmt.Errorf("error when getting scalers %s", err)
}

for scalerIndex, scaler := range scalers {
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/artemis_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *artemisScaler) getQueueMessageCount() (int, error) {
if resp.StatusCode == 200 && monitoringInfo.Status == 200 {
messageCount = monitoringInfo.MsgCount
} else {
return -1, fmt.Errorf("Artemis management endpoint response error code : %d", resp.StatusCode)
return -1, fmt.Errorf("artemis management endpoint response error code : %d", resp.StatusCode)
}

artemisLog.V(1).Info(fmt.Sprintf("Artemis scaler: Providing metrics based on current queue length %d queue length limit %d", messageCount, s.metadata.queueLength))
Expand Down
16 changes: 7 additions & 9 deletions pkg/scalers/aws_cloudwatch_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type awsCloudwatchMetadata struct {
awsRegion string

awsAuthorization awsAuthorizationMetadata

authParams map[string]string
}

var cloudwatchLog = logf.Log.WithName("aws_cloudwatch_scaler")
Expand All @@ -58,7 +56,7 @@ var cloudwatchLog = logf.Log.WithName("aws_cloudwatch_scaler")
func NewAwsCloudwatchScaler(resolvedEnv, metadata, authParams map[string]string) (Scaler, error) {
meta, err := parseAwsCloudwatchMetadata(metadata, resolvedEnv, authParams)
if err != nil {
return nil, fmt.Errorf("Error parsing Cloudwatch metadata: %s", err)
return nil, fmt.Errorf("error parsing cloudwatch metadata: %s", err)
}

return &awsCloudwatchScaler{
Expand All @@ -75,25 +73,25 @@ func parseAwsCloudwatchMetadata(metadata, resolvedEnv, authParams map[string]str
if val, ok := metadata["namespace"]; ok && val != "" {
meta.namespace = val
} else {
return nil, fmt.Errorf("Namespace not given")
return nil, fmt.Errorf("namespace not given")
}

if val, ok := metadata["metricName"]; ok && val != "" {
meta.metricsName = val
} else {
return nil, fmt.Errorf("Metric Name not given")
return nil, fmt.Errorf("metric name not given")
}

if val, ok := metadata["dimensionName"]; ok && val != "" {
meta.dimensionName = val
} else {
return nil, fmt.Errorf("Dimension Name not given")
return nil, fmt.Errorf("dimension name not given")
}

if val, ok := metadata["dimensionValue"]; ok && val != "" {
meta.dimensionValue = val
} else {
return nil, fmt.Errorf("Dimension Value not given")
return nil, fmt.Errorf("dimension value not given")
}

if val, ok := metadata["targetMetricValue"]; ok && val != "" {
Expand All @@ -115,7 +113,7 @@ func parseAwsCloudwatchMetadata(metadata, resolvedEnv, authParams map[string]str
meta.minMetricValue = minMetricValue
}
} else {
return nil, fmt.Errorf("Min Metric Value not given")
return nil, fmt.Errorf("min metric value not given")
}

if val, ok := metadata["metricCollectionTime"]; ok && val != "" {
Expand Down Expand Up @@ -262,7 +260,7 @@ func (c *awsCloudwatchScaler) GetCloudwatchMetrics() (float64, error) {
if output.MetricDataResults[0].Values != nil {
metricValue = *output.MetricDataResults[0].Values[0]
} else {
return -1, fmt.Errorf("Metric Data not received")
return -1, fmt.Errorf("metric data not received")
}

return metricValue, nil
Expand Down
1 change: 0 additions & 1 deletion pkg/scalers/aws_iam_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type awsAuthorizationMetadata struct {

awsAccessKeyID string
awsSecretAccessKey string
awsSessionToken string

podIdentityOwner bool
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/aws_kinesis_stream_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var kinesisStreamLog = logf.Log.WithName("aws_kinesis_stream_scaler")
func NewAwsKinesisStreamScaler(resolvedEnv, metadata map[string]string, authParams map[string]string) (Scaler, error) {
meta, err := parseAwsKinesisStreamMetadata(metadata, resolvedEnv, authParams)
if err != nil {
return nil, fmt.Errorf("Error parsing Kinesis stream metadata: %s", err)
return nil, fmt.Errorf("error parsing Kinesis stream metadata: %s", err)
}

return &awsKinesisStreamScaler{
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/aws_sqs_queue_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var sqsQueueLog = logf.Log.WithName("aws_sqs_queue_scaler")
func NewAwsSqsQueueScaler(resolvedEnv, metadata map[string]string, authParams map[string]string) (Scaler, error) {
meta, err := parseAwsSqsQueueMetadata(metadata, resolvedEnv, authParams)
if err != nil {
return nil, fmt.Errorf("Error parsing SQS queue metadata: %s", err)
return nil, fmt.Errorf("error parsing SQS queue metadata: %s", err)
}

return &awsSqsQueueScaler{
Expand Down
12 changes: 6 additions & 6 deletions pkg/scalers/azure/azure_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,25 @@ func extractValue(azMetricRequest azureExternalMetricRequest, metricResult insig
metricVals := *metricResult.Value

if len(metricVals) == 0 {
err := fmt.Errorf("Got an empty response for metric %s/%s and aggregate type %s", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, insights.AggregationType(strings.ToTitle(azMetricRequest.Aggregation)))
err := fmt.Errorf("got an empty response for metric %s/%s and aggregate type %s", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, insights.AggregationType(strings.ToTitle(azMetricRequest.Aggregation)))
return -1, err
}

timeseriesPtr := metricVals[0].Timeseries
if timeseriesPtr == nil || len(*timeseriesPtr) == 0 {
err := fmt.Errorf("Got metric result for %s/%s and aggregate type %s without timeseries", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, insights.AggregationType(strings.ToTitle(azMetricRequest.Aggregation)))
err := fmt.Errorf("got metric result for %s/%s and aggregate type %s without timeseries", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, insights.AggregationType(strings.ToTitle(azMetricRequest.Aggregation)))
return -1, err
}

dataPtr := (*timeseriesPtr)[0].Data
if dataPtr == nil || len(*dataPtr) == 0 {
err := fmt.Errorf("Got metric result for %s/%s and aggregate type %s without any metric values", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, insights.AggregationType(strings.ToTitle(azMetricRequest.Aggregation)))
err := fmt.Errorf("got metric result for %s/%s and aggregate type %s without any metric values", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, insights.AggregationType(strings.ToTitle(azMetricRequest.Aggregation)))
return -1, err
}

valuePtr, err := verifyAggregationTypeIsSupported(azMetricRequest.Aggregation, *dataPtr)
if err != nil {
return -1, fmt.Errorf("Unable to get value for metric %s/%s with aggregation %s. No value returned by Azure Monitor", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, azMetricRequest.Aggregation)
return -1, fmt.Errorf("unable to get value for metric %s/%s with aggregation %s. No value returned by Azure Monitor", azMetricRequest.ResourceProviderNamespace, azMetricRequest.MetricName, azMetricRequest.Aggregation)
}

klog.V(2).Infof("metric type: %s %f", azMetricRequest.Aggregation, *valuePtr)
Expand Down Expand Up @@ -195,7 +195,7 @@ func formatTimeSpan(timeSpan string) (string, error) {
seconds, serr := strconv.Atoi(aggregationInterval[2])

if herr != nil || merr != nil || serr != nil {
return "", fmt.Errorf("Errors parsing metricAggregationInterval: %v, %v, %v", herr, merr, serr)
return "", fmt.Errorf("errors parsing metricAggregationInterval: %v, %v, %v", herr, merr, serr)
}

starttime = time.Now().Add(-(time.Duration(hours)*time.Hour + time.Duration(minutes)*time.Minute + time.Duration(seconds)*time.Second)).UTC().Format(time.RFC3339)
Expand All @@ -216,7 +216,7 @@ func verifyAggregationTypeIsSupported(aggregationType string, data []insights.Me
} else if strings.EqualFold(string(insights.Count), aggregationType) && data[len(data)-1].Count != nil {
valuePtr = data[len(data)-1].Count
} else {
err := fmt.Errorf("Unsupported aggregation type %s", insights.AggregationType(strings.ToTitle(aggregationType)))
err := fmt.Errorf("unsupported aggregation type %s", insights.AggregationType(strings.ToTitle(aggregationType)))
return nil, err
}
return valuePtr, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/scalers/azure_blob_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type azureBlobMetadata struct {
blobDelimiter string
blobPrefix string
connection string
useAAdPodIdentity bool
accountName string
}

Expand Down Expand Up @@ -64,7 +63,7 @@ func parseAzureBlobMetadata(metadata, resolvedEnv, authParams map[string]string,
blobCount, err := strconv.Atoi(val)
if err != nil {
azureBlobLog.Error(err, "Error parsing azure blob metadata", "blobCountMetricName", blobCountMetricName)
return nil, "", fmt.Errorf("Error parsing azure blob metadata %s: %s", blobCountMetricName, err.Error())
return nil, "", fmt.Errorf("error parsing azure blob metadata %s: %s", blobCountMetricName, err.Error())
}

meta.targetBlobCount = blobCount
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/azure_eventhub_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func parseAzureEventHubMetadata(metadata, resolvedEnv, authParams map[string]str
if val, ok := metadata[thresholdMetricName]; ok {
threshold, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing azure eventhub metadata %s: %s", thresholdMetricName, err)
return nil, fmt.Errorf("error parsing azure eventhub metadata %s: %s", thresholdMetricName, err)
}

meta.threshold = threshold
Expand Down
Loading

0 comments on commit c498970

Please sign in to comment.