8000 fix: adding the discovery servicename to the statefulset by shawkins · Pull Request #39419 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: adding the discovery servicename to the statefulset #39419

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 6, 2025

Conversation

shawkins
Copy link
Contributor
@shawkins shawkins commented May 2, 2025

closes: #38757

closes: keycloak#38757

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
@shawkins shawkins requested review from a team as code owners May 2, 2025 14:39
@shawkins
Copy link
Contributor Author
shawkins commented May 2, 2025

Double checked locally that it doesn't matter what order the statefulset and service are created in - kube / minikube will create the statefulset just fine without the service in existence, and it won't cause a restart to create it after the fact.

@@ -287,6 +287,7 @@ private StatefulSet createBaseDeployment(Keycloak keycloakCR, Context<Keycloak>
.editOrNewSpec().withImagePullSecrets(keycloakCR.getSpec().getImagePullSecrets()).endSpec()
.endTemplate()
.withReplicas(keycloakCR.getSpec().getInstances())
.withServiceName(KeycloakDiscoveryServiceDependentResource.getName(keycloakCR))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it rather use the main service?

Suggested change
.withServiceName(KeycloakDiscoveryServiceDependentResource.getName(keycloakCR))
.withServiceName(KeycloakServiceDependentResource.getServiceName(keycloakCR))

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, it's supposed to be a headless service.

Copy link
Contributor
@vmuzikar vmuzikar May 5, 2025

Choose a reason for hiding this comment

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

From the docs it does not seem so?

Additionally it says:

This service must exist before the StatefulSet

Despite it now works with StS created before the Service, can we really rely on it as that behaviour might change to align with the spec?

Copy link
Contributor Author
@shawkins shawkins May 5, 2025

Choose a reason for hiding this comment

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

From the docs it does not seem so?

I'm referencing https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id

I suppose the language there does say "can", not "must" be headless.

Despite it now works with StS created before the Service, can we really rely on 8000 it as that behaviour might change to align with the spec?

This behavior / validation has been poorly defined for quite some time. kubernetes/kubernetes#69608 was logged years ago.

Even if it doesn't "work" at some point in the furture, the worst case behavior would be the statefulset not scaling up until the service is created - since these are peer dependent resources, that would be a narrow window.

I'm leary of adding any kind of reconciliation condition for this kind of behavior - instead if you are worried about not eventually seeing some kind of ephemeral error, then I'd opt instead for Dependent.dependsOn

Copy link
Contributor
@vmuzikar vmuzikar May 6, 2025

Choose a reason for hiding this comment

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

I'm referencing https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id

I suppose the language there does say "can", not "must" be headless.

I see. Well, it says headless service so probably there's no going around it. However, it feels a bit odd to me that the KC Pod's DNS records would be derived from the Discovery Service. Moreover, what if we switch to the JDBC ping in the future, so that Service is not needed anymore?

But it's not a blocker for me, I don't have a better idea. We might create a dedicated headlessService just for this purpose but that seems like an overkill at this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if it doesn't "work" at some point in the furture, the worst case behavior would be the statefulset not scaling up until the service is created - since these are peer dependent resources, that would be a narrow window.

Makes sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might create a dedicated headlessService just for this purpose but that seems like an overkill at this point.

I think we'd just leave the discovery service in place. There's not much harm / risk and users may have already adopted using it for their own purposes as well.

Copy link
Contributor
@vmuzikar vmuzikar left a comment

Choose a reason for hiding this comment

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

LGTM as I don't have a better solution in mind. Thanks @shawkins.

@shawkins shawkins merged commit 16c747b into keycloak:main May 6, 2025
76 checks passed
InJoDave pushed a commit to InJoDave/keycloak that referenced this pull request May 6, 2025
)

closes: keycloak#38757

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
shawkins added a commit to shawkins/keycloak that referenced this pull request May 7, 2025
)

closes: keycloak#38757

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
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.

Keycloak statefulset is not mapped to any headless service if installed via operator
2 participants
0