Repository navigation
#9730 Clustering support #10249
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
Closed
Closed
#9730 Clustering support #10249
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a909d4
Service
8ea60bb
Service and discovery service
0546b4a
Service and discovery service
c06f2e4
Service and discovery service
cb220a9
Service and discovery service
4686703
Service and discovery service
4aa6a5d
Service and discovery service
8e774d5
Service and discovery service
ff1c886
Service and discovery service
d2e1aaa
Service and discovery service
8c6e6e1
Service and discovery service
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
operator/src/main/java/org/keycloak/operator/v2alpha1/KeycloakDiscoveryService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright 2021 Red Hat, Inc. and/or its affiliates | ||
| * and other contributors as indicated by the @author tags. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.keycloak.operator.v2alpha1; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.HasMetadata; | ||
| import io.fabric8.kubernetes.api.model.IntOrString; | ||
| import io.fabric8.kubernetes.api.model.Service; | ||
| import io.fabric8.kubernetes.api.model.ServiceBuilder; | ||
| import io.fabric8.kubernetes.api.model.ServiceSpec; | ||
| import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; | ||
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
| import org.keycloak.operator.Constants; | ||
| import org.keycloak.operator.OperatorManagedResource; | ||
| import org.keycloak.operator.v2alpha1.crds.Keycloak; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public class KeycloakDiscoveryService extends OperatorManagedResource { | ||
|
|
||
| public KeycloakDiscoveryService(KubernetesClient client, Keycloak keycloakCR) { | ||
| super(client, keycloakCR); | ||
| } | ||
|
|
||
| private ServiceSpec getServiceSpec() { | ||
| return new ServiceSpecBuilder() | ||
| .withSelector(Constants.DEFAULT_LABELS) | ||
| .addNewPort() | ||
| .withTargetPort(new IntOrString(Constants.KEYCLOAK_DISCOVERY_SERVICE_PORT)) | ||
| .withPort(Constants.KEYCLOAK_DISCOVERY_SERVICE_PORT) | ||
| .endPort() | ||
| .withClusterIP("None") | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Optional<HasMetadata> getReconciledResource() { | ||
| return Optional.of(fetchExistingService() | ||
| .map(a -> { | ||
| a.setSpec(getServiceSpec()); | ||
| return a; | ||
| }) | ||
| .orElse(newService())); | ||
| } | ||
|
|
||
| private Service newService() { | ||
| Service service = new ServiceBuilder() | ||
| .withNewMetadata() | ||
| .withName(getName()) | ||
| .withLabels(Constants.DEFAULT_LABELS) | ||
| .endMetadata() | ||
| .withSpec(getServiceSpec()) | ||
| .build(); | ||
| return service; | ||
| } | ||
|
|
||
| private Optional<Service> fetchExistingService() { | ||
| return Optional.ofNullable(client | ||
| .services() | ||
| .inNamespace(getNamespace()) | ||
| .withName(getName()) | ||
| .get()); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getName() { | ||
| return cr.getMetadata().getName() + "-discovery"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
operator/src/main/java/org/keycloak/operator/v2alpha1/KeycloakService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright 2021 Red Hat, Inc. and/or its affiliates | ||
| * and other contributors as indicated by the @author tags. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.keycloak.operator.v2alpha1; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.HasMetadata; | ||
| import io.fabric8.kubernetes.api.model.IntOrString; | ||
| import io.fabric8.kubernetes.api.model.Service; | ||
| import io.fabric8.kubernetes.api.model.ServiceBuilder; | ||
| import io.fabric8.kubernetes.api.model.ServiceSpec; | ||
| import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; | ||
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
| import org.keycloak.operator.Constants; | ||
| import org.keycloak.operator.OperatorManagedResource; | ||
| import org.keycloak.operator.v2alpha1.crds.Keycloak; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public class KeycloakService extends OperatorManagedResource { | ||
|
|
||
| public KeycloakService(KubernetesClient client, Keycloak keycloakCR) { | ||
| super(client, keycloakCR); | ||
| } | ||
|
|
||
| private ServiceSpec getServiceSpec() { | ||
| return new ServiceSpecBuilder() | ||
| .withSelector(Constants.DEFAULT_LABELS) | ||
| .addNewPort() | ||
| .withName(getName()) | ||
| .withTargetPort(new IntOrString(Constants.KEYCLOAK_SERVICE_PORT)) | ||
| .withPort(Constants.KEYCLOAK_SERVICE_PORT) | ||
| .withProtocol(Constants.KEYCLOAK_SERVICE_PROTOCOL) | ||
| .endPort() | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Optional<HasMetadata> getReconciledResource() { | ||
| return Optional.of(fetchExistingService() | ||
| .map(a -> { | ||
| a.setSpec(getServiceSpec()); | ||
| return a; | ||
| }) | ||
| .orElse(newService())); | ||
| } | ||
|
|
||
| private Service newService() { | ||
| Service service = new ServiceBuilder() | ||
| .withNewMetadata() | ||
| .withName(getName()) | ||
| .withLabels(Constants.DEFAULT_LABELS) | ||
| .endMetadata() | ||
| .withSpec(getServiceSpec()) | ||
| .build(); | ||
| return service; | ||
| } | ||
|
|
||
| private Optional<Service> fetchExistingService() { | ||
| return Optional.ofNullable(client | ||
| .services() | ||
| .inNamespace(getNamespace()) | ||
| .withName(getName()) | ||
| .get()); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return cr.getMetadata().getName()+"-service"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should probably reflect this in the CR's status. I'd probably call
addNotReadyMessageif a service is not found, similarly to:keycloak/operator/src/main/java/org/keycloak/operator/v2alpha1/KeycloakDeployment.java
Lines 148 to 152 in 8ea60bb