-
Notifications
You must be signed in to change notification settings - Fork 27
[WIP] [Operator] Add Route #2418
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
Draft
jankalinic
wants to merge
7
commits into
streamshub:main
Choose a base branch
from
jankalinic:route-ingress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ac7ea5
[WIP] operator route
jankalinic 624845b
[WIP] operator route - fix
jankalinic 847c001
[WIP] operator route - fix2
jankalinic 60e099f
[WIP] operator route - fix2
jankalinic 9475f76
[WIP] operator route-working dev
jankalinic 3324ae5
add rbac for routes and custom hostname
jankalinic 767879d
throw error for no hostname on ingress and remove nativeAPI routes.op…
jankalinic 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
90 changes: 90 additions & 0 deletions
90
operator/src/main/java/com/github/streamshub/console/dependents/ConsoleRoute.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,90 @@ | ||
| package com.github.streamshub.console.dependents; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.inject.Inject; | ||
|
|
||
| import com.github.streamshub.console.api.v1alpha1.Console; | ||
|
|
||
| import io.fabric8.openshift.api.model.Route; | ||
| import io.fabric8.openshift.api.model.RouteBuilder; | ||
| import io.fabric8.openshift.api.model.RouteTargetReferenceBuilder; | ||
| import io.fabric8.openshift.api.model.TLSConfigBuilder; | ||
| import io.javaoperatorsdk.operator.api.config.informer.Informer; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
| import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
| import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; | ||
| import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; | ||
| import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @ApplicationScoped | ||
| @KubernetesDependent(informer = @Informer(labelSelector = ConsoleResource.MANAGEMENT_SELECTOR)) | ||
| public class ConsoleRoute extends CRUDKubernetesDependentResource<Route, Console> | ||
| implements ConsoleResource<Route> { | ||
|
|
||
| public static final String NAME = "console-route"; | ||
|
|
||
| @Inject | ||
| ConsoleService service; | ||
|
|
||
| public ConsoleRoute() { | ||
| super(Route.class); | ||
| } | ||
|
|
||
| @Override | ||
| public String resourceName() { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Route> getSecondaryResource(Console primary, Context<Console> context) { | ||
| return ConsoleResource.super.getSecondaryResource(primary, context); | ||
| } | ||
|
|
||
| @Override | ||
| protected Route desired(Console primary, Context<Console> context) { | ||
| String host = primary.getSpec().getHostname(); | ||
jankalinic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String serviceName = service.instanceName(primary); | ||
|
|
||
| // Store the URL so ConsoleDeployment can use it for NEXTAUTH_URL | ||
| setAttribute(context, INGRESS_URL_KEY, "https://" + host); | ||
|
|
||
| return new RouteBuilder() | ||
| .withNewMetadata() | ||
| .withName(instanceName(primary)) | ||
| .withNamespace(primary.getMetadata().getNamespace()) | ||
| .withLabels(commonLabels("console")) | ||
| .endMetadata() | ||
| .withNewSpec() | ||
| .withHost(host) | ||
| .withTo(new RouteTargetReferenceBuilder() | ||
| .withKind("Service") | ||
| .withName(serviceName) | ||
| .withWeight(100) | ||
| .build()) | ||
| .withNewPort() | ||
| .withNewTargetPort("https") | ||
jankalinic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .endPort() | ||
| .withTls(new TLSConfigBuilder() | ||
| .withTermination("edge") | ||
| .withInsecureEdgeTerminationPolicy("Redirect") | ||
| .build()) | ||
| .endSpec() | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Reconcile precondition: only create the Route when the cluster supports | ||
| * OpenShift Route resources (i.e. OpenShift / MicroShift). | ||
| */ | ||
| @ApplicationScoped | ||
| public static class Precondition implements Condition<Route, Console> { | ||
jankalinic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| public boolean isMet(DependentResource<Route, Console> dependentResource, | ||
| Console primary, | ||
| Context<Console> context) { | ||
| return context.getClient().supports(Route.class); | ||
| } | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
...rc/main/java/com/github/streamshub/console/dependents/conditions/RouteReadyCondition.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,50 @@ | ||
| package com.github.streamshub.console.dependents.conditions; | ||
|
|
||
| import com.github.streamshub.console.api.v1alpha1.Console; | ||
| import io.fabric8.openshift.api.model.Route; | ||
| import io.fabric8.openshift.api.model.RouteIngress; | ||
| import io.fabric8.openshift.api.model.RouteIngressCondition; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
| import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
| import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; | ||
| import org.jboss.logging.Logger; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public class RouteReadyCondition implements Condition<Route, Console> { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(RouteReadyCondition.class); | ||
|
|
||
| @Override | ||
| public boolean isMet(DependentResource<Route, Console> dependentResource, | ||
| Console primary, | ||
| Context<Console> context) { | ||
| return dependentResource.getSecondaryResource(primary, context) | ||
| .map(this::isReady) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| private boolean isReady(Route route) { | ||
| // A Route is ready when at least one ingress entry carries an | ||
| // Admitted=True condition — this is how the OpenShift router signals | ||
| // that it has picked up the route (works on both full OCP and MicroShift). | ||
| boolean ready = Optional.ofNullable(route.getStatus()) | ||
| .map(s -> s.getIngress()) | ||
| .filter(list -> !list.isEmpty()) | ||
| .map(ingresses -> ingresses.stream().anyMatch(this::isAdmitted)) | ||
| .orElse(false); | ||
|
|
||
| LOGGER.debugf("Route %s ready: %s", route.getMetadata().getName(), ready); | ||
| return ready; | ||
| } | ||
|
|
||
| private boolean isAdmitted(RouteIngress ingress) { | ||
| return Optional.ofNullable(ingress.getConditions()) | ||
| .map(conditions -> conditions.stream().anyMatch(this::admittedTrue)) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| private boolean admittedTrue(RouteIngressCondition condition) { | ||
| return "Admitted".equals(condition.getType()) && "True".equals(condition.getStatus()); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.