Skip to content
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 support for initialCooldownPeriod On httpScaledObjects #1212

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This changelog keeps track of work items that have been completed and are ready
- **General**: Support portName in HTTPScaledObject service scaleTargetRef ([#1174](https://github.com/kedacore/http-add-on/issues/1174))
- **General**: Support setting multiple TLS certs for different domains on the interceptor proxy ([#1116](https://github.com/kedacore/http-add-on/issues/1116))
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
- **General**: Support InitialCooldownPeriod for HTTPScaledObject [#1213](https://github.com/kedacore/http-add-on/issues/1213)

- **Interceptor**: Add support for for AWS ELB healthcheck probe ([#1198](https://github.com/kedacore/http-add-on/issues/1198))

Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/http.keda.sh_httpscaledobjects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ spec:
items:
type: string
type: array
initialCooldownPeriod:
description: (optional) Initial period before scaling
format: int32
type: integer
pathPrefixes:
description: |-
The paths to route. All requests which the Request Target matches any
Expand Down
3 changes: 3 additions & 0 deletions operator/apis/http/v1alpha1/httpscaledobject_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ type HTTPScaledObjectSpec struct {
// (optional) Cooldown period value
// +optional
CooldownPeriod *int32 `json:"scaledownPeriod,omitempty" description:"Cooldown period (seconds) for resources to scale down (Default 300)"`
// (optional) Initial period before scaling
// +optional
InitialCooldownPeriod int32 `json:"initialCooldownPeriod,omitempty" description:"Initial period (seconds) before scaling (Default 0)"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
InitialCooldownPeriod int32 `json:"initialCooldownPeriod,omitempty" description:"Initial period (seconds) before scaling (Default 0)"`
InitialCooldownPeriod *int32 `json:"initialCooldownPeriod,omitempty" description:"Initial period (seconds) before scaling (Default 0)"`

I think this is better

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change this, however the scaledObject parameter is not a pointer, which means we'll have to add a nil check.
let me know if you think it's worth.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that was an oversight on the upstream KEDA. Let's use pointers here, I will see if I can safely change the upstream as well.

Copy link
Member

@wozniakjan wozniakjan Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that seems to be correct. In KEDA the CooldownPeriod is a pointer while InitialCooldownPeriod is not a pointer. I think it's because default for CooldownPeriod is 300 and user setting 0 must be distinguishable from user not setting anything and expecting KEDA to set the default. For InitialCooldownPeriod, the default is 0 so setting nil would be semantically equivalent, hence no need for a pointer.

I'd actually vote for keeping the API consistent with KEDA, CooldownPeriod as a pointer and InitialCooldownPeriod not a pointer. But I'm easy to convince otherwise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine either way, just let me know what to do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking here: kedacore/keda#6423

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zroubalik I see the upstream was merged. should I update this one accordingly? do we want to set default values here or just pass whatever we get to the scaled object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please also use pointer here and I think that we should keep the defaults to the core, CC @wozniakjan

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, we will probably have to wait for kedacore to cut a release version we can reference with the new type. unless you want to point to a master commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code for now.

// (optional) Configuration for the metric used for scaling
// +optional
ScalingMetric *ScalingMetricSpec `json:"scalingMetric,omitempty" description:"Configuration for the metric used for scaling. If empty 'concurrency' will be used"`
Expand Down
1 change: 1 addition & 0 deletions operator/controllers/http/scaled_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateScaledObject(
minReplicaCount,
maxReplicaCount,
httpso.Spec.CooldownPeriod,
httpso.Spec.InitialCooldownPeriod,
)

// Set HTTPScaledObject instance as the owner and controller
Expand Down
10 changes: 6 additions & 4 deletions pkg/k8s/scaledobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewScaledObject(
minReplicas *int32,
maxReplicas *int32,
cooldownPeriod *int32,
initialCooldownPeriod int32,
) *kedav1alpha1.ScaledObject {
return &kedav1alpha1.ScaledObject{
TypeMeta: metav1.TypeMeta{
Expand All @@ -45,10 +46,11 @@ func NewScaledObject(
Kind: workloadRef.Kind,
Name: workloadRef.Name,
},
PollingInterval: ptr.To[int32](soPollingInterval),
CooldownPeriod: cooldownPeriod,
MinReplicaCount: minReplicas,
MaxReplicaCount: maxReplicas,
PollingInterval: ptr.To[int32](soPollingInterval),
CooldownPeriod: cooldownPeriod,
InitialCooldownPeriod: initialCooldownPeriod,
MinReplicaCount: minReplicas,
MaxReplicaCount: maxReplicas,
Advanced: &kedav1alpha1.AdvancedConfig{
RestoreToOriginalReplicaCount: true,
},
Expand Down
Loading