Skip to content

Commit ec53c56

Browse files
[release-1.17] Run keda obj deletion only if the feature was previously enabled, to avoid GET requests for KEDA resources against the API server on each reconcilation (#4385)
* Run keda obj deletion only if the feature was previously enabled, to avoid GET requests for KEDA resources against the API server on each reconcilation Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> * lipstick: make string constant Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> --------- Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> Co-authored-by: Matthias Wessendorf <mwessend@redhat.com>
1 parent 1e1a7f0 commit ec53c56

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

control-plane/pkg/apis/internalskafkaeventing/v1alpha1/consumer_group_lifecycle.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
ConditionConsumerGroupConsumers apis.ConditionType = "Consumers"
2727
ConditionConsumerGroupConsumersScheduled apis.ConditionType = "ConsumersScheduled"
2828
ConditionAutoscaling apis.ConditionType = "Autoscaler"
29+
AutoscalerDisabled = "AutoscalerDisabled"
2930
// Labels
3031
KafkaChannelNameLabel = "kafkachannel-name"
3132
ConsumerLabelSelector = "kafka.eventing.knative.dev/metadata.uid"
@@ -98,7 +99,7 @@ func (cg *ConsumerGroup) MarkAutoscalerSucceeded() {
9899
}
99100

100101
func (cg *ConsumerGroup) MarkAutoscalerDisabled() {
101-
cg.GetConditionSet().Manage(cg.GetStatus()).MarkTrueWithReason(ConditionAutoscaling, "Autoscaler is disabled", "")
102+
cg.GetConditionSet().Manage(cg.GetStatus()).MarkTrueWithReason(ConditionAutoscaling, AutoscalerDisabled, "")
102103
}
103104

104105
func (cg *ConsumerGroup) MarkAutoscalerFailed(reason string, err error) error {

control-plane/pkg/apis/internalskafkaeventing/v1alpha1/consumer_group_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ func (cg *ConsumerGroup) IsNotScheduled() bool {
232232
return cond.IsFalse() || cond.IsUnknown()
233233
}
234234

235+
func (cg *ConsumerGroup) IsAutoscalerNotDisabled() bool {
236+
condition := cg.Status.GetCondition(ConditionAutoscaling)
237+
238+
// If condition doesn't exist or is not true, it's not in "disabled" state
239+
if condition == nil || condition.Status != corev1.ConditionTrue {
240+
return true
241+
}
242+
243+
// If condition is True but reason is not "autoscaler is disabled", then it's actively enabled
244+
return condition.Reason != AutoscalerDisabled
245+
}
246+
235247
func (cg *ConsumerGroup) HasDeadLetterSink() bool {
236248
return hasDeadLetterSink(cg.Spec.Template.Spec.Delivery)
237249
}

control-plane/pkg/reconciler/consumergroup/consumergroup.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,18 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, cg *kafkainternals.Consu
211211
}
212212
cg.MarkAutoscalerSucceeded()
213213
} else {
214-
// If KEDA is not installed or autoscaler feature disabled, do nothing
215-
cg.MarkAutoscalerDisabled()
216-
if err := r.deleteKedaObjects(ctx, cg); err != nil {
217-
return err
214+
215+
// If KEDA autoscaler feature is disabled, we need to check if it was enabled before
216+
// check if the conditoion is not yet AutoscalerDisabled, only than delete KEDA objects
217+
if cg.IsAutoscalerNotDisabled() {
218+
logger.Debugw("Deleting KEDA objects as autoscaler is being disabled")
219+
if err := r.deleteKedaObjects(ctx, cg); err != nil {
220+
return err
221+
}
218222
}
223+
224+
// Mark as disabled after successful deletion, or if the feature was already disabled
225+
cg.MarkAutoscalerDisabled()
219226
}
220227

221228
logger.Debugw("Reconciling consumers")

0 commit comments

Comments
 (0)