-
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
chore: Adds CoudEvents when a ScaledObject scales a workload from/to zero or one #5632
Changes from all commits
4ffb9df
405357e
7241fc1
7bcbc46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,12 @@ import ( | |
autoscalingv1 "k8s.io/api/autoscaling/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" | ||
"github.com/kedacore/keda/v2/pkg/common/message" | ||
"github.com/kedacore/keda/v2/pkg/eventemitter" | ||
"github.com/kedacore/keda/v2/pkg/eventreason" | ||
kedastatus "github.com/kedacore/keda/v2/pkg/status" | ||
) | ||
|
@@ -272,6 +275,13 @@ func (e *scaleExecutor) scaleToZeroOrIdle(ctx context.Context, logger logr.Logge | |
|
||
e.recorder.Eventf(scaledObject, corev1.EventTypeNormal, eventreason.KEDAScaleTargetDeactivated, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"Deactivated %s %s/%s from %d to %d", scaledObject.Status.ScaleTargetKind, scaledObject.Namespace, scaledObject.Spec.ScaleTargetRef.Name, currentReplicas, scaleToReplicas) | ||
|
||
if scaleToReplicas == 0 && e.eventEmitter != nil { | ||
e.eventEmitter.Emit(scaledObject, types.NamespacedName{Namespace: scaledObject.Namespace}, | ||
corev1.EventTypeNormal, eventemitter.ScaleToZeroType, eventreason.KEDAScaleTargetActivated, | ||
message.ScaleTargetToZero) | ||
} | ||
|
||
if err := e.setActiveCondition(ctx, logger, scaledObject, metav1.ConditionFalse, "ScalerNotActive", "Scaling is not performed because triggers are not active"); err != nil { | ||
logger.Error(err, "Error in setting active condition") | ||
return | ||
|
@@ -309,6 +319,13 @@ func (e *scaleExecutor) scaleFromZeroOrIdle(ctx context.Context, logger logr.Log | |
logger.Info("Successfully updated ScaleTarget", | ||
"Original Replicas Count", currentReplicas, | ||
"New Replicas Count", replicas) | ||
|
||
if currentReplicas == 0 && e.eventEmitter != nil { | ||
e.eventEmitter.Emit(scaledObject, types.NamespacedName{Namespace: scaledObject.Namespace}, | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
// Scale was successful. Update lastScaleTime and lastActiveTime on the scaledObject | ||
|
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.
create and pass a new event emitter as well so that it doesn't need to check nil later.