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

chore: Adds CoudEvents when a ScaledObject scales a workload from/to zero or one #5632

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

neelanjan00
Copy link
Contributor

@neelanjan00 neelanjan00 commented Mar 27, 2024

Checklist

Relates to #3527

@neelanjan00 neelanjan00 requested a review from a team as a code owner March 27, 2024 17:46
Signed-off-by: neelanjan00 <neelanjan.manna@harness.io>
Signed-off-by: neelanjan00 <neelanjan.manna@harness.io>
@tomkerkhove
Copy link
Member

Can you open a PR for our docs as well please?

Copy link
Member

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

Added some small suggestions, but I was wondering if:

  • You could add e2e tests
  • Share an example of the cloudevents being emitted

@@ -28,4 +28,8 @@ const (
ScaleTargetNotFoundMsg = "Target resource doesn't exist"

ScaleTargetNoSubresourceMsg = "Target resource doesn't expose /scale subresource"

ScaleTargetFromZero = "Target resource is scaling up from zero number of replicas"
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
ScaleTargetFromZero = "Target resource is scaling up from zero number of replicas"
ScaleTargetFromZero = "Target resource is scaling out from zero"


ScaleTargetFromZero = "Target resource is scaling up from zero number of replicas"

ScaleTargetToZero = "Target resource is scaling down to zero number of replicas"
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
ScaleTargetToZero = "Target resource is scaling down to zero number of replicas"
ScaleTargetToZero = "Target resource is scaling in to zero replicas"

@zroubalik
Copy link
Member

@neelanjan00 any update on this please?

@SpiritZhou
Copy link
Contributor

eventEmitter.Emit() will emit a k8s event at the same time. Replacing the recorder with eventEmitter and r.Recorder.Event() with eventEmitter.Emit() is better than passing an eventEmitter as a new parameter. Alternatively, we could pass an eventEmitter as a new parameter and delete the recorder once all r.Recorder.Event() calls have been replaced.

@@ -272,6 +275,13 @@ func (e *scaleExecutor) scaleToZeroOrIdle(ctx context.Context, logger logr.Logge

e.recorder.Eventf(scaledObject, corev1.EventTypeNormal, eventreason.KEDAScaleTargetDeactivated,
Copy link
Contributor

Choose a reason for hiding this comment

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

This one and the new one are duplicated. We should merge these two into one event. eventEmitter.Emit() includes emitting k8s event.

corev1.EventTypeNormal, eventemitter.ScaleFromZeroType, eventreason.KEDAScaleTargetActivated,
message.ScaleTargetFromZero)
}

e.recorder.Eventf(scaledObject, corev1.EventTypeNormal, eventreason.KEDAScaleTargetActivated, "Scaled %s %s/%s from %d to %d", scaledObject.Status.ScaleTargetKind, scaledObject.Namespace, scaledObject.Spec.ScaleTargetRef.Name, currentReplicas, replicas)
Copy link
Contributor

Choose a reason for hiding this comment

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

This one and the new one are duplicated. We should merge these two into one event.

@@ -80,7 +80,7 @@ func init() {

// SetupWithManager initializes the ScaledJobReconciler instance and starts a new controller managed by the passed Manager instance.
func (r *ScaledJobReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
r.scaleHandler = scaling.NewScaleHandler(mgr.GetClient(), nil, mgr.GetScheme(), r.GlobalHTTPTimeout, mgr.GetEventRecorderFor("scale-handler"), r.SecretsLister)
r.scaleHandler = scaling.NewScaleHandler(mgr.GetClient(), nil, mgr.GetScheme(), r.GlobalHTTPTimeout, mgr.GetEventRecorderFor("scale-handler"), r.SecretsLister, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

create and pass a new event emitter as well so that it doesn't need to check nil later.

@tomkerkhove
Copy link
Member

We are planning release on Thursday, any chance we can incorporate the feedback?

@neelanjan00
Copy link
Contributor Author

Hey @tomkerkhove, @zroubalik sorry for not being active on this! I am presently occupied with some office work so not able to put time away for this, not sure if I will be able to add the E2E tests on time for the release.

@tomkerkhove
Copy link
Member

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants