diff --git a/CHANGELOG.md b/CHANGELOG.md index d056c2ae4b9..b6f3ef1a46b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio ## History - [Unreleased](#unreleased) +- [v2.11.2](#v2110) +- [v2.11.1](#v2110) - [v2.11.0](#v2110) - [v2.10.1](#v2101) - [v2.10.0](#v2100) @@ -55,9 +57,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio ### Fixes -- **General**: Paused ScaledObject continues working after removing the annotation ([#4733](https://github.com/kedacore/keda/issues/4733)) -- **General**: Skip resolving secrets if namespace is restricted ([#4519](https://github.com/kedacore/keda/issues/4519)) -- **Prometheus**: Authenticated connections to Prometheus work in non-PodIdenty case ([#4695](https://github.com/kedacore/keda/issues/4695)) +- TODO ([#XXX](https://github.com/kedacore/keda/issue/XXX)) ### Deprecations @@ -75,6 +75,32 @@ New deprecation(s): - TODO ([#XXX](https://github.com/kedacore/keda/issue/XXX)) +## v2.11.2 + +### Fixes + +- **General**: Metrics server exposes Prometheus metrics ([#4776](https://github.com/kedacore/keda/issues/4776)) +- **AWS Pod Identity Authentication**: Use `default` service account if the workload doesn't set it ([#4767](https://github.com/kedacore/keda/issues/4767)) +- **GitHub Runner Scaler**: Fix rate checking on GHEC when HTTP 200 ([#4786](https://github.com/kedacore/keda/issues/4786)) +- **GitHub Runner Scaler**: Fix explicit repo check 404 to skip not crash ([#4790](https://github.com/kedacore/keda/issues/4790)) +- **Pulsar Scaler**: Fix `msgBacklogThreshold` field being named wrongly as `msgBacklog` ([#4681](https://github.com/kedacore/keda/issues/4681)) + +### Deprecations + +You can find all deprecations in [this overview](https://github.com/kedacore/keda/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abreaking-change) and [join the discussion here](https://github.com/kedacore/keda/discussions/categories/deprecations). + +New deprecation(s): + +- **Pulsar Scaler**: Fix `msgBacklogThreshold` field being named wrongly as `msgBacklog` ([#4681](https://github.com/kedacore/keda/issues/4681)) + +## v2.11.1 + +### Fixes + +- **General**: Paused ScaledObject continues working after removing the annotation ([#4733](https://github.com/kedacore/keda/issues/4733)) +- **General**: Skip resolving secrets if namespace is restricted ([#4519](https://github.com/kedacore/keda/issues/4519)) +- **Prometheus**: Authenticated connections to Prometheus work in non-PodIdenty case ([#4695](https://github.com/kedacore/keda/issues/4695)) + ## v2.11.0 ### New diff --git a/cmd/adapter/main.go b/cmd/adapter/main.go index 5219f473ea9..6c2cde02825 100644 --- a/cmd/adapter/main.go +++ b/cmd/adapter/main.go @@ -21,15 +21,9 @@ import ( "flag" "fmt" "os" - "time" appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/wait" - kubeinformers "k8s.io/client-go/informers" - "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/tools/record" "k8s.io/klog/v2" "k8s.io/klog/v2/klogr" ctrl "sigs.k8s.io/controller-runtime" @@ -40,7 +34,6 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/metricsservice" kedaprovider "github.com/kedacore/keda/v2/pkg/provider" - "github.com/kedacore/keda/v2/pkg/scaling" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -62,44 +55,44 @@ var ( metricsServiceAddr string ) -func (a *Adapter) makeProvider(ctx context.Context, globalHTTPTimeout time.Duration) (provider.ExternalMetricsProvider, error) { +func (a *Adapter) makeProvider(ctx context.Context) (provider.ExternalMetricsProvider, <-chan struct{}, error) { scheme := scheme.Scheme if err := appsv1.SchemeBuilder.AddToScheme(scheme); err != nil { logger.Error(err, "failed to add apps/v1 scheme to runtime scheme") - return nil, fmt.Errorf("failed to add apps/v1 scheme to runtime scheme (%s)", err) + return nil, nil, fmt.Errorf("failed to add apps/v1 scheme to runtime scheme (%s)", err) } if err := kedav1alpha1.SchemeBuilder.AddToScheme(scheme); err != nil { logger.Error(err, "failed to add keda scheme to runtime scheme") - return nil, fmt.Errorf("failed to add keda scheme to runtime scheme (%s)", err) + return nil, nil, fmt.Errorf("failed to add keda scheme to runtime scheme (%s)", err) } namespace, err := getWatchNamespace() if err != nil { logger.Error(err, "failed to get watch namespace") - return nil, fmt.Errorf("failed to get watch namespace (%s)", err) + return nil, nil, fmt.Errorf("failed to get watch namespace (%s)", err) } leaseDuration, err := kedautil.ResolveOsEnvDuration("KEDA_METRICS_LEADER_ELECTION_LEASE_DURATION") if err != nil { logger.Error(err, "invalid KEDA_METRICS_LEADER_ELECTION_LEASE_DURATION") - return nil, fmt.Errorf("invalid KEDA_METRICS_LEADER_ELECTION_LEASE_DURATION (%s)", err) + return nil, nil, fmt.Errorf("invalid KEDA_METRICS_LEADER_ELECTION_LEASE_DURATION (%s)", err) } renewDeadline, err := kedautil.ResolveOsEnvDuration("KEDA_METRICS_LEADER_ELECTION_RENEW_DEADLINE") if err != nil { logger.Error(err, "Invalid KEDA_METRICS_LEADER_ELECTION_RENEW_DEADLINE") - return nil, fmt.Errorf("invalid KEDA_METRICS_LEADER_ELECTION_RENEW_DEADLINE (%s)", err) + return nil, nil, fmt.Errorf("invalid KEDA_METRICS_LEADER_ELECTION_RENEW_DEADLINE (%s)", err) } retryPeriod, err := kedautil.ResolveOsEnvDuration("KEDA_METRICS_LEADER_ELECTION_RETRY_PERIOD") if err != nil { logger.Error(err, "Invalid KEDA_METRICS_LEADER_ELECTION_RETRY_PERIOD") - return nil, fmt.Errorf("invalid KEDA_METRICS_LEADER_ELECTION_RETRY_PERIOD (%s)", err) + return nil, nil, fmt.Errorf("invalid KEDA_METRICS_LEADER_ELECTION_RETRY_PERIOD (%s)", err) } useMetricsServiceGrpc, err := kedautil.ResolveOsEnvBool("KEDA_USE_METRICS_SERVICE_GRPC", true) if err != nil { logger.Error(err, "Invalid KEDA_USE_METRICS_SERVICE_GRPC") - return nil, fmt.Errorf("invalid KEDA_USE_METRICS_SERVICE_GRPC (%s)", err) + return nil, nil, fmt.Errorf("invalid KEDA_USE_METRICS_SERVICE_GRPC (%s)", err) } // Get a config to talk to the apiserver @@ -121,38 +114,24 @@ func (a *Adapter) makeProvider(ctx context.Context, globalHTTPTimeout time.Durat }) if err != nil { logger.Error(err, "failed to setup manager") - return nil, err + return nil, nil, err } - broadcaster := record.NewBroadcaster() - recorder := broadcaster.NewRecorder(scheme, corev1.EventSource{Component: "keda-metrics-adapter"}) - - kubeClientset, err := kubernetes.NewForConfig(cfg) - if err != nil { - logger.Error(err, "Unable to create kube clientset") - return nil, err - } - objectNamespace, err := kedautil.GetClusterObjectNamespace() - if err != nil { - logger.Error(err, "Unable to get cluster object namespace") - return nil, err - } - // the namespaced kubeInformerFactory is used to restrict secret informer to only list/watch secrets in KEDA cluster object namespace, - // refer to https://github.com/kedacore/keda/issues/3668 - kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClientset, 1*time.Hour, kubeinformers.WithNamespace(objectNamespace)) - secretInformer := kubeInformerFactory.Core().V1().Secrets() - - handler := scaling.NewScaleHandler(mgr.GetClient(), nil, scheme, globalHTTPTimeout, recorder, secretInformer.Lister()) - kubeInformerFactory.Start(ctx.Done()) - logger.Info("Connecting Metrics Service gRPC client to the server", "address", metricsServiceAddr) grpcClient, err := metricsservice.NewGrpcClient(metricsServiceAddr, a.SecureServing.ServerCert.CertDirectory) if err != nil { logger.Error(err, "error connecting Metrics Service gRPC client to the server", "address", metricsServiceAddr) - return nil, err - } - - return kedaprovider.NewProvider(ctx, logger, handler, mgr.GetClient(), *grpcClient, useMetricsServiceGrpc, namespace), nil + return nil, nil, err + } + stopCh := make(chan struct{}) + go func() { + if err := mgr.Start(ctx); err != nil { + logger.Error(err, "controller-runtime encountered an error") + stopCh <- struct{}{} + close(stopCh) + } + }() + return kedaprovider.NewProvider(ctx, logger, mgr.GetClient(), *grpcClient, useMetricsServiceGrpc, namespace), stopCh, nil } // generateDefaultMetricsServiceAddr generates default Metrics Service gRPC Server address based on the current Namespace. @@ -217,19 +196,12 @@ func main() { ctrl.SetLogger(logger) - // default to 3 seconds if they don't pass the env var - globalHTTPTimeoutMS, err := kedautil.ResolveOsEnvInt("KEDA_HTTP_DEFAULT_TIMEOUT", 3000) - if err != nil { - logger.Error(err, "Invalid KEDA_HTTP_DEFAULT_TIMEOUT") - return - } - err = printWelcomeMsg(cmd) if err != nil { return } - kedaProvider, err := cmd.makeProvider(ctx, time.Duration(globalHTTPTimeoutMS)*time.Millisecond) + kedaProvider, stopCh, err := cmd.makeProvider(ctx) if err != nil { logger.Error(err, "making provider") return @@ -237,7 +209,7 @@ func main() { cmd.WithExternalMetrics(kedaProvider) logger.Info(cmd.Message) - if err = cmd.Run(wait.NeverStop); err != nil { + if err = cmd.Run(stopCh); err != nil { return } } diff --git a/config/metrics-server/service.yaml b/config/metrics-server/service.yaml index e1281b12bae..ffa713d6f29 100644 --- a/config/metrics-server/service.yaml +++ b/config/metrics-server/service.yaml @@ -13,8 +13,8 @@ spec: - name: https port: 443 targetPort: 6443 - - name: http - port: 80 + - name: metrics + port: 8080 targetPort: 8080 selector: app: keda-metrics-apiserver diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 410a5cfc1fc..0bae4e9c22d 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -29,7 +29,6 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/metricsservice" - "github.com/kedacore/keda/v2/pkg/scaling" ) // KedaProvider implements External Metrics Provider @@ -37,7 +36,6 @@ type KedaProvider struct { defaults.DefaultExternalMetricsProvider client client.Client - scaleHandler scaling.ScaleHandler watchedNamespace string ctx context.Context @@ -52,10 +50,9 @@ var ( ) // NewProvider returns an instance of KedaProvider -func NewProvider(ctx context.Context, adapterLogger logr.Logger, scaleHandler scaling.ScaleHandler, client client.Client, grpcClient metricsservice.GrpcClient, useMetricsServiceGrpc bool, watchedNamespace string) provider.ExternalMetricsProvider { +func NewProvider(ctx context.Context, adapterLogger logr.Logger, client client.Client, grpcClient metricsservice.GrpcClient, useMetricsServiceGrpc bool, watchedNamespace string) provider.ExternalMetricsProvider { provider := &KedaProvider{ client: client, - scaleHandler: scaleHandler, watchedNamespace: watchedNamespace, ctx: ctx, grpcClient: grpcClient, diff --git a/pkg/scalers/authentication/authentication_types.go b/pkg/scalers/authentication/authentication_types.go index d6484dce233..34d009995f0 100644 --- a/pkg/scalers/authentication/authentication_types.go +++ b/pkg/scalers/authentication/authentication_types.go @@ -6,15 +6,15 @@ import "time" type Type string const ( - // APIKeyAuthType is a auth type using an API key + // APIKeyAuthType is an auth type using an API key APIKeyAuthType Type = "apiKey" - // BasicAuthType is a auth type using basic auth + // BasicAuthType is an auth type using basic auth BasicAuthType Type = "basic" - // TLSAuthType is a auth type using TLS + // TLSAuthType is an auth type using TLS TLSAuthType Type = "tls" - // BearerAuthType is a auth type using a bearer token + // BearerAuthType is an auth type using a bearer token BearerAuthType Type = "bearer" - // CustomAuthType is a auth type using a custom header + // CustomAuthType is an auth type using a custom header CustomAuthType Type = "custom" ) diff --git a/pkg/scalers/github_runner_scaler.go b/pkg/scalers/github_runner_scaler.go index a310f2481d7..943790b14bb 100644 --- a/pkg/scalers/github_runner_scaler.go +++ b/pkg/scalers/github_runner_scaler.go @@ -479,7 +479,7 @@ func (s *githubRunnerScaler) getRepositories(ctx context.Context) ([]string, err default: return nil, fmt.Errorf("runnerScope %s not supported", s.metadata.runnerScope) } - body, err := getGithubRequest(ctx, url, s.metadata, s.httpClient) + body, _, err := getGithubRequest(ctx, url, s.metadata, s.httpClient) if err != nil { return nil, err } @@ -498,10 +498,10 @@ func (s *githubRunnerScaler) getRepositories(ctx context.Context) ([]string, err return repoList, nil } -func getGithubRequest(ctx context.Context, url string, metadata *githubRunnerMetadata, httpClient *http.Client) ([]byte, error) { +func getGithubRequest(ctx context.Context, url string, metadata *githubRunnerMetadata, httpClient *http.Client) ([]byte, int, error) { req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { - return []byte{}, err + return []byte{}, -1, err } req.Header.Set("Accept", "application/vnd.github.v3+json") @@ -513,27 +513,29 @@ func getGithubRequest(ctx context.Context, url string, metadata *githubRunnerMet r, err := httpClient.Do(req) if err != nil { - return []byte{}, err + return []byte{}, -1, err } b, err := io.ReadAll(r.Body) if err != nil { - return []byte{}, err + return []byte{}, -1, err } _ = r.Body.Close() - if r.StatusCode != 200 || r.Header.Get("X-RateLimit-Remaining") == "" { - return []byte{}, fmt.Errorf("the GitHub REST API returned error. url: %s status: %d response: %s", url, r.StatusCode, string(b)) - } + if r.StatusCode != 200 { + if r.Header.Get("X-RateLimit-Remaining") != "" { + githubAPIRemaining, _ := strconv.Atoi(r.Header.Get("X-RateLimit-Remaining")) - githubAPIRemaining, _ := strconv.Atoi(r.Header.Get("X-RateLimit-Remaining")) + if githubAPIRemaining == 0 { + resetTime, _ := strconv.ParseInt(r.Header.Get("X-RateLimit-Reset"), 10, 64) + return []byte{}, r.StatusCode, fmt.Errorf("GitHub API rate limit exceeded, resets at %s", time.Unix(resetTime, 0)) + } + } - if githubAPIRemaining == 0 { - resetTime, _ := strconv.ParseInt(r.Header.Get("X-RateLimit-Reset"), 10, 64) - return []byte{}, fmt.Errorf("GitHub API rate limit exceeded, resets at %s", time.Unix(resetTime, 0)) + return []byte{}, r.StatusCode, fmt.Errorf("the GitHub REST API returned error. url: %s status: %d response: %s", url, r.StatusCode, string(b)) } - return b, nil + return b, r.StatusCode, nil } func stripDeadRuns(allWfrs []WorkflowRuns) []WorkflowRun { @@ -551,7 +553,7 @@ func stripDeadRuns(allWfrs []WorkflowRuns) []WorkflowRun { // getWorkflowRunJobs returns a list of jobs for a given workflow run func (s *githubRunnerScaler) getWorkflowRunJobs(ctx context.Context, workflowRunID int64, repoName string) ([]Job, error) { url := fmt.Sprintf("%s/repos/%s/%s/actions/runs/%d/jobs", s.metadata.githubAPIURL, s.metadata.owner, repoName, workflowRunID) - body, err := getGithubRequest(ctx, url, s.metadata, s.httpClient) + body, _, err := getGithubRequest(ctx, url, s.metadata, s.httpClient) if err != nil { return nil, err } @@ -568,8 +570,10 @@ func (s *githubRunnerScaler) getWorkflowRunJobs(ctx context.Context, workflowRun // getWorkflowRuns returns a list of workflow runs for a given repository func (s *githubRunnerScaler) getWorkflowRuns(ctx context.Context, repoName string) (*WorkflowRuns, error) { url := fmt.Sprintf("%s/repos/%s/%s/actions/runs", s.metadata.githubAPIURL, s.metadata.owner, repoName) - body, err := getGithubRequest(ctx, url, s.metadata, s.httpClient) - if err != nil { + body, statusCode, err := getGithubRequest(ctx, url, s.metadata, s.httpClient) + if err != nil && statusCode == 404 { + return nil, nil + } else if err != nil { return nil, err } @@ -618,7 +622,9 @@ func (s *githubRunnerScaler) GetWorkflowQueueLength(ctx context.Context) (int64, if err != nil { return -1, err } - allWfrs = append(allWfrs, *wfrs) + if wfrs != nil { + allWfrs = append(allWfrs, *wfrs) + } } var queueCount int64 diff --git a/pkg/scalers/github_runner_scaler_test.go b/pkg/scalers/github_runner_scaler_test.go index 9efc428829f..d09b1f79ed5 100644 --- a/pkg/scalers/github_runner_scaler_test.go +++ b/pkg/scalers/github_runner_scaler_test.go @@ -28,7 +28,7 @@ type parseGitHubRunnerMetadataTestData struct { var testGitHubRunnerResolvedEnv = map[string]string{ "GITHUB_API_URL": "https://api.github.com", "ACCESS_TOKEN": "sample", - "RUNNER_SCOPE": "org", + "RUNNER_SCOPE": ORG, "ORG_NAME": "ownername", "OWNER": "ownername", "LABELS": "foo,bar", @@ -49,11 +49,11 @@ var testGitHubRunnerMetadata = []parseGitHubRunnerMetadataTestData{ // nothing passed {"empty", map[string]string{}, true, true, "no runnerScope given"}, // properly formed - {"properly formed", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, true, false, ""}, + {"properly formed", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, true, false, ""}, // properly formed with no labels and no repos - {"properly formed, no labels or repos", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "owner": "ownername", "targetWorkflowQueueLength": "1"}, true, false, ""}, + {"properly formed, no labels or repos", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "owner": "ownername", "targetWorkflowQueueLength": "1"}, true, false, ""}, // string for int64 - {"string for int64-1", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "owner": "ownername", "targetWorkflowQueueLength": "a"}, true, false, ""}, + {"string for int64-1", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "owner": "ownername", "targetWorkflowQueueLength": "a"}, true, false, ""}, // formed from env {"formed from env", map[string]string{"githubApiURLFromEnv": "GITHUB_API_URL", "runnerScopeFromEnv": "RUNNER_SCOPE", "ownerFromEnv": "OWNER", "reposFromEnv": "REPOS", "targetWorkflowQueueLength": "1"}, true, false, ""}, // missing runnerScope @@ -61,23 +61,23 @@ var testGitHubRunnerMetadata = []parseGitHubRunnerMetadataTestData{ // empty runnerScope {"empty runnerScope", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, true, true, "no runnerScope given"}, // missing owner - {"missing owner", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "repos": "reponame", "targetWorkflowQueueLength": "1"}, true, true, "no owner given"}, + {"missing owner", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "repos": "reponame", "targetWorkflowQueueLength": "1"}, true, true, "no owner given"}, // empty owner - {"empty owner", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "owner": "", "repos": "reponame", "targetWorkflowQueueLength": "1"}, true, true, "no owner given"}, + {"empty owner", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "owner": "", "repos": "reponame", "targetWorkflowQueueLength": "1"}, true, true, "no owner given"}, // empty token - {"empty targetWorkflowQueueLength", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "owner": "ownername", "repos": "reponame"}, true, false, ""}, + {"empty targetWorkflowQueueLength", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "owner": "ownername", "repos": "reponame"}, true, false, ""}, // missing installationID From Env - {"missing installationID Env", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "applicationIDFromEnv": "APP_ID"}, true, true, "applicationID, installationID and applicationKey must be given"}, + {"missing installationID Env", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "applicationIDFromEnv": "APP_ID"}, true, true, "applicationID, installationID and applicationKey must be given"}, // missing applicationID From Env - {"missing applicationId Env", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "installationIDFromEnv": "INST_ID"}, true, true, "applicationID, installationID and applicationKey must be given"}, + {"missing applicationId Env", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "installationIDFromEnv": "INST_ID"}, true, true, "applicationID, installationID and applicationKey must be given"}, // nothing passed {"empty, no envs", map[string]string{}, false, true, "no runnerScope given"}, // empty githubApiURL - {"empty githubApiURL, no envs", map[string]string{"githubApiURL": "", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"empty githubApiURL, no envs", map[string]string{"githubApiURL": "", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, false, ""}, // properly formed - {"properly formed, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"properly formed, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, false, ""}, // properly formed with no labels and no repos - {"properly formed, no envs, labels or repos", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "ent", "owner": "ownername", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"properly formed, no envs, labels or repos", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ENT, "owner": "ownername", "targetWorkflowQueueLength": "1"}, false, false, ""}, // formed from env {"formed from env, no envs", map[string]string{"githubApiURLFromEnv": "GITHUB_API_URL", "ownerFromEnv": "OWNER", "repos": "reponame", "targetWorkflowQueueLength": "1"}, false, true, "no runnerScope given"}, // formed from default env @@ -87,23 +87,23 @@ var testGitHubRunnerMetadata = []parseGitHubRunnerMetadataTestData{ // empty runnerScope {"empty runnerScope, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, true, "no runnerScope given"}, // empty owner - {"empty owner, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "owner": "", "repos": "reponame", "targetWorkflowQueueLength": "1"}, false, true, "no owner given"}, + {"empty owner, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "owner": "", "repos": "reponame", "targetWorkflowQueueLength": "1"}, false, true, "no owner given"}, // missing owner - {"missing owner, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "repo", "repos": "reponame", "targetWorkflowQueueLength": "1"}, false, true, "no owner given"}, + {"missing owner, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": REPO, "repos": "reponame", "targetWorkflowQueueLength": "1"}, false, true, "no owner given"}, // missing labels, no envs - {"missing labels, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"missing labels, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "targetWorkflowQueueLength": "1"}, false, false, ""}, // empty labels, no envs - {"empty labels, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "labels": "", "repos": "reponame,otherrepo", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"empty labels, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "labels": "", "repos": "reponame,otherrepo", "targetWorkflowQueueLength": "1"}, false, false, ""}, // missing repos, no envs - {"missing repos, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"missing repos, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "labels": "golang", "targetWorkflowQueueLength": "1"}, false, false, ""}, // empty repos, no envs - {"empty repos, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "labels": "golang", "repos": "", "targetWorkflowQueueLength": "1"}, false, false, ""}, + {"empty repos, no envs", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "labels": "golang", "repos": "", "targetWorkflowQueueLength": "1"}, false, false, ""}, // missing installationID - {"missing installationID", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "applicationID": "1"}, true, true, "applicationID, installationID and applicationKey must be given"}, + {"missing installationID", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "applicationID": "1"}, true, true, "applicationID, installationID and applicationKey must be given"}, // missing applicationID - {"missing applicationID", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "installationID": "1"}, true, true, "applicationID, installationID and applicationKey must be given"}, + {"missing applicationID", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "installationID": "1"}, true, true, "applicationID, installationID and applicationKey must be given"}, // all good - {"missing applicationKey", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": "org", "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "applicationID": "1", "installationID": "1"}, true, true, "applicationID, installationID and applicationKey must be given"}, + {"missing applicationKey", map[string]string{"githubApiURL": "https://api.github.com", "runnerScope": ORG, "owner": "ownername", "repos": "reponame,otherrepo", "labels": "golang", "targetWorkflowQueueLength": "1", "applicationID": "1", "installationID": "1"}, true, true, "applicationID, installationID and applicationKey must be given"}, } func TestGitHubRunnerParseMetadata(t *testing.T) { @@ -133,7 +133,7 @@ func getGitHubTestMetaData(url string) *githubRunnerMetadata { meta := githubRunnerMetadata{ githubAPIURL: url, - runnerScope: "repo", + runnerScope: REPO, owner: "testOwner", personalAccessToken: &testpat, targetWorkflowQueueLength: 1, @@ -155,23 +155,30 @@ func buildQueueJSON() []byte { func apiStubHandler(hasRateLeft bool) *httptest.Server { return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + futureReset := time.Now() + futureReset = futureReset.Add(time.Minute * 30) + w.Header().Set("X-RateLimit-Reset", fmt.Sprint(futureReset.Unix())) if hasRateLeft { w.Header().Set("X-RateLimit-Remaining", "50") } else { w.Header().Set("X-RateLimit-Remaining", "0") + w.WriteHeader(http.StatusForbidden) } - futureReset := time.Now() - futureReset = futureReset.Add(time.Minute * 30) - w.Header().Set("X-RateLimit-Reset", fmt.Sprint(futureReset.Unix())) - w.WriteHeader(http.StatusOK) if strings.HasSuffix(r.URL.String(), "jobs") { _, _ = w.Write([]byte(testGhWFJobResponse)) + w.WriteHeader(http.StatusOK) } if strings.HasSuffix(r.URL.String(), "runs") { - _, _ = w.Write(buildQueueJSON()) + if strings.Contains(r.URL.String(), "BadRepo") { + w.WriteHeader(http.StatusNotFound) + } else { + _, _ = w.Write(buildQueueJSON()) + w.WriteHeader(http.StatusOK) + } } if strings.HasSuffix(r.URL.String(), "repos") { _, _ = w.Write([]byte(testGhUserReposResponse)) + w.WriteHeader(http.StatusOK) } })) } @@ -289,7 +296,6 @@ func TestNewGitHubRunnerScaler_404(t *testing.T) { httpClient: http.DefaultClient, } - mockGitHubRunnerScaler.metadata.repos = []string{"test"} mockGitHubRunnerScaler.metadata.labels = []string{"foo", "bar"} _, err := mockGitHubRunnerScaler.GetWorkflowQueueLength(context.TODO()) @@ -385,7 +391,35 @@ func TestNewGitHubRunnerScaler_QueueLength_MultiRepo_Assigned(t *testing.T) { tRepo := []string{"test", "test2"} mockGitHubRunnerScaler.metadata.repos = tRepo - mockGitHubRunnerScaler.metadata.runnerScope = "org" + mockGitHubRunnerScaler.metadata.runnerScope = ORG + mockGitHubRunnerScaler.metadata.labels = []string{"foo", "bar"} + + queueLen, err := mockGitHubRunnerScaler.GetWorkflowQueueLength(context.TODO()) + + if err != nil { + fmt.Println(err) + t.Fail() + } + + if queueLen != 2 { + fmt.Println(queueLen) + t.Fail() + } +} + +func TestNewGitHubRunnerScaler_QueueLength_MultiRepo_Assigned_OneBad(t *testing.T) { + var apiStub = apiStubHandler(true) + + meta := getGitHubTestMetaData(apiStub.URL) + + mockGitHubRunnerScaler := githubRunnerScaler{ + metadata: meta, + httpClient: http.DefaultClient, + } + + tRepo := []string{"test", "test2", "BadRepo"} + mockGitHubRunnerScaler.metadata.repos = tRepo + mockGitHubRunnerScaler.metadata.runnerScope = ORG mockGitHubRunnerScaler.metadata.labels = []string{"foo", "bar"} queueLen, err := mockGitHubRunnerScaler.GetWorkflowQueueLength(context.TODO()) @@ -435,7 +469,7 @@ func TestNewGitHubRunnerScaler_QueueLength_MultiRepo_PulledOrgRepos(t *testing.T httpClient: http.DefaultClient, } - mockGitHubRunnerScaler.metadata.runnerScope = "org" + mockGitHubRunnerScaler.metadata.runnerScope = ORG mockGitHubRunnerScaler.metadata.labels = []string{"foo", "bar"} queueLen, err := mockGitHubRunnerScaler.GetWorkflowQueueLength(context.TODO()) @@ -460,7 +494,7 @@ func TestNewGitHubRunnerScaler_QueueLength_MultiRepo_PulledEntRepos(t *testing.T httpClient: http.DefaultClient, } - mockGitHubRunnerScaler.metadata.runnerScope = "ent" + mockGitHubRunnerScaler.metadata.runnerScope = ENT mockGitHubRunnerScaler.metadata.labels = []string{"foo", "bar"} queueLen, err := mockGitHubRunnerScaler.GetWorkflowQueueLength(context.TODO()) diff --git a/pkg/scalers/pulsar_scaler.go b/pkg/scalers/pulsar_scaler.go index 498b36f6f33..511d61b6e1c 100644 --- a/pkg/scalers/pulsar_scaler.go +++ b/pkg/scalers/pulsar_scaler.go @@ -95,7 +95,8 @@ type pulsarStats struct { // NewPulsarScaler creates a new PulsarScaler func NewPulsarScaler(config *ScalerConfig) (Scaler, error) { - pulsarMetadata, err := parsePulsarMetadata(config) + logger := InitializeLogger(config, "pulsar_scaler") + pulsarMetadata, err := parsePulsarMetadata(config, logger) if err != nil { return nil, fmt.Errorf("error parsing pulsar metadata: %w", err) } @@ -125,11 +126,11 @@ func NewPulsarScaler(config *ScalerConfig) (Scaler, error) { return &pulsarScaler{ client: client, metadata: pulsarMetadata, - logger: InitializeLogger(config, "pulsar_scaler"), + logger: logger, }, nil } -func parsePulsarMetadata(config *ScalerConfig) (pulsarMetadata, error) { +func parsePulsarMetadata(config *ScalerConfig, logger logr.Logger) (pulsarMetadata, error) { meta := pulsarMetadata{} switch { case config.TriggerMetadata["adminURLFromEnv"] != "": @@ -178,13 +179,24 @@ func parsePulsarMetadata(config *ScalerConfig) (pulsarMetadata, error) { meta.msgBacklogThreshold = defaultMsgBacklogThreshold + // FIXME: msgBacklog support DEPRECATED to be removed in v2.14 + fmt.Println(config.TriggerMetadata) if val, ok := config.TriggerMetadata[msgBacklogMetricName]; ok { + logger.V(1).Info("\"msgBacklog\" is deprecated and will be removed in v2.14, please use \"msgBacklogThreshold\" instead") + t, err := strconv.ParseInt(val, 10, 64) + if err != nil { + return meta, fmt.Errorf("error parsing %s: %w", msgBacklogMetricName, err) + } + meta.msgBacklogThreshold = t + } else if val, ok := config.TriggerMetadata["msgBacklogThreshold"]; ok { t, err := strconv.ParseInt(val, 10, 64) if err != nil { return meta, fmt.Errorf("error parsing %s: %w", msgBacklogMetricName, err) } meta.msgBacklogThreshold = t } + // END FIXME + // For backwards compatibility, we need to map "tls: enable" to if tls, ok := config.TriggerMetadata["tls"]; ok { if tls == enable && (config.AuthParams["cert"] != "" || config.AuthParams["key"] != "") { diff --git a/pkg/scalers/pulsar_scaler_test.go b/pkg/scalers/pulsar_scaler_test.go index 549546ef795..beb8c700c33 100644 --- a/pkg/scalers/pulsar_scaler_test.go +++ b/pkg/scalers/pulsar_scaler_test.go @@ -3,6 +3,7 @@ package scalers import ( "context" "fmt" + "strconv" "strings" "testing" @@ -60,6 +61,12 @@ var parsePulsarMetadataTestDataset = []parsePulsarMetadataTestData{ {map[string]string{"adminURL": "http://127.0.0.1:8080", "topic": "persistent://public/default/my-topic", "subscription": "sub1"}, false, false, false, "http://127.0.0.1:8080", "persistent://public/default/my-topic", "sub1"}, {map[string]string{"adminURL": "http://127.0.0.1:8080", "topic": "persistent://public/default/my-topic", "subscription": "sub1"}, false, false, false, "http://127.0.0.1:8080", "persistent://public/default/my-topic", "sub1"}, {map[string]string{"adminURL": "http://127.0.0.1:8080", "topic": "persistent://public/default/my-topic", "isPartitionedTopic": "true", "subscription": "sub1"}, false, false, true, "http://127.0.0.1:8080", "persistent://public/default/my-topic", "sub1"}, + // test metric msgBacklogThreshold + {map[string]string{"adminURL": "http://127.0.0.1:8080", "topic": "persistent://public/default/my-topic", "isPartitionedTopic": "true", "subscription": "sub1", "msgBacklogThreshold": "5"}, false, false, true, "http://127.0.0.1:8080", "persistent://public/default/my-topic", "sub1"}, + // FIXME: msgBacklog support DEPRECATED to be removed in v2.14 + // test metric msgBacklog + {map[string]string{"adminURL": "http://127.0.0.1:8080", "topic": "persistent://public/default/my-topic", "isPartitionedTopic": "true", "subscription": "sub1", "msgBacklog": "5"}, false, false, true, "http://127.0.0.1:8080", "persistent://public/default/my-topic", "sub1"}, + // END FIXME // tls {map[string]string{"adminURL": "https://localhost:8443", "tls": "enable", "cert": "certdata", "key": "keydata", "ca": "cadata", "topic": "persistent://public/default/my-topic", "subscription": "sub1"}, false, true, false, "https://localhost:8443", "persistent://public/default/my-topic", "sub1"}, @@ -87,7 +94,8 @@ var pulsarMetricIdentifiers = []pulsarMetricIdentifier{ func TestParsePulsarMetadata(t *testing.T) { for _, testData := range parsePulsarMetadataTestDataset { - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}) + logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -120,12 +128,32 @@ func TestParsePulsarMetadata(t *testing.T) { t.Errorf("Expected subscription %s but got %s\n", testData.subscription, meta.subscription) } + var testDataMsgBacklogThreshold int64 + // FIXME: msgBacklog support DEPRECATED to be removed in v2.14 + if val, ok := testData.metadata["msgBacklog"]; ok { + testDataMsgBacklogThreshold, err = strconv.ParseInt(val, 10, 64) + if err != nil { + t.Errorf("error parseing msgBacklog: %v", err) + } + // END FiXME + } else if val, ok := testData.metadata["msgBacklogThreshold"]; ok { + testDataMsgBacklogThreshold, err = strconv.ParseInt(val, 10, 64) + if err != nil { + t.Errorf("error parseing msgBacklogThreshold: %v", err) + } + } else { + testDataMsgBacklogThreshold = defaultMsgBacklogThreshold + } + if meta.msgBacklogThreshold != testDataMsgBacklogThreshold && testDataMsgBacklogThreshold != defaultMsgBacklogThreshold { + t.Errorf("Expected msgBacklogThreshold %s but got %d\n", testData.metadata["msgBacklogThreshold"], meta.msgBacklogThreshold) + } + authParams := validPulsarWithoutAuthParams if k, ok := testData.metadata["tls"]; ok && k == "enable" { authParams = validPulsarWithAuthParams } - meta, err = parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: authParams}) + meta, err = parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: authParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -150,7 +178,8 @@ func TestParsePulsarMetadata(t *testing.T) { func TestPulsarAuthParams(t *testing.T) { for _, testData := range parsePulsarMetadataTestAuthTLSDataset { - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}) + logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", testData.authParams, err) @@ -204,7 +233,8 @@ func TestPulsarAuthParams(t *testing.T) { func TestPulsarGetMetricSpecForScaling(t *testing.T) { for _, testData := range pulsarMetricIdentifiers { - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}) + logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}, logger) if err != nil { if testData.metadataTestData.isError { continue diff --git a/pkg/scalers/scaler.go b/pkg/scalers/scaler.go index 6afb8ce4a39..71088572652 100644 --- a/pkg/scalers/scaler.go +++ b/pkg/scalers/scaler.go @@ -149,7 +149,7 @@ func InitializeLogger(config *ScalerConfig, scalerName string) logr.Logger { return logf.Log.WithName(scalerName).WithValues("type", config.ScalableObjectType, "namespace", config.ScalableObjectNamespace, "name", config.ScalableObjectName) } -// GetMetricTargetType helps getting the metric target type of the scaler +// GetMetricTargetType helps get the metric target type of the scaler func GetMetricTargetType(config *ScalerConfig) (v2.MetricTargetType, error) { switch config.MetricType { case v2.UtilizationMetricType: diff --git a/pkg/scaling/resolver/scale_resolvers.go b/pkg/scaling/resolver/scale_resolvers.go index d21a273c2ce..9d18eeb20c0 100644 --- a/pkg/scaling/resolver/scale_resolvers.go +++ b/pkg/scaling/resolver/scale_resolvers.go @@ -39,11 +39,12 @@ import ( ) const ( - referenceOperator = '$' - referenceOpener = '(' - referenceCloser = ')' - boolTrue = true - boolFalse = false + referenceOperator = '$' + referenceOpener = '(' + referenceCloser = ')' + boolTrue = true + boolFalse = false + defaultServiceAccount = "default" ) var ( @@ -181,7 +182,10 @@ func ResolveAuthRefAndPodIdentity(ctx context.Context, client client.Client, log authParams, podIdentity := resolveAuthRef(ctx, client, logger, triggerAuthRef, &podTemplateSpec.Spec, namespace, secretsLister) if podIdentity.Provider == kedav1alpha1.PodIdentityProviderAwsEKS { - serviceAccountName := podTemplateSpec.Spec.ServiceAccountName + serviceAccountName := defaultServiceAccount + if podTemplateSpec.Spec.ServiceAccountName != "" { + serviceAccountName = podTemplateSpec.Spec.ServiceAccountName + } serviceAccount := &corev1.ServiceAccount{} err := client.Get(ctx, types.NamespacedName{Name: serviceAccountName, Namespace: namespace}, serviceAccount) if err != nil { diff --git a/tests/scalers/aws/aws_cloudwatch_pod_identity/aws_cloudwatch_pod_identity_test.go b/tests/scalers/aws/aws_cloudwatch_pod_identity/aws_cloudwatch_pod_identity_test.go index 0a2c832cb99..14aaf920365 100644 --- a/tests/scalers/aws/aws_cloudwatch_pod_identity/aws_cloudwatch_pod_identity_test.go +++ b/tests/scalers/aws/aws_cloudwatch_pod_identity/aws_cloudwatch_pod_identity_test.go @@ -71,7 +71,6 @@ spec: labels: app: {{.DeploymentName}} spec: - serviceAccountName: default containers: - name: nginx image: nginxinc/nginx-unprivileged diff --git a/tests/scalers/aws/aws_dynamodb_pod_identity/aws_dynamodb_pod_identity_test.go b/tests/scalers/aws/aws_dynamodb_pod_identity/aws_dynamodb_pod_identity_test.go index 19cfdba5c89..c39d9bb223f 100644 --- a/tests/scalers/aws/aws_dynamodb_pod_identity/aws_dynamodb_pod_identity_test.go +++ b/tests/scalers/aws/aws_dynamodb_pod_identity/aws_dynamodb_pod_identity_test.go @@ -73,7 +73,6 @@ spec: labels: app: {{.DeploymentName}} spec: - serviceAccountName: default containers: - name: nginx image: nginxinc/nginx-unprivileged diff --git a/tests/scalers/aws/aws_dynamodb_streams_pod_identity/aws_dynamodb_streams_pod_identity_test.go b/tests/scalers/aws/aws_dynamodb_streams_pod_identity/aws_dynamodb_streams_pod_identity_test.go index 0c0547d34d5..de5dc1017d6 100644 --- a/tests/scalers/aws/aws_dynamodb_streams_pod_identity/aws_dynamodb_streams_pod_identity_test.go +++ b/tests/scalers/aws/aws_dynamodb_streams_pod_identity/aws_dynamodb_streams_pod_identity_test.go @@ -79,7 +79,6 @@ spec: labels: app: {{.DeploymentName}} spec: - serviceAccountName: default containers: - name: nginx image: nginxinc/nginx-unprivileged diff --git a/tests/scalers/aws/aws_kinesis_stream_pod_identity/aws_kinesis_stream_pod_identity_test.go b/tests/scalers/aws/aws_kinesis_stream_pod_identity/aws_kinesis_stream_pod_identity_test.go index 40b48dcef07..07d54c02d14 100644 --- a/tests/scalers/aws/aws_kinesis_stream_pod_identity/aws_kinesis_stream_pod_identity_test.go +++ b/tests/scalers/aws/aws_kinesis_stream_pod_identity/aws_kinesis_stream_pod_identity_test.go @@ -69,7 +69,6 @@ spec: labels: app: {{.DeploymentName}} spec: - serviceAccountName: default containers: - name: nginx image: nginxinc/nginx-unprivileged diff --git a/tests/scalers/aws/aws_sqs_queue_pod_identity/aws_sqs_queue_pod_identity_test.go b/tests/scalers/aws/aws_sqs_queue_pod_identity/aws_sqs_queue_pod_identity_test.go index 2c63e1c54d2..01e8daaebc3 100644 --- a/tests/scalers/aws/aws_sqs_queue_pod_identity/aws_sqs_queue_pod_identity_test.go +++ b/tests/scalers/aws/aws_sqs_queue_pod_identity/aws_sqs_queue_pod_identity_test.go @@ -68,7 +68,6 @@ spec: labels: app: {{.DeploymentName}} spec: - serviceAccountName: default containers: - name: nginx image: nginxinc/nginx-unprivileged diff --git a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go index ed38b25dc72..4bd2bb367af 100644 --- a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go +++ b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go @@ -30,17 +30,18 @@ const ( ) var ( - testNamespace = fmt.Sprintf("%s-ns", testName) - deploymentName = fmt.Sprintf("%s-deployment", testName) - monitoredDeploymentName = fmt.Sprintf("%s-monitored", testName) - scaledObjectName = fmt.Sprintf("%s-so", testName) - wrongScaledObjectName = fmt.Sprintf("%s-wrong", testName) - wrongScalerName = fmt.Sprintf("%s-wrong-scaler", testName) - cronScaledJobName = fmt.Sprintf("%s-cron-sj", testName) - clientName = fmt.Sprintf("%s-client", testName) - kedaOperatorPrometheusURL = "http://keda-operator.keda.svc.cluster.local:8080/metrics" - kedaWebhookPrometheusURL = "http://keda-admission-webhooks.keda.svc.cluster.local:8080/metrics" - namespaceString = "namespace" + testNamespace = fmt.Sprintf("%s-ns", testName) + deploymentName = fmt.Sprintf("%s-deployment", testName) + monitoredDeploymentName = fmt.Sprintf("%s-monitored", testName) + scaledObjectName = fmt.Sprintf("%s-so", testName) + wrongScaledObjectName = fmt.Sprintf("%s-wrong", testName) + wrongScalerName = fmt.Sprintf("%s-wrong-scaler", testName) + cronScaledJobName = fmt.Sprintf("%s-cron-sj", testName) + clientName = fmt.Sprintf("%s-client", testName) + kedaOperatorPrometheusURL = "http://keda-operator.keda.svc.cluster.local:8080/metrics" + kedaMetricsServerPrometheusURL = "http://keda-metrics-apiserver.keda.svc.cluster.local:8080/metrics" + kedaWebhookPrometheusURL = "http://keda-admission-webhooks.keda.svc.cluster.local:8080/metrics" + namespaceString = "namespace" ) type templateData struct { @@ -267,6 +268,7 @@ func TestPrometheusMetrics(t *testing.T) { testScalerErrors(t, data) testScalerErrorsTotal(t, data) testOperatorMetrics(t, kc, data) + testMetricServerMetrics(t) testWebhookMetrics(t, data) testScalableObjectMetrics(t) @@ -617,6 +619,10 @@ func testWebhookMetricValues(t *testing.T) { checkWebhookValues(t, families) } +func testMetricServerMetrics(t *testing.T) { + _ = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaMetricsServerPrometheusURL)) +} + func testOperatorMetricValues(t *testing.T, kc *kubernetes.Clientset) { families := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) expectedTriggerTotals, expectedCrTotals := getOperatorMetricsManually(t, kc)