Skip to content

Commit

Permalink
use vendor packages to generate mocks (#3520)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik authored Aug 8, 2022
1 parent cdba613 commit 7a0b37b
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 55 deletions.
2 changes: 1 addition & 1 deletion controllers/keda/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func initScaleClient(mgr manager.Manager, clientset *discovery.DiscoveryClient)
)
}

// Reconcile performs reconciliation on the identified ScaledObject resource based on the request information passed, returns the result and an error (if any).
// Reconcile performs reconciliation on the identified ScaledObject resource based on the request information passed, returns the result and an error (if any).
func (r *ScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
reqLogger := log.FromContext(ctx)

Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/azure/azure_aad_podidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -42,7 +42,7 @@ func GetAzureADPodIdentityToken(ctx context.Context, httpClient util.HTTPDoer, i
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return token, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/azure_log_analytics_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -625,7 +625,7 @@ func (s *azureLogAnalyticsScaler) runHTTP(request *http.Request, caller string)
defer resp.Body.Close()
s.httpClient.CloseIdleConnections()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, resp.StatusCode, fmt.Errorf("error reading %s response body: Inner Error: %v", caller, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/azure_pipelines_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -210,7 +210,7 @@ func getAzurePipelineRequest(ctx context.Context, url string, metadata *azurePip
return []byte{}, err
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return []byte{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/elasticsearch_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *elasticsearchScaler) getQueryResult(ctx context.Context) (float64, erro
}

defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/graphite_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
url_pkg "net/url"
"strconv"
Expand Down Expand Up @@ -191,7 +191,7 @@ func (s *graphiteScaler) executeGrapQuery(ctx context.Context) (float64, error)
return -1, err
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return -1, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/ibmmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -200,7 +200,7 @@ func (s *IBMMQScaler) getQueueDepthViaHTTP(ctx context.Context) (int64, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return 0, fmt.Errorf("failed to ready body of request: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/metrics_api_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
neturl "net/url"
"strconv"
Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *metricsAPIScaler) getMetricValue(ctx context.Context) (float64, error)
return 0, errors.New(msg)
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return 0, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/scalers/openstack/keystone_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -289,7 +289,7 @@ func (keystone *KeystoneAuthRequest) getToken(ctx context.Context) (string, erro
return resp.Header["X-Subject-Token"][0], nil
}

errBody, err := ioutil.ReadAll(resp.Body)
errBody, err := io.ReadAll(resp.Body)

if err != nil {
return "", err
Expand Down Expand Up @@ -338,7 +338,7 @@ func (keystone *KeystoneAuthRequest) getCatalog(ctx context.Context, token strin
return keystoneCatalog.Catalog, nil
}

errBody, err := ioutil.ReadAll(resp.Body)
errBody, err := io.ReadAll(resp.Body)

if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/scalers/openstack_metrics_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -331,7 +331,7 @@ func (s *openstackMetricScaler) readOpenstackMetrics(ctx context.Context) (float

defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyError, readError := ioutil.ReadAll(resp.Body)
bodyError, readError := io.ReadAll(resp.Body)

if readError != nil {
s.logger.Error(readError, "Request failed with code: %s for URL: %s", resp.StatusCode, s.metadata.metricsURL)
Expand All @@ -342,7 +342,7 @@ func (s *openstackMetricScaler) readOpenstackMetrics(ctx context.Context) (float
}

m := measureResult{}
body, errConvertJSON := ioutil.ReadAll(resp.Body)
body, errConvertJSON := io.ReadAll(resp.Body)

if errConvertJSON != nil {
s.logger.Error(errConvertJSON, "Failed to convert Body format response to json")
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/openstack_swift_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scalers
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *openstackSwiftScaler) getOpenstackSwiftContainerObjectCount(ctx context

defer resp.Body.Close()

body, readError := ioutil.ReadAll(resp.Body)
body, readError := io.ReadAll(resp.Body)

if readError != nil {
s.logger.Error(readError, "could not read response body from Swift API")
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/prometheus_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
url_pkg "net/url"
"strconv"
Expand Down Expand Up @@ -235,7 +235,7 @@ func (s *prometheusScaler) ExecutePromQuery(ctx context.Context) (float64, error
return -1, err
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return -1, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/pulsar_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -211,7 +211,7 @@ func (s *pulsarScaler) GetStats(ctx context.Context) (*pulsarStats, error) {

switch res.StatusCode {
case 200:
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("error requesting stats from url: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/rabbitmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -443,7 +443,7 @@ func getJSON(s *rabbitMQScaler, url string) (queueInfo, error) {
return result, err
}

body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
return result, fmt.Errorf("error requesting rabbitMQ API status: %s, response: %s, from: %s", r.Status, body, url)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"strconv"
Expand Down Expand Up @@ -210,7 +210,7 @@ func (s *seleniumGridScaler) getSessionsCount(ctx context.Context, logger logr.L
}

defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return -1, err
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/scalers/solace_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type solaceSEMPMetadata struct {
ResponseCode int `json:"responseCode"`
}

// Constructor for SolaceScaler
// Constructor for SolaceScaler
func NewSolaceScaler(config *ScalerConfig) (Scaler, error) {
// Create HTTP Client
httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout, false)
Expand All @@ -139,7 +139,7 @@ func NewSolaceScaler(config *ScalerConfig) (Scaler, error) {
}, nil
}

// Called by constructor
// Called by constructor
func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) {
meta := SolaceMetadata{}
// GET THE SEMP API ENDPOINT
Expand Down Expand Up @@ -263,14 +263,14 @@ func getSolaceSempCredentials(config *ScalerConfig) (u string, p string, err err
return u, p, nil
}

// INTERFACE METHOD
// DEFINE METRIC FOR SCALING
// CURRENT SUPPORTED METRICS ARE:
// - QUEUE MESSAGE COUNT (msgCount)
// - QUEUE SPOOL USAGE (msgSpoolUsage in MBytes)
// METRIC IDENTIFIER HAS THE SIGNATURE:
// - solace-[Queue_Name]-[metric_type]
// e.g. solace-QUEUE1-msgCount
// INTERFACE METHOD
// DEFINE METRIC FOR SCALING
// CURRENT SUPPORTED METRICS ARE:
// - QUEUE MESSAGE COUNT (msgCount)
// - QUEUE SPOOL USAGE (msgSpoolUsage in MBytes)
// METRIC IDENTIFIER HAS THE SIGNATURE:
// - solace-[Queue_Name]-[metric_type]
// e.g. solace-QUEUE1-msgCount
func (s *SolaceScaler) GetMetricSpecForScaling(context.Context) []v2beta2.MetricSpec {
var metricSpecList []v2beta2.MetricSpec
// Message Count Target Spec
Expand Down Expand Up @@ -300,7 +300,7 @@ func (s *SolaceScaler) GetMetricSpecForScaling(context.Context) []v2beta2.Metric
return metricSpecList
}

// returns SolaceMetricValues struct populated from broker SEMP endpoint
// returns SolaceMetricValues struct populated from broker SEMP endpoint
func (s *SolaceScaler) getSolaceQueueMetricsFromSEMP(ctx context.Context) (SolaceMetricValues, error) {
var scaledMetricEndpointURL = s.metadata.endpointURL
var httpClient = s.httpClient
Expand Down Expand Up @@ -345,9 +345,9 @@ func (s *SolaceScaler) getSolaceQueueMetricsFromSEMP(ctx context.Context) (Solac
return metricValues, nil
}

// INTERFACE METHOD
// Call SEMP API to retrieve metrics
// returns value for named metric
// INTERFACE METHOD
// Call SEMP API to retrieve metrics
// returns value for named metric
func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metricSelector labels.Selector) ([]external_metrics.ExternalMetricValue, error) {
var metricValues, mv SolaceMetricValues
var mve error
Expand All @@ -372,9 +372,9 @@ func (s *SolaceScaler) GetMetrics(ctx context.Context, metricName string, metric
return append([]external_metrics.ExternalMetricValue{}, metric), nil
}

// INTERFACE METHOD
// Call SEMP API to retrieve metrics
// IsActive returns true if queue messageCount > 0 || msgSpoolUsage > 0
// INTERFACE METHOD
// Call SEMP API to retrieve metrics
// IsActive returns true if queue messageCount > 0 || msgSpoolUsage > 0
func (s *SolaceScaler) IsActive(ctx context.Context) (bool, error) {
metricValues, err := s.getSolaceQueueMetricsFromSEMP(ctx)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/scaling/resolver/hashicorpvault_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package resolver
import (
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/go-logr/logr"
vaultapi "github.com/hashicorp/vault/api"
Expand Down Expand Up @@ -112,7 +112,7 @@ func (vh *HashicorpVaultHandler) token(client *vaultapi.Client) (string, error)
}

// Get the JWT from POD
jwt, err := ioutil.ReadFile(vh.vault.Credential.ServiceAccount)
jwt, err := os.ReadFile(vh.vault.Credential.ServiceAccount)
if err != nil {
return token, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/scaling/resolver/scale_resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -250,7 +249,7 @@ func getClusterObjectNamespace() (string, error) {
clusterObjectNamespaceCache = &env
return env, nil
}
data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 7a0b37b

Please sign in to comment.