@@ -431,9 +431,8 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
431431 // The old secret's finalizer is removed later (after all services deploy)
432432 // so that rapid rotations don't revoke a credential still in use by pods.
433433 if instance .Spec .Auth .ApplicationCredentialSecret != "" {
434- if err := keystonev1 . ManageACSecretFinalizer (ctx , helper , instance .Namespace ,
434+ if err := object . ManageSecretConsumerFinalizer (ctx , helper , instance .Namespace ,
435435 instance .Spec .Auth .ApplicationCredentialSecret ,
436- "" ,
437436 watcher .ACConsumerFinalizer ); err != nil {
438437 instance .Status .Conditions .Set (condition .FalseCondition (
439438 condition .InputReadyCondition ,
@@ -567,24 +566,6 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
567566 watcherDecisionEngine .Status .AppliedInputSecretHash == subLevelSecretHash &&
568567 watcherDecisionEngine .IsReady ()
569568
570- // Manage the old AC secret's finalizer and status tracking.
571- // On rotation (old != new), only remove the old secret's finalizer after
572- // all sub-services are ready with the new credentials. This prevents
573- // premature revocation during rapid rotations.
574- isRotation := instance .Status .ApplicationCredentialSecret != "" && instance .Status .ApplicationCredentialSecret != instance .Spec .Auth .ApplicationCredentialSecret
575-
576- if isRotation {
577- if allServicesReady {
578- if err := keystonev1 .RemoveACSecretConsumerFinalizer (ctx , helper , instance .Namespace ,
579- instance .Status .ApplicationCredentialSecret , watcher .ACConsumerFinalizer ); err != nil {
580- return ctrl.Result {}, err
581- }
582- instance .Status .ApplicationCredentialSecret = instance .Spec .Auth .ApplicationCredentialSecret
583- }
584- } else if instance .Status .ApplicationCredentialSecret != instance .Spec .Auth .ApplicationCredentialSecret {
585- instance .Status .ApplicationCredentialSecret = instance .Spec .Auth .ApplicationCredentialSecret
586- }
587-
588569 // Finalize transport URL and notification transport URL secret rotation.
589570 // The consumer finalizer on the old secret is only released once every
590571 // sub-service is ready with the new credentials (allServicesReady), so
@@ -642,6 +623,19 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
642623 instance .Status .NotificationsTransportURLSecret = ""
643624 }
644625
626+ // Finalize AC secret rotation
627+ acSecretName , err := object .FinalizeSecretRotation (
628+ ctx , helper , instance .Namespace ,
629+ instance .Status .ApplicationCredentialSecret ,
630+ instance .Spec .Auth .ApplicationCredentialSecret ,
631+ watcher .ACConsumerFinalizer ,
632+ guardReady ,
633+ )
634+ if err != nil {
635+ return ctrl.Result {}, err
636+ }
637+ instance .Status .ApplicationCredentialSecret = acSecretName
638+
645639 // Self-heal consumer finalizers stranded on secrets superseded during
646640 // rapid rotation (A -> B -> C before the workloads became ready):
647641 // FinalizeSecretRotation only ever releases the single tracked "old"
@@ -1520,17 +1514,6 @@ func (r *WatcherReconciler) reconcileDelete(ctx context.Context, instance *watch
15201514 }
15211515 //
15221516
1523- // Remove consumer finalizer from AC secrets watcher was consuming.
1524- for _ , secretName := range []string {
1525- instance .Status .ApplicationCredentialSecret ,
1526- instance .Spec .Auth .ApplicationCredentialSecret ,
1527- } {
1528- if err := keystonev1 .RemoveACSecretConsumerFinalizer (ctx , helper , instance .Namespace ,
1529- secretName , watcher .ACConsumerFinalizer ); err != nil {
1530- return ctrl.Result {}, err
1531- }
1532- }
1533-
15341517 // Remove the transport consumer finalizer from every transport URL secret
15351518 // watcher was consuming (main + notifications, plus any secret superseded by
15361519 // an in-flight rotation). Pass no keep set so all secrets still carrying the
@@ -1542,6 +1525,14 @@ func (r *WatcherReconciler) reconcileDelete(ctx context.Context, instance *watch
15421525 return ctrl.Result {}, err
15431526 }
15441527
1528+ // Remove the AC consumer finalizer from every AC secret watcher was
1529+ // protecting so their owning application credentials can be revoked.
1530+ if err := object .PruneSecretConsumerFinalizers (
1531+ ctx , helper , instance .Namespace , watcher .ACConsumerFinalizer ,
1532+ ); err != nil {
1533+ return ctrl.Result {}, err
1534+ }
1535+
15451536 controllerutil .RemoveFinalizer (instance , helper .GetFinalizer ())
15461537 Log .Info (fmt .Sprintf ("Reconciled Service '%s' delete successfully" , instance .Name ))
15471538 return ctrl.Result {}, nil
0 commit comments