forked from kedacore/keda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
InitialCooldownPeriod
for ScaledObjects (kedacore#5478)
Signed-off-by: xrwang <68765051+xrwang8@users.noreply.github.com> Signed-off-by: wangxingrui <xrwang8@gmail.com> Co-authored-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es> Co-authored-by: Zbynek Roubalik <zroubalik@gmail.com>
- Loading branch information
1 parent
adfe867
commit 80806a7
Showing
5 changed files
with
137 additions
and
3 deletions.
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
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
120 changes: 120 additions & 0 deletions
120
tests/internals/initial_delay_cooldownperiod/initial_delay_cooldownperiod_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,120 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package initial_delay_cooldownperiod_test | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
. "github.com/kedacore/keda/v2/tests/helper" | ||
) | ||
|
||
const ( | ||
testName = "initial-delay-cooldownperiod-test" | ||
) | ||
|
||
var ( | ||
testNamespace = fmt.Sprintf("%s-ns", testName) | ||
deploymentName = fmt.Sprintf("%s-deployment", testName) | ||
scaledObjectName = fmt.Sprintf("%s-so", testName) | ||
|
||
now = time.Now().Local() | ||
start = (now.Minute() + 10) % 60 | ||
end = (start + 1) % 60 | ||
) | ||
|
||
type templateData struct { | ||
TestNamespace string | ||
DeploymentName string | ||
ScaledObjectName string | ||
StartMin string | ||
EndMin string | ||
} | ||
|
||
const ( | ||
deploymentTemplate = ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{.DeploymentName}} | ||
namespace: {{.TestNamespace}} | ||
labels: | ||
deploy: {{.DeploymentName}} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
pod: {{.DeploymentName}} | ||
template: | ||
metadata: | ||
labels: | ||
pod: {{.DeploymentName}} | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: 'nginxinc/nginx-unprivileged' | ||
` | ||
|
||
scaledObjectTemplate = ` | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: {{.ScaledObjectName}} | ||
namespace: {{.TestNamespace}} | ||
spec: | ||
scaleTargetRef: | ||
name: {{.DeploymentName}} | ||
cooldownPeriod: 5 | ||
minReplicaCount: 0 | ||
initialCooldownPeriod: 120 | ||
advanced: | ||
horizontalPodAutoscalerConfig: | ||
behavior: | ||
scaleDown: | ||
stabilizationWindowSeconds: 15 | ||
triggers: | ||
- type: cron | ||
metadata: | ||
timezone: Etc/UTC | ||
start: {{.StartMin}} * * * * | ||
end: {{.EndMin}} * * * * | ||
desiredReplicas: '0' | ||
` | ||
) | ||
|
||
func TestScaler(t *testing.T) { | ||
// setup | ||
t.Log("--- setting up ---") | ||
|
||
// Create kubernetes resources | ||
kc := GetKubernetesClient(t) | ||
data, templates := getTemplateData() | ||
|
||
CreateKubernetesResources(t, kc, testNamespace, data, templates) | ||
assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, 1, 60, 1), | ||
"replica count should be %d after 1 minute", 1) | ||
t.Log("--- Waiting for some time to ensure deployment replica count doesn't change ---") | ||
AssertReplicaCountNotChangeDuringTimePeriod(t, kc, deploymentName, testNamespace, 1, 90) | ||
t.Log("--- scale to 0 replicas ---") | ||
assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, 0, 120, 1), | ||
"replica count should be %d after 2 minute", 0) // Assert that the workload is scaled to zero after the initial cooldown period | ||
|
||
DeleteKubernetesResources(t, testNamespace, data, templates) | ||
} | ||
func getTemplateData() (templateData, []Template) { | ||
return templateData{ | ||
TestNamespace: testNamespace, | ||
DeploymentName: deploymentName, | ||
ScaledObjectName: scaledObjectName, | ||
StartMin: strconv.Itoa(start), | ||
EndMin: strconv.Itoa(end), | ||
}, []Template{ | ||
{Name: "deploymentTemplate", Config: deploymentTemplate}, | ||
{Name: "scaledObjectTemplate", Config: scaledObjectTemplate}, | ||
} | ||
} |