Skip to content

Commit

Permalink
add: support for a simple ingress in docs and a flexible ingress temp…
Browse files Browse the repository at this point in the history
…late
  • Loading branch information
ChrisMcKenzie committed Sep 28, 2024
1 parent ac2ca13 commit 499b6f2
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 14 deletions.
72 changes: 59 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,27 @@ which can be modified to suit your needs, install the chart:

This above command will install the Big Peer chart with the release name `ditto-bp`.

### Ingress
### Ports

For ingress to work, you will need to have a working ingress controller in your cluster.
and then you can create an ingress resource that points to the k8s service in your install called
ditto-bp-hydra-subscription and map to port `8080`.
We expose the following ports in the Big Peer chart via the service named `ditto-bp-hydra-subscription`:

If you are deploying to something like Kubernetes for Docker Desktop, you will have to port-forward port 8080 from the
ditto-bp-hydra-subscription service to your local machine.
```bash
kubectl port-forward svc/ditto-bp-hydra-subscription 8080
```
- 8080: The port for the Big Peer to listen on for incoming connections from Small Peers.
- 4040: The port for the Big Peer to listen on for incoming connections from other Big Peers.
- 10080: The port for the Big Peer to listen on for incoming HTTP API calls.

### Getting started in the cloud

If you are wanting to deploy a simple cloud environment that you can connect your small peers to.
We recommend creating a vm with a public ip in AWS, or your favorite cloud provider, and then following the guide
to install K3s on that vm. https://docs.k3s.io/quick-start

This will provide a simple kubernetes cluster that you can deploy
the Big Peer to following the same instructions above.

You can then set `ingress.enabled` to `true` and change the `ingress.hosts` to the ip of your vm or dns name if you have it.
This should leave you with a Big Peer that is accessible from the internet via `http://<ip>:80`

To Connect a small peer to your newly created big peer follow the instructions in the section below.

### Notes on dependencies

