-
Couldn't load subscription status.
- Fork 131
Fix VDS bug where 2 leases are being generated on initial deployment #1054
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
base: main
Are you sure you want to change the base?
Conversation
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.
Could we add tests for this case.
| if addedFinalizer, err := maybeAddFinalizer(ctx, r.Client, o, vaultDynamicSecretFinalizer); err != nil { | ||
| return ctrl.Result{}, err | ||
| } else if addedFinalizer { | ||
| // the finalizer was added, requeue the request. | ||
| return ctrl.Result{Requeue: true}, 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.
There's a comment in maybeAddFinalizer():
vault-secrets-operator/controllers/common.go
Lines 248 to 249 in e024c75
| // always call maybeAddFinalizer() after client.Client.Status.Update() to avoid | |
| // API validation errors due to changes to the status schema. |
Any concern with API validation errors now that maybeAddFinalizer() is being called before updateStatus()?
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.
Thank you for reviewing! My understanding for the comment is that an API validation error would happen if both metadata (finalizers) and status of a resource are updated in the same reconcile pass. But in our case, we are calling maybeAddFinalizer() first, and if a finalizer is added, we exit early and requeue. So we shouldn't be touching the status in the same loop, which would avoid the validation issue because the next reconcile handles the status update separately. Please let me know if I am misunderstanding!
This PR fixes a race condition that could cause two Vault leases to be created during the initial reconcile of VDS. This happened because the finalizer was added after the status update (LastGeneration = generation), which caused the generation to be bumped again, triggering another reconcile that passed the predicate filters and re-ran sync logic.
I moved the
maybeAddFinalizerlogic to run before setting status or performing sync logic. If a finalizer is added, we requeue and exit early. By doing this the generation bump caused by adding the finalizer is processed cleanly, and the reconcile won't proceed to status updates or sync logic prematurely.