-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: remove keda objects during reconciliation #3676
Changes from 3 commits
ed14fa0
9e62fdd
c94a6b4
36e3b3a
2099976
1ae09da
ffcae53
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 | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -195,6 +195,9 @@ | |||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||
// If KEDA is not installed or autoscaler feature disabled, do nothing | ||||||||||||||||||||||||||||||||||||||||
cg.MarkAutoscalerDisabled() | ||||||||||||||||||||||||||||||||||||||||
if err := r.deleteKedaObjects(ctx); err != nil { | ||||||||||||||||||||||||||||||||||||||||
Check failure on line 198 in control-plane/pkg/reconciler/consumergroup/consumergroup.go GitHub Actions / analyze / Go vulnerability Detection
Check failure on line 198 in control-plane/pkg/reconciler/consumergroup/consumergroup.go GitHub Actions / build / Build
Check failure on line 198 in control-plane/pkg/reconciler/consumergroup/consumergroup.go GitHub Actions / test / Unit Tests
|
||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if err := r.reconcileConsumers(ctx, cg); err != nil { | ||||||||||||||||||||||||||||||||||||||||
|
@@ -845,3 +848,52 @@ | |||||||||||||||||||||||||||||||||||||||
func keyOf(cg metav1.Object) string { | ||||||||||||||||||||||||||||||||||||||||
return types.NamespacedName{Namespace: cg.GetNamespace(), Name: cg.GetName()}.String() | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// deleteKedaObjects is responsible for deleting Keda (Kubernetes-based Event Driven Autoscaling) objects, "scaled | ||||||||||||||||||||||||||||||||||||||||
// objects" and "trigger authentications" from all available namespaces. | ||||||||||||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||||||||||||
// When Keda creates a scaled object, it also generates a Horizontal Pod Autoscaler. This resource will also be removed | ||||||||||||||||||||||||||||||||||||||||
// when the scaled object is deleted. | ||||||||||||||||||||||||||||||||||||||||
func (r *Reconciler) deleteKedaObjects(ctx context.Context, cg *kafkainternals.ConsumerGroup) error { | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// check if scaled object exist, if not ignore | ||||||||||||||||||||||||||||||||||||||||
scaledObjectName := keda.GenerateScaledObjectName(cg) | ||||||||||||||||||||||||||||||||||||||||
_, err := r.KedaClient.KedaV1alpha1().ScaledObjects(cg.Namespace).Get(ctx, scaledObjectName, metav1.GetOptions{}) | ||||||||||||||||||||||||||||||||||||||||
if err != nil && !apierrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to get Keda scaled object: %w", err) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
if !apierrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||
err = r.KedaClient.KedaV1alpha1().ScaledObjects(cg.Namespace).Delete(ctx, scaledObjectName, metav1.DeleteOptions{}) | ||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to delete Keda scaled object: %w", err) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
logging.FromContext(ctx).Debugw("Keda scaled object deleted", | ||||||||||||||||||||||||||||||||||||||||
"name", scaledObjectName, | ||||||||||||||||||||||||||||||||||||||||
"namespace", cg.Namespace) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
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. Instead of
Suggested change
I don't know if the suggestion is properly formatted, it's mostly for describing the idea better |
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// check if trigger authentication exist , if not ignore | ||||||||||||||||||||||||||||||||||||||||
var triggerAuthName string | ||||||||||||||||||||||||||||||||||||||||
if len(cg.ObjectMeta.OwnerReferences) > 0 && cg.ObjectMeta.OwnerReferences[0].UID != "" { | ||||||||||||||||||||||||||||||||||||||||
triggerAuthName = string(cg.ObjectMeta.OwnerReferences[0].UID) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
// skip deleting trigger authentication if object reference doesn't exist | ||||||||||||||||||||||||||||||||||||||||
if triggerAuthName == "" { | ||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
_, err = r.KedaClient.KedaV1alpha1().TriggerAuthentications(cg.Namespace).Get(ctx, triggerAuthName, metav1.GetOptions{}) | ||||||||||||||||||||||||||||||||||||||||
if err != nil && !apierrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to get Keda trigger authenticatoin") | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
if !apierrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||
err = r.KedaClient.KedaV1alpha1().TriggerAuthentications(cg.Namespace).Delete(ctx, triggerAuthName, metav1.DeleteOptions{}) | ||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to delete Keda trigger authentication: %w", err) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
logging.FromContext(ctx).Debugw("Keda trigger authentication deleted", | ||||||||||||||||||||||||||||||||||||||||
"name", triggerAuthName, | ||||||||||||||||||||||||||||||||||||||||
"namespace", cg.Namespace) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
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. similar idea here, we can just call 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. |
||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||
} |
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.