Expand All @@ -52,9 +61,13 @@ By default the following dependencies are enabled:
- [Strimzi Kafka Operator](https://strimzi.io/)
- [Cert Manager](https://github.com/cert-manager/cert-manager)

### Connecting to a Big Peer on my laptop
### Connecting to a Big Peer with a small peer

In order to connect to a Big Peer running on your laptop, you will need to expose the service to the host machine. via the above method of port forwarding.
If you are deploying to something like Kubernetes for Docker Desktop, you will have to port-forward port 8080 from the
ditto-bp-hydra-subscription service to your local machine.
```bash
kubectl port-forward svc/ditto-bp-hydra-subscription 8080
```

Next in your small peer client you will need to change a few configuration items to connect to the Big Peer running on your laptop.
these examples are in kotlin for Android but should work similarly for other platforms.
Expand All @@ -63,7 +76,7 @@ In your Ditto object you will need to setup an identity that looks like this.
```kotlin
OnlineWithAuthentication(
dependencies = androidDependencies,
appId = Constants.onlineAppId,
appId = "your-app-id",
customAuthUrl = "http://10.0.2.2:8080",
enableDittoCloudSync = true,
callback = AuthCallback(),
Expand Down Expand Up @@ -95,7 +108,8 @@ class AuthCallback: DittoAuthenticationCallback {
}
```

you will also need to setup the DittoTransportConfig to have a custom URL for the Big Peer.
You will also need to setup the DittoTransportConfig
to have a custom URL for the Big Peer.

```kotlin
val conf = DittoTransportConfig()
Expand All @@ -108,3 +122,35 @@ ditto?.let { ditto ->

```

### Big Peer to Big Peer communication

If you have two Big Peers running on your laptop and you want them to communicate with each other,
you will need to setup a few things.

You will have to know the "App ID" you intend to operator under.
This can be generated by creating a v4 UUID as long as it is the same for all of the peers in you network (Big and Small).

via the HTTP API (see the ports section we will make a few different calls.

```bash
curl -v --request POST \
--url http://<big-peer>:10080/${app_id}/sub/v1/peer/connections \
--header 'content-type: application/json' \
--data '{ "addr": "localhost:4040" }'
```

Next we will need to make a call to setup the subscription query so that we sync the data between the two peers.

```bash
curl -v --request POST \
--url http://<big-peer>:10080/${app_id}/sub/v1/peer/subscriptions \
--header 'content-type: application/json' \
--data '{
"queries": {
"my_collection": ["true"]
}
}'

```

We should now see the two peers syncing data between each other.
2 changes: 1 addition & 1 deletion charts/big-peer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ home: https://docs.ditto.live/
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
39 changes: 39 additions & 0 deletions charts/big-peer/templates/_ingress.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{/* Renders the Ingress objects required by the chart */}}
{{- define "common.ingress" -}}
{{- /* Generate named ingresses as required */ -}}
{{- range $name, $ingress := .Values.ingress }}
{{- if $ingress.enabled -}}
{{- $ingressValues := $ingress -}}

{{/* set defaults */}}
{{- if and (not $ingressValues.nameOverride) (ne $name (include "common.ingress.primary" $)) -}}
{{- $_ := set $ingressValues "nameOverride" $name -}}
{{- end -}}

{{- $_ := set $ "ObjectValues" (dict "ingress" $ingressValues) -}}
{{- include "common.classes.ingress" $ }}
{{- end }}
{{- end }}
{{- end }}

{{/* Return the name of the primary ingress object */}}
{{- define "common.ingress.primary" -}}
{{- $enabledIngresses := dict -}}
{{- range $name, $ingress := .Values.ingress -}}
{{- if $ingress.enabled -}}
{{- $_ := set $enabledIngresses $name . -}}
{{- end -}}
{{- end -}}

{{- $result := "" -}}
{{- range $name, $ingress := $enabledIngresses -}}
{{- if and (hasKey $ingress "primary") $ingress.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}

{{- if not $result -}}
{{- $result = keys $enabledIngresses | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}
1 change: 1 addition & 0 deletions charts/big-peer/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ include "common.ingress" . }}
56 changes: 56 additions & 0 deletions charts/big-peer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,62 @@ global:
tolerations: []
affinity: {}

# -- Configure the ingresses for the chart here.
# Additional ingresses can be added by adding a dictionary key similar to the 'main' ingress.
# @default -- See below
ingress:
main:
# -- Enables or disables the ingress
enabled: false

# -- Make this the primary ingress (used in probes, notes, etc...).
# If there is more than 1 ingress, make sure that only 1 ingress is marked as primary.
primary: true

# -- Override the name suffix that is used for this ingress.
nameOverride:

# -- Provide additional annotations which may be required.
annotations: {}
# kubernetes.io/ingress.class: traefik
# kubernetes.io/tls-acme: "true"

# -- Provide additional labels which may be required.
labels: {}

# -- Set the ingressClass that is used for this ingress.
# Requires Kubernetes >=1.19
ingressClassName: # "traefik"

## Configure the hosts for the ingress
hosts:
- # -- Host address. Helm template can be passed.
host: chart-example.local
## Configure the paths for the host
paths:
- # -- path. helm template can be passed.
path: /_ditto
# -- ignored if not kubeversion >= 1.14-0
pathtype: prefix
service:
# -- overrides the service name reference for this path
name: ditto-bp-hydra-subscription
# -- overrides the service port reference for this path
port: 8080

- # -- path. helm template can be passed.
path: /
# -- ignored if not kubeversion >= 1.14-0
pathtype: prefix
service:
# -- overrides the service name reference for this path
name: ditto-bp-hydra-subscription
# -- overrides the service port reference for this path
port: 10080

# -- Configure TLS for the ingress. Both secretName and hosts can process a Helm template.
tls: []

########################################################################
# Hades Default Values
# Custom Resource Definitions
Expand Down

0 comments on commit 499b6f2

Please sign in to comment.