Files
cozystack/packages/apps/mongodb/tests/external-svc_test.yaml
T
Myasnikov Daniil 8358c04ce9 fix(mongodb): expose replica-set members per pod for external access (#2514)
A single LoadBalancer selecting all replset members round-robined writes
across primary and secondaries, so ~⅔ of writes failed with "not primary".
Drivers couldn't auto-recover either: `isMaster` returned in-cluster DNS
names that don't resolve from outside.

Switch to the Percona operator's native `replsets[].expose` so it creates
one LoadBalancer per pod and rewrites `rs.conf` with the external IPs;
the driver then discovers the primary correctly via the standard replica
set connection string. The manual `external-svc.yaml` is now scoped to
sharded mode (mongos front-end) only.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-04-28 17:06:07 +05:00

123 lines
2.6 KiB
YAML

suite: external service tests
templates:
- templates/external-svc.yaml
tests:
###################
# Rendering #
###################
- it: does not render when external is false
release:
name: test-mongodb
namespace: tenant-test
set:
external: false
asserts:
- hasDocuments:
count: 0
- it: does not render in replica-set mode (operator handles per-pod LBs via replsets[].expose)
release:
name: test-mongodb
namespace: tenant-test
set:
external: true
sharding: false
asserts:
- hasDocuments:
count: 0
- it: renders single LoadBalancer in sharded mode (mongos front-end)
release:
name: test-mongodb
namespace: tenant-test
set:
external: true
sharding: true
asserts:
- hasDocuments:
count: 1
- isKind:
of: Service
###################
# Service config #
###################
- it: uses correct service name
release:
name: mydb
namespace: tenant-test
set:
external: true
sharding: true
asserts:
- equal:
path: metadata.name
value: mydb-external
- it: sets LoadBalancer type
release:
name: test-mongodb
namespace: tenant-test
set:
external: true
sharding: true
asserts:
- equal:
path: spec.type
value: LoadBalancer
- it: sets externalTrafficPolicy to Local
release:
name: test-mongodb
namespace: tenant-test
set:
external: true
sharding: true
asserts:
- equal:
path: spec.externalTrafficPolicy
value: Local
- it: exposes MongoDB port 27017
release:
name: test-mongodb
namespace: tenant-test
set:
external: true
sharding: true
asserts:
- equal:
path: spec.ports[0].name
value: mongodb
- equal:
path: spec.ports[0].port
value: 27017
###########################
# Sharded selector #
###########################
- it: targets mongos pods only
release:
name: test-mongodb
namespace: tenant-test
set:
external: true
sharding: true
asserts:
- equal:
path: spec.selector["app.kubernetes.io/name"]
value: percona-server-mongodb
- equal:
path: spec.selector["app.kubernetes.io/instance"]
value: test-mongodb
- equal:
path: spec.selector["app.kubernetes.io/component"]
value: mongos
- notExists:
path: spec.selector["app.kubernetes.io/replset"]