Skip to content

fix: Improve e2e tests and small fixes #6737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pkg/scalers/external_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package scalers

import (
"context"
"errors"
"fmt"
"io"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -249,27 +251,35 @@ func (s *externalScaler) GetMetricsAndActivity(ctx context.Context, metricName s
// handleIsActiveStream is the only writer to the active channel and will close it on return.
func (s *externalPushScaler) Run(ctx context.Context, active chan<- bool) {
defer close(active)

// retry on error from runWithLog() starting by 2 sec backing off * 2 with a max of 2 minute
retryDuration := time.Second * 2

// It's possible for the connection to get terminated anytime, we need to run this in a retry loop
runWithLog := func() {
grpcClient, err := getClientForConnectionPool(s.metadata)
if err != nil {
s.logger.Error(err, "error running internalRun")
s.logger.Error(err, "unable to get connection from the pool")
return
}
if err := handleIsActiveStream(ctx, &s.scaledObjectRef, grpcClient, active); err != nil {
s.logger.Error(err, "error running internalRun")
if !errors.Is(err, io.EOF) { // If io.EOF is returned, the stream has terminated with an OK status
s.logger.Error(err, "error running internalRun")
return
}
// if the connection is properly closed, we reset the timer
retryDuration = time.Second * 2
return
}
}

// retry on error from runWithLog() starting by 2 sec backing off * 2 with a max of 2 minute
retryDuration := time.Second * 2
// the caller of this function needs to ensure that they call Stop() on the resulting
// timer, to release background resources.
retryBackoff := func() *time.Timer {
tmr := time.NewTimer(retryDuration)
s.logger.V(1).Info("external push retry backoff", "duration", retryDuration)
retryDuration *= 2
if retryDuration > time.Minute*1 {
if retryDuration > time.Minute {
retryDuration = time.Minute * 1
}
return tmr
Expand Down
16 changes: 8 additions & 8 deletions pkg/scalers/gcp_storage_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,22 @@ func (s *gcsScaler) getItemCount(ctx context.Context, maxCount int64) (int64, er

for count < maxCount {
item, err := it.Next()
if err == iterator.Done {
break
}
// The folder is retrieved as an entity, so if size is 0
// we can skip it
if item.Size == 0 {
continue
}
if err != nil {
if errors.Is(err, iterator.Done) {
break
}
if errors.Is(err, storage.ErrBucketNotExist) {
s.logger.Info("Bucket " + s.metadata.bucketName + " doesn't exist")
return 0, nil
}
s.logger.Error(err, "failed to enumerate items in bucket "+s.metadata.bucketName)
return count, err
}
// The folder is retrieved as an entity, so if size is 0
// we can skip it
if item.Size == 0 {
continue
}
count++
}

Expand Down
4 changes: 2 additions & 2 deletions tests/internals/cache_metrics/cache_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
spec:
containers:
- name: {{.MonitoredDeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

deploymentTemplate = `
Expand All @@ -78,7 +78,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'`
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'`

secretTemplate = `
apiVersion: v1
Expand Down Expand Up @@ -145,7 +145,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'`
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'`

scaledObjectTemplate = `apiVersion: keda.sh/v1alpha1
kind: ScaledObject
Expand Down
6 changes: 3 additions & 3 deletions tests/internals/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'
`

deploymentTemplate = `
Expand All @@ -112,7 +112,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged:alpine-slim
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTargetErrTemplate = `
Expand Down Expand Up @@ -150,7 +150,7 @@ spec:
spec:
containers:
- name: {{.DaemonsetName}}
image: nginxinc/nginx-unprivileged:alpine-slim
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTargetNotSupportTemplate = `
Expand Down
2 changes: 1 addition & 1 deletion tests/internals/fallback/fallback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/idle_replicas/idle_replicas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spec:
spec:
containers:
- name: {{.MonitoredDeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

deploymentTemplate = `
Expand All @@ -75,7 +75,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
spec:
containers:
- name: {{.MonitoredDeploymentName}}
image: nginxinc/nginx-unprivileged:alpine-slim
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

deploymentTemplate = `
Expand All @@ -82,7 +82,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged:alpine-slim
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
spec:
containers:
- name: {{.MonitoredDeploymentName}}
image: nginxinc/nginx-unprivileged:alpine-slim
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

deploymentTemplate = `
Expand All @@ -81,7 +81,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged:alpine-slim
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/restore_original/restore_original_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spec:
spec:
containers:
- name: {{.MonitoredDeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

deploymentTemplate = `
Expand All @@ -75,7 +75,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down Expand Up @@ -335,7 +335,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
resources:
limits:
cpu: 50m
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/scaling_modifiers/scaling_modifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down Expand Up @@ -237,7 +237,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'`
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'`

updateMetricsTemplate = `
apiVersion: batch/v1
Expand Down
2 changes: 1 addition & 1 deletion tests/internals/status_update/status_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/subresource_scale/subresource_scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'`
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'`

argoRolloutTemplate = `apiVersion: argoproj.io/v1alpha1
kind: Rollout
Expand All @@ -82,7 +82,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `apiVersion: keda.sh/v1alpha1
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/trigger_update_so/trigger_update_so_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand All @@ -135,7 +135,7 @@ spec:
spec:
containers:
- name: nginx
image: 'nginxinc/nginx-unprivileged'`
image: 'ghcr.io/nginx/nginx-unprivileged:1.26'`

metricsServerDeploymentTemplate = `
apiVersion: apps/v1
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/update_ta/update_ta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand All @@ -122,7 +122,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/value_metric_type/value_metric_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spec:
spec:
containers:
- name: {{.MonitoredDeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

deploymentTemplate = `
Expand All @@ -76,7 +76,7 @@ spec:
spec:
containers:
- name: {{.DeploymentName}}
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
`

scaledObjectTemplate = `
Expand Down
2 changes: 1 addition & 1 deletion tests/scalers/activemq/activemq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ spec:
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged
image: ghcr.io/nginx/nginx-unprivileged:1.26
ports:
- containerPort: 80
`
Expand Down
Loading
Loading