From 499b6f2c28c784592fd9e687087b1973ab91818b Mon Sep 17 00:00:00 2001 From: ChrisMcKenzie Date: Fri, 27 Sep 2024 19:03:38 -0500 Subject: [PATCH] add: support for a simple ingress in docs and a flexible ingress template --- README.md | 72 +++++++++++++++++++++----- charts/big-peer/Chart.yaml | 2 +- charts/big-peer/templates/_ingress.tpl | 39 ++++++++++++++ charts/big-peer/templates/ingress.yaml | 1 + charts/big-peer/values.yaml | 56 ++++++++++++++++++++ 5 files changed, 156 insertions(+), 14 deletions(-) create mode 100644 charts/big-peer/templates/_ingress.tpl create mode 100644 charts/big-peer/templates/ingress.yaml diff --git a/README.md b/README.md index ade97c2..e420345 100644 --- a/README.md +++ b/README.md @@ -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://:80` + +To Connect a small peer to your newly created big peer follow the instructions in the section below. ### Notes on dependencies @@ -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. @@ -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(), @@ -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() @@ -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://: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://: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. diff --git a/charts/big-peer/Chart.yaml b/charts/big-peer/Chart.yaml index 68e3745..adc963a 100644 --- a/charts/big-peer/Chart.yaml +++ b/charts/big-peer/Chart.yaml @@ -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 diff --git a/charts/big-peer/templates/_ingress.tpl b/charts/big-peer/templates/_ingress.tpl new file mode 100644 index 0000000..b14e170 --- /dev/null +++ b/charts/big-peer/templates/_ingress.tpl @@ -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 -}} diff --git a/charts/big-peer/templates/ingress.yaml b/charts/big-peer/templates/ingress.yaml new file mode 100644 index 0000000..8f87c68 --- /dev/null +++ b/charts/big-peer/templates/ingress.yaml @@ -0,0 +1 @@ +{{ include "common.ingress" . }} diff --git a/charts/big-peer/values.yaml b/charts/big-peer/values.yaml index 3cc2733..ce12782 100644 --- a/charts/big-peer/values.yaml +++ b/charts/big-peer/values.yaml @@ -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