Skip to content

Commit

Permalink
Add validations for Stabilizationwindowseconds (#4983)
Browse files Browse the repository at this point in the history
Signed-off-by: Indresh2410 <indreshprakash24@gmail.com>
  • Loading branch information
Indresh2410 committed Sep 20, 2023
1 parent b7c3d24 commit d131480
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **Pulsar Scaler**: Add support for OAuth extensions ([#4700](https://github.com/kedacore/keda/issues/4700))

### Fixes
- **General**: Add validations for stabilizationWindowSeconds ([#4976](https://github.com/kedacore/keda/issues/4976))
- **RabbitMQ Scaler**: Allow subpaths along with vhost in connection string ([#2634](https://github.com/kedacore/keda/issues/2634))
- **Selenium Grid Scaler**: Fix latest browser version use case scaling ([#4858](https://github.com/kedacore/keda/issues/4858))
- **Solace Scaler**: Fix a bug where `queueName` is not properly escaped during URL encode ([#4936](https://github.com/kedacore/keda/issues/4936))
Expand Down
20 changes: 20 additions & 0 deletions apis/keda/v1alpha1/scaledobject_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,26 @@ var _ = It("should validate the so update if it's removing the finalizer even if
}).ShouldNot(HaveOccurred())
})

var _ = It("shouldn't create so when stabilizationWindowSeconds exceeds 3600", func() {

namespaceName := "fail-so-creation"
namespace := createNamespace(namespaceName)
so := createScaledObject(soName, namespaceName, workloadName, "apps/v1", "Deployment", false, map[string]string{}, "")
so.Spec.Advanced.HorizontalPodAutoscalerConfig = &HorizontalPodAutoscalerConfig{
Behavior: &v2.HorizontalPodAutoscalerBehavior{
ScaleDown: &v2.HPAScalingRules{
StabilizationWindowSeconds: ptr.To[int32](3700),
},
},
}
err := k8sClient.Create(context.Background(), namespace)
Expect(err).ToNot(HaveOccurred())

Eventually(func() error {
return k8sClient.Create(context.Background(), so)
}).Should(HaveOccurred())
})

var _ = AfterSuite(func() {
cancel()
By("tearing down the test environment")
Expand Down
7 changes: 7 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ patchesJson6902:
name: scaledjobs.keda.sh
path: patches/scaledjob_patch.yaml

- target:
version: v1
group: apiextensions.k8s.io
kind: CustomResourceDefinition
name: scaledobjects.keda.sh
path: patches/scaledobject_patch.yaml

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
Expand Down
18 changes: 18 additions & 0 deletions config/crd/patches/scaledobject_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
## needs to be patched because of an issue with stabilizationWindowSeconds maximum limit
## https://github.com/kedacore/keda/issues/4976
- op: add
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/advanced/properties/horizontalPodAutoscalerConfig/properties/behavior/properties/scaleDown/properties/stabilizationWindowSeconds/minimum
value: 0

- op: add
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/advanced/properties/horizontalPodAutoscalerConfig/properties/behavior/properties/scaleDown/properties/stabilizationWindowSeconds/maximum
value: 3600

- op: add
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/advanced/properties/horizontalPodAutoscalerConfig/properties/behavior/properties/scaleUp/properties/stabilizationWindowSeconds/minimum
value: 0

- op: add
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/advanced/properties/horizontalPodAutoscalerConfig/properties/behavior/properties/scaleUp/properties/stabilizationWindowSeconds/maximum
value: 3600

0 comments on commit d131480

Please sign in to comment.