Skip to content

Commit

Permalink
Add WebView Support #296 (#298)
Browse files Browse the repository at this point in the history
* add ingressHostnamePrefixes to AppDefinition
* update ingress rules with additional values from ingressHostnamePrefixes
  • Loading branch information
jfaltermeier authored Jun 17, 2024
1 parent 5dd68d9 commit 5a5538b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Extend configuration options for the new landing page for texts and logo file type
- Removed terms and conditions
- Build the common package as ESM and CJS bundles for extended compatibility
- [common] Add `ingressHostnamePrefixes` list to `AppDefinition.v1beta10` [#298](https://github.com/eclipsesource/theia-cloud/pull/298) | [#57](https://github.com/eclipsesource/theia-cloud-helm/pull/57)

## [0.10.0] - 2024-04-02

Expand Down
11 changes: 11 additions & 0 deletions documentation/LocalCertificates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Installing the self signed CA for local testing

When testing locally you usually have to accept the self signed certificate in your browser. When working with wildcard certificates however, as used by e.g. the default webview hostnames, you usually will get an error with no way to accept the certificate.

You may import the self-signed CA in your browser however. You may export the secret to an importable file like this:

```bash
kubectl get secret theia-cloud-ca-key-pair -n cert-manager -o jsonpath='{.data.tls\.crt}' | base64 --decode > ca.crt
```

Then, e.g. in Chrome, got to <chrome://settings/certificates> and Add Authority.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
********************************************************************************/
package org.eclipse.theia.cloud.common.k8s.resource.appdefinition;

import java.util.List;
import java.util.Map;

import org.eclipse.theia.cloud.common.k8s.resource.appdefinition.hub.AppDefinitionHub;
Expand Down Expand Up @@ -83,6 +84,9 @@ public class AppDefinitionSpec {
@JsonProperty("options")
private Map<String, String> options;

@JsonProperty("ingressHostnamePrefixes")
private List<String> ingressHostnamePrefixes;

/**
* Default constructor.
*/
Expand Down Expand Up @@ -110,6 +114,7 @@ public AppDefinitionSpec(AppDefinitionHub fromHub) {
this.timeout = fromHub.getTimeoutLimit().orElse(0);

this.options = fromHub.getOptions().orElse(null);
this.ingressHostnamePrefixes = fromHub.getIngressHostnamePrefixes().orElse(null);

int monitorPort = fromHub.getMonitorPort().orElse(0);
if (monitorPort > 0) {
Expand Down Expand Up @@ -201,6 +206,10 @@ public Map<String, String> getOptions() {
return options;
}

public List<String> getIngressHostnamePrefixes() {
return ingressHostnamePrefixes;
}

@Override
public String toString() {
return "AppDefinitionSpec [name=" + name + ", image=" + image + ", imagePullPolicy=" + imagePullPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/
package org.eclipse.theia.cloud.common.k8s.resource.appdefinition.hub;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class AppDefinitionHub {
final OptionalInt downlinkLimit;// kilobits per second
final OptionalInt uplinkLimit;// kilobits per second
final Optional<String> mountPath;
final Optional<List<String>> ingressHostnamePrefixes;

final OptionalInt timeoutLimit;
@Deprecated
Expand Down Expand Up @@ -75,6 +77,7 @@ public AppDefinitionHub(AppDefinition toHub) {
this.uplinkLimit = OptionalInt.of(toHub.getSpec().getUplinkLimit());
this.mountPath = Optional.ofNullable(toHub.getSpec().getMountPath());
this.options = Optional.ofNullable(toHub.getSpec().getOptions());
this.ingressHostnamePrefixes = Optional.ofNullable(toHub.getSpec().getIngressHostnamePrefixes());

this.timeoutLimit = OptionalInt.of(toHub.getSpec().getTimeout());

Expand Down Expand Up @@ -126,6 +129,7 @@ public AppDefinitionHub(
this.uplinkLimit = OptionalInt.of(toHub.getSpec().getUplinkLimit());
this.mountPath = Optional.ofNullable(toHub.getSpec().getMountPath());
this.options = Optional.empty();
this.ingressHostnamePrefixes = Optional.empty();

this.timeoutLimit = OptionalInt.of(toHub.getSpec().getTimeout());

Expand Down Expand Up @@ -177,6 +181,7 @@ public AppDefinitionHub(
this.uplinkLimit = OptionalInt.of(toHub.getSpec().getUplinkLimit());
this.mountPath = Optional.ofNullable(toHub.getSpec().getMountPath());
this.options = Optional.empty();
this.ingressHostnamePrefixes = Optional.empty();

if (toHub.getSpec().getTimeout() != null) {
this.timeoutLimit = OptionalInt.of(toHub.getSpec().getTimeout().getLimit());
Expand Down Expand Up @@ -313,4 +318,8 @@ public Optional<Map<String, String>> getOptions() {
return options;
}

public Optional<List<String>> getIngressHostnamePrefixes() {
return ingressHostnamePrefixes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -465,34 +466,45 @@ protected void addVolumeClaim(Deployment deployment, String pvcName, AppDefiniti

protected synchronized String updateIngress(Optional<Ingress> ingress, Optional<Service> serviceToUse,
Session session, AppDefinition appDefinition, String correlationId) {
final String host = arguments.getInstancesHost();
List<String> hostsToAdd = new ArrayList<>();
final String instancesHost = arguments.getInstancesHost();
hostsToAdd.add(instancesHost);
List<String> ingressHostnamePrefixes = appDefinition.getSpec().getIngressHostnamePrefixes() != null
? appDefinition.getSpec().getIngressHostnamePrefixes()
: Collections.emptyList();
for (String prefix : ingressHostnamePrefixes) {
hostsToAdd.add(prefix + instancesHost);
}
String path = ingressPathProvider.getPath(appDefinition, session);
client.ingresses().edit(correlationId, ingress.get().getMetadata().getName(), ingressToUpdate -> {
IngressRule ingressRule = new IngressRule();
ingressToUpdate.getSpec().getRules().add(ingressRule);
for (String host : hostsToAdd) {
IngressRule ingressRule = new IngressRule();
ingressToUpdate.getSpec().getRules().add(ingressRule);

ingressRule.setHost(host);

ingressRule.setHost(host);
HTTPIngressRuleValue http = new HTTPIngressRuleValue();
ingressRule.setHttp(http);

HTTPIngressRuleValue http = new HTTPIngressRuleValue();
ingressRule.setHttp(http);
HTTPIngressPath httpIngressPath = new HTTPIngressPath();
http.getPaths().add(httpIngressPath);
httpIngressPath.setPath(path + AddedHandlerUtil.INGRESS_REWRITE_PATH);
httpIngressPath.setPathType("Prefix");

HTTPIngressPath httpIngressPath = new HTTPIngressPath();
http.getPaths().add(httpIngressPath);
httpIngressPath.setPath(path + AddedHandlerUtil.INGRESS_REWRITE_PATH);
httpIngressPath.setPathType("Prefix");
IngressBackend ingressBackend = new IngressBackend();
httpIngressPath.setBackend(ingressBackend);

IngressBackend ingressBackend = new IngressBackend();
httpIngressPath.setBackend(ingressBackend);
IngressServiceBackend ingressServiceBackend = new IngressServiceBackend();
ingressBackend.setService(ingressServiceBackend);
ingressServiceBackend.setName(serviceToUse.get().getMetadata().getName());

IngressServiceBackend ingressServiceBackend = new IngressServiceBackend();
ingressBackend.setService(ingressServiceBackend);
ingressServiceBackend.setName(serviceToUse.get().getMetadata().getName());
ServiceBackendPort serviceBackendPort = new ServiceBackendPort();
ingressServiceBackend.setPort(serviceBackendPort);
serviceBackendPort.setNumber(appDefinition.getSpec().getPort());
}

ServiceBackendPort serviceBackendPort = new ServiceBackendPort();
ingressServiceBackend.setPort(serviceBackendPort);
serviceBackendPort.setNumber(appDefinition.getSpec().getPort());
});
return host + path + "/";
return instancesHost + path + "/";
}

@Override
Expand Down

0 comments on commit 5a5538b

Please sign in to comment.