8000 fix: keeping the image consistent for the recreate strategy by shawkins · Pull Request #39714 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: keeping the image consistent for the recreate strategy #39714

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

Merged
merged 1 commit into from
May 14, 2025

Conversation

shawkins
Copy link
Contributor

closes: #39710

closes: keycloak#39710

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
@shawkins shawkins requested a review from pruivo May 14, 2025 12:22
@shawkins shawkins marked this pull request as ready for review May 14, 2025 13:36
@shawkins shawkins requested review from a team as code owners May 14, 2025 13:36
Comment on lines 582 to +585
desired.getMetadata().getAnnotations().put(Constants.KEYCLOAK_MIGRATING_ANNOTATION, Boolean.TRUE.toString());
desired.getSpec().setReplicas(0);
var currentImage = RecreateOnImageChangeUpdateLogic.extractImage(actual);
kcContainer.setImage(currentImage);
Copy link
Contributor
@pruivo pruivo May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of modifying the replicas in the desired, shouldn't we modify the replicas in the actual?

Edit: I'm asking because I'm concerned that the same incorrect behavior may happen if the user changes the configuration (i.e. the EnvVar)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of modifying the replicas in the desired, shouldn't we modify the replicas in the actual?

desired is what is actually being returned to the operator sdk. We don't want to use the actual as the desired. What we're effectively relying upon the controller behavior that honors the replica count first, then rolls out any changes in the statefulset spec.

Edit: I'm asking because I'm concerned that the same incorrect behavior may happen if the user changes the configuration (i.e. the EnvVar)

I don't follow that concern. This pr reinstates the recreate behavior we've always had. Are you thinking that there is some scenario where a change in the env will somehow be rolled out prior to the replica count being honored?

Alternative behavior would be working against the operator sdk / SSA - that is rather than honoring a desired state we'd have to directly isssue a patch against the actual.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking that there is some scenario where a change in the env will somehow be rolled out prior to the replica count being honored?

Yes exactly. Is that possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the controller will respect the replica reduction first - why restart the pods if you are just going to scale them down anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I don't understand why it does not respect the replica count when the image is different. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is with our logic if we don't keep the old image - the recreate stategy needs to see that difference. If it sees the new image on the actual, it will let the desired logic immediately set the replica count back to what is in the keycloak cr.

You could alternatively try to account for this in the recreate stategy logic - if the images are the same, but the actual statefulset spec has 0 replicas, and the status replicas are greater than 0, then keep using the recreate stategy. It seems simpler to just keep the desired image as the old image.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Gotcha! Sorry for being slow 😅 It makes sense now. Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

@shawkins shawkins requested a review from vmuzikar May 14, 2025 15:32
Copy link
Contributor
@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving based on previous review

@ahus1 ahus1 merged commit fdcd89c into keycloak:main May 14, 2025
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recreate update is not scaling down the statefulset to zero
3 participants
0