Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ jobs:
eventing: "0"
extras: "0"
release_gates: "0"
worker_workspace: "1"
- name: node-eventing
suite: runtime
examples: hello-nodejs
Expand Down Expand Up @@ -923,6 +924,7 @@ jobs:
LAMPYR_CI_RUNTIME_EXTRAS: ${{ matrix.extras }}
LAMPYR_CI_RELEASE_GATES: ${{ matrix.release_gates }}
LAMPYR_CI_MODE_CHECKS: ${{ matrix.mode_checks || 'all' }}
LAMPYR_CI_WORKER_WORKSPACE: ${{ matrix.worker_workspace || '0' }}
LAMPYR_CLUSTER_INPUTS: ${{ github.workspace }}/build/cluster-inputs
run: just test-kind-runtime-integration-prebuilt

Expand Down
6 changes: 6 additions & 0 deletions docs/cli/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ python3 tests/contracts/test_worker_workspace.py \
--url https://YOUR_CLUSTER_INGRESS --host worker-api.default.YOUR_DOMAIN
```

To also check processor and reused services through ingress, expose all three
services in `ingress.services`, redeploy them, and add `--direct-services`.
Each request uses its service hostname for TLS SNI, certificate checks, and
HTTP Host. An optional hostname port stays in HTTP Host, not TLS SNI.
`--url` sets the connection address and port; `--host` does not change them.

Only for a test cluster with a self-signed certificate, add `--insecure`.
The runner checks fresh state, bindings, event content, explicit reuse and
idle reset, errors, streaming, and client cancellation. The unchanged runner
Expand Down
29 changes: 29 additions & 0 deletions scripts/test-kind-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ if [[ "$suite" == "full" || "$suite" == "runtime" ]]; then
rm -rf "$project/services/$service/.lampyr"
sed -i 's/^ cpu: 250m$/ cpu: 10m/' "$project/services/$service/lampyr.yaml"
done
if [[ "${LAMPYR_CI_WORKER_WORKSPACE:-0}" == 1 ]]; then
for service in api processor reused; do
cp -a "$repo_root/demos/local-worker-workspace/services/$service" \
"$project/services/worker-$service"
done
fi
expose_workspace_services "$project"
"$repo_root/build/ly" build "$project"
phase_done "build runtime examples"
Expand Down Expand Up @@ -637,6 +643,26 @@ print(fiberd_grants.router_fibers_busy(sys.argv[2], sys.argv[3]))
done
}

run_worker_workspace_checks() {
local service
for service in worker-processor worker-reused worker-api; do
current_service=$service
"$repo_root/build/ly" deploy --context "$context" \
--image "$images/$service:$tag" "$project/services/$service"
done
kubectl --context "$context" -n kourier-system get secret lampyr-kourier-tls \
-o 'jsonpath={.data.tls\.crt}' | base64 --decode > "$project/ingress-trust.pem"
SSL_CERT_FILE="$project/ingress-trust.pem" \
python3 "$repo_root/tests/contracts/test_worker_workspace.py" \
--url "https://127.0.0.1:$https_port" \
--host "worker-api.default.localhost:$https_port" \
--direct-services
for service in worker-api worker-processor worker-reused; do
"$repo_root/build/ly" delete --context "$context" "$project/services/$service"
done
phase_done "verify worker workspace through trusted HTTPS ingress"
}

run_runtime_mode_checks() {
reuse_dir="$project/services/reuse-mode"
mkdir -p "$reuse_dir"
Expand Down Expand Up @@ -809,6 +835,9 @@ fi

if [[ "$suite" == "full" || "$suite" == "runtime" ]]; then
run_runtime_checks
if [[ "${LAMPYR_CI_WORKER_WORKSPACE:-0}" == 1 ]]; then
run_worker_workspace_checks
fi
fi

if [[ "$runtime_extras" == 1 ]]; then
Expand Down
116 changes: 116 additions & 0 deletions scripts/tests/test_worker_workspace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python3

import importlib.util
import json
import pathlib
import sys
import unittest
from unittest import mock
import urllib.parse
Expand All @@ -17,6 +19,120 @@


class WorkerWorkspaceConnectionTests(unittest.TestCase):
def test_direct_requests_use_sibling_tls_identity(self):
cases = (
("https://worker-api.default.example.com:8443", None, ":8443"),
("https://127.0.0.1:8443", "worker-api.default.example.com:9443", ":9443"),
("https://127.0.0.1:8443", "worker-api.default.example.com", ""),
)
for url, override, port in cases:
with self.subTest(host=override):
requests = self.run_contract(url, override)
for service, count in (("worker-processor", 2), ("worker-reused", 2)):
with self.subTest(service=service):
hostname = f"{service}.default.example.com"
direct = [
request
for request in requests
if request["host"] == f"{hostname}{port}"
]
self.assertEqual(len(direct), count)
for request in direct:
self.assertEqual(
request["address"], urllib.parse.urlsplit(url).hostname
)
self.assertEqual(request["port"], 8443)
self.assertEqual(request["tls_hostname"], hostname)

def test_direct_http_requests_keep_native_destination(self):
requests = self.run_contract("http://127.0.0.1:8080")
for service in ("worker-processor", "worker-reused"):
direct = [
request
for request in requests
if request["host"] == f"{service}.default.localhost"
]
self.assertEqual(len(direct), 2)
for request in direct:
self.assertEqual(request["address"], "127.0.0.1")
self.assertEqual(request["port"], 8080)
self.assertIsNone(request["tls_hostname"])

def run_contract(self, url, host=None):
replies = [
{"count": 1, "fiberId": "root-1"},
{"count": 1, "fiberId": "root-2"},
{"kind": "http", "count": 1, "fiberId": "processor-1"},
{"kind": "http", "count": 1, "fiberId": "processor-2"},
{
"kind": "event", "id": "worker-demo", "count": 1,
"data": {"message": "hello from HTTP ingress"}, "fiberId": "event",
},
{"count": 1, "fiberId": "reused"},
{"count": 2, "fiberId": "reused"},
{"count": 1, "fiberId": "reset"},
None, None, None, None,
{"count": 1, "fiberId": "after-cancel"},
]
statuses = [200] * len(replies)
statuses[8:10] = [500, 502]
if url.startswith("http:"):
replies.append(None)
statuses.append(404)
replies.extend([
{"kind": "http", "count": 1, "fiberId": "direct-processor-1"},
{"kind": "http", "count": 1, "fiberId": "direct-processor-2"},
{"count": 1},
{"count": 2},
])
statuses.extend([200] * 4)
responses = []
for reply, status in zip(replies, statuses):
response = mock.Mock(status=status)
response.read.return_value = json.dumps(reply).encode()
response.getheader.return_value = None
responses.append(response)
responses[10].read.return_value = b"start\nend\n"
responses[10].getheader.return_value = "text/plain"
responses[11].readline.return_value = b"start\n"
requests = []
context = CONTRACT.ssl.create_default_context()

def send(connection, method, path, headers):
connection.connect()
requests.append({
"address": connection.host,
"port": connection.port,
"host": headers["Host"],
"tls_hostname": (
wrap_socket.call_args.kwargs["server_hostname"]
if isinstance(connection, CONTRACT.IngressHTTPSConnection)
else None
),
})

argv = ["test_worker_workspace.py", "--url", url, "--direct-services"]
if host is not None:
argv.extend(["--host", host])
with (
mock.patch.object(sys, "argv", argv),
mock.patch.object(CONTRACT.ssl, "create_default_context", return_value=context),
mock.patch.object(context, "wrap_socket", return_value=mock.Mock()) as wrap_socket,
mock.patch.object(CONTRACT.http.client.HTTPConnection, "connect"),
mock.patch.object(
CONTRACT.http.client.HTTPConnection, "request",
autospec=True, side_effect=send,
),
mock.patch.object(
CONTRACT.http.client.HTTPConnection, "getresponse", side_effect=responses,
),
mock.patch.object(CONTRACT.time, "sleep"),
mock.patch.object(CONTRACT.time, "monotonic", side_effect=[0, 2]),
mock.patch("builtins.print"),
):
CONTRACT.main()
return requests

def test_https_host_override_is_used_for_tls_identity(self):
base = urllib.parse.urlsplit("https://127.0.0.1:8443")
context = mock.Mock()
Expand Down
6 changes: 3 additions & 3 deletions tests/contracts/test_worker_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def main():
assert base.scheme in ("http", "https") and base.hostname
hostname = args.host or ("worker-api.default.localhost" if base.scheme == "http" else base.netloc)

def connect():
return open_connection(base, hostname, args.insecure)
def connect(host=None):
return open_connection(base, host or hostname, args.insecure)

def request(path, status=200, host=None, content_type=False):
connection = connect()
connection = connect(host)
connection.request("GET", path, headers={"Host": host or hostname})
response = connection.getresponse()
body = response.read()
Expand Down
Loading