-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add eagerScalingStrategy for ScaledJob #5872
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8de78e5
feat: add eager mode
junekhan f0614e3
chore: add changelog
junekhan bb7c502
fix: rename unused parameter
junekhan 6113790
chore: correct changelog order
junekhan e911f6d
add e2e test for eagerScalingStrategy
junekhan 754105e
fix: correct the e2e test case with the missing RMQ connection config…
junekhan 25991f8
Merge branch 'main' into feat/eager-mode
junekhan 497848e
chore: fix changelog order
junekhan 51ba022
Merge branch 'main' into feat/eager-mode
zroubalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
tests/internals/scaling_strategies/eager_scaling_strategy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package eager_scaling_strategy_test | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
. "github.com/kedacore/keda/v2/tests/helper" // For helper methods | ||
. "github.com/kedacore/keda/v2/tests/scalers/rabbitmq" | ||
) | ||
|
||
var _ = godotenv.Load("../../.env") // For loading env variables from .env | ||
|
||
const ( | ||
testName = "eager-scaling-strategy-test" | ||
) | ||
|
||
var ( | ||
testNamespace = fmt.Sprintf("%s-ns", testName) | ||
rmqNamespace = fmt.Sprintf("%s-rmq", testName) | ||
scaledJobName = fmt.Sprintf("%s-sj", testName) | ||
queueName = "hello" | ||
user = fmt.Sprintf("%s-user", testName) | ||
password = fmt.Sprintf("%s-password", testName) | ||
vhost = "/" | ||
connectionString = fmt.Sprintf("amqp://%s:%s@rabbitmq.%s.svc.cluster.local/", user, password, rmqNamespace) | ||
httpConnectionString = fmt.Sprintf("http://%s:%s@rabbitmq.%s.svc.cluster.local/", user, password, rmqNamespace) | ||
secretName = fmt.Sprintf("%s-secret", testName) | ||
) | ||
|
||
// YAML templates for your Kubernetes resources | ||
const ( | ||
scaledJobTemplate = ` | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{.SecretName}} | ||
namespace: {{.TestNamespace}} | ||
data: | ||
RabbitApiHost: {{.Base64Connection}} | ||
--- | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledJob | ||
metadata: | ||
name: {{.ScaledJobName}} | ||
namespace: {{.TestNamespace}} | ||
labels: | ||
app: {{.ScaledJobName}} | ||
spec: | ||
jobTargetRef: | ||
template: | ||
spec: | ||
containers: | ||
- name: sleeper | ||
image: busybox | ||
command: | ||
- sleep | ||
- "300" | ||
imagePullPolicy: IfNotPresent | ||
envFrom: | ||
- secretRef: | ||
name: {{.SecretName}} | ||
restartPolicy: Never | ||
backoffLimit: 1 | ||
pollingInterval: 5 | ||
maxReplicaCount: 10 | ||
scalingStrategy: | ||
strategy: "eager" | ||
triggers: | ||
- type: rabbitmq | ||
metadata: | ||
queueName: {{.QueueName}} | ||
hostFromEnv: RabbitApiHost | ||
mode: QueueLength | ||
value: '1' | ||
` | ||
) | ||
|
||
type templateData struct { | ||
ScaledJobName string | ||
TestNamespace string | ||
QueueName string | ||
SecretName string | ||
Base64Connection string | ||
} | ||
|
||
func TestScalingStrategy(t *testing.T) { | ||
kc := GetKubernetesClient(t) | ||
data, templates := getTemplateData() | ||
t.Cleanup(func() { | ||
DeleteKubernetesResources(t, testNamespace, data, templates) | ||
RMQUninstall(t, rmqNamespace, user, password, vhost, WithoutOAuth()) | ||
}) | ||
|
||
RMQInstall(t, kc, rmqNamespace, user, password, vhost, WithoutOAuth()) | ||
CreateKubernetesResources(t, kc, testNamespace, data, templates) | ||
|
||
testEagerScaling(t, kc) | ||
} | ||
|
||
func getTemplateData() (templateData, []Template) { | ||
return templateData{ | ||
// Populate fields required in YAML templates | ||
ScaledJobName: scaledJobName, | ||
TestNamespace: testNamespace, | ||
QueueName: queueName, | ||
Base64Connection: base64.StdEncoding.EncodeToString([]byte(httpConnectionString)), | ||
SecretName: secretName, | ||
}, []Template{ | ||
{Name: "scaledJobTemplate", Config: scaledJobTemplate}, | ||
} | ||
} | ||
|
||
func testEagerScaling(t *testing.T, kc *kubernetes.Clientset) { | ||
iterationCount := 20 | ||
RMQPublishMessages(t, rmqNamespace, connectionString, queueName, 4) | ||
assert.True(t, WaitForScaledJobCount(t, kc, scaledJobName, testNamespace, 4, iterationCount, 1), | ||
"job count should be %d after %d iterations", 4, iterationCount) | ||
|
||
RMQPublishMessages(t, rmqNamespace, connectionString, queueName, 4) | ||
assert.True(t, WaitForScaledJobCount(t, kc, scaledJobName, testNamespace, 8, iterationCount, 1), | ||
"job count should be %d after %d iterations", 8, iterationCount) | ||
|
||
RMQPublishMessages(t, rmqNamespace, connectionString, queueName, 4) | ||
assert.True(t, WaitForScaledJobCount(t, kc, scaledJobName, testNamespace, 10, iterationCount, 1), | ||
"job count should be %d after %d iterations", 10, iterationCount) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semgrep found a possible database connection string built with string concatenation. Check for proper encoding/escaping of components to prevent parse errors and injection vulnerabilities.
Ignore this finding from db-connection-string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay.