[SMG] Expand K8s integration tests: cross-namespace, lifecycle, multi-model (#24375)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kangyan-Zhou
2026-05-13 20:08:09 -07:00
committed by GitHub
co-authored by Claude Opus 4.7
parent e8d57e7243
commit 8b9ff4a68c
7 changed files with 1364 additions and 0 deletions
@@ -0,0 +1,79 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: smg-gateway-cluster
namespace: smg-test
spec:
replicas: 1
selector:
matchLabels:
app: smg-gateway-cluster
template:
metadata:
labels:
app: smg-gateway-cluster
spec:
serviceAccountName: smg-gateway-cluster
containers:
- name: gateway
image: smg-gateway:test
imagePullPolicy: Never
# No --service-discovery-namespace: watch all namespaces (Api::all
# in service_discovery.rs:279). Requires the ClusterRole defined in
# rbac-cluster-scoped.yaml.
#
# Selector includes `cross-ns-test=true` (in addition to the usual
# app=fake-worker) so this gateway only registers workers deployed
# by test_cross_namespace.py, not the app=fake-worker pods other
# tests deploy in smg-test. Without this, the exact-count assertion
# in the test would race with concurrent test files.
args:
- "--service-discovery"
- "--selector"
- "app=fake-worker"
- "cross-ns-test=true"
- "--service-discovery-port"
- "8000"
- "--port"
- "30002"
- "--prometheus-port"
- "29002"
- "--disable-health-check"
- "--worker-startup-timeout-secs"
- "30"
- "--log-level"
- "debug"
ports:
- containerPort: 30002
name: http
- containerPort: 29002
name: metrics
readinessProbe:
httpGet:
path: /liveness
port: 30002
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
httpGet:
path: /liveness
port: 30002
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: smg-gateway-cluster
namespace: smg-test
spec:
type: NodePort
selector:
app: smg-gateway-cluster
ports:
- name: http
port: 30002
targetPort: 30002
- name: metrics
port: 29002
targetPort: 29002
@@ -0,0 +1,148 @@
# Two gateways with disjoint --selector values to verify per-model isolation.
# Both watch the smg-test namespace, both use the namespace-scoped RBAC from
# rbac.yaml, but each only matches workers carrying its own `model=...` label.
apiVersion: apps/v1
kind: Deployment
metadata:
name: smg-gateway-llama
namespace: smg-test
spec:
replicas: 1
selector:
matchLabels:
app: smg-gateway-llama
template:
metadata:
labels:
app: smg-gateway-llama
spec:
serviceAccountName: smg-gateway
containers:
- name: gateway
image: smg-gateway:test
imagePullPolicy: Never
args:
- "--service-discovery"
- "--selector"
- "app=fake-worker"
- "model=llama"
- "--service-discovery-port"
- "8000"
- "--service-discovery-namespace"
- "smg-test"
- "--port"
- "30003"
- "--prometheus-port"
- "29003"
- "--disable-health-check"
- "--worker-startup-timeout-secs"
- "30"
- "--log-level"
- "debug"
ports:
- containerPort: 30003
name: http
- containerPort: 29003
name: metrics
readinessProbe:
httpGet:
path: /liveness
port: 30003
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
httpGet:
path: /liveness
port: 30003
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: smg-gateway-llama
namespace: smg-test
spec:
type: NodePort
selector:
app: smg-gateway-llama
ports:
- name: http
port: 30003
targetPort: 30003
- name: metrics
port: 29003
targetPort: 29003
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: smg-gateway-qwen
namespace: smg-test
spec:
replicas: 1
selector:
matchLabels:
app: smg-gateway-qwen
template:
metadata:
labels:
app: smg-gateway-qwen
spec:
serviceAccountName: smg-gateway
containers:
- name: gateway
image: smg-gateway:test
imagePullPolicy: Never
args:
- "--service-discovery"
- "--selector"
- "app=fake-worker"
- "model=qwen"
- "--service-discovery-port"
- "8000"
- "--service-discovery-namespace"
- "smg-test"
- "--port"
- "30004"
- "--prometheus-port"
- "29004"
- "--disable-health-check"
- "--worker-startup-timeout-secs"
- "30"
- "--log-level"
- "debug"
ports:
- containerPort: 30004
name: http
- containerPort: 29004
name: metrics
readinessProbe:
httpGet:
path: /liveness
port: 30004
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
httpGet:
path: /liveness
port: 30004
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: smg-gateway-qwen
namespace: smg-test
spec:
type: NodePort
selector:
app: smg-gateway-qwen
ports:
- name: http
port: 30004
targetPort: 30004
- name: metrics
port: 29004
targetPort: 29004
@@ -0,0 +1,83 @@
# Dedicated gateway used by the gateway-restart test in test_lifecycle.py.
# Runs on its own ports (30005/29005) so killing this gateway's pod does
# not invalidate the session-scoped port-forward against the default
# smg-gateway used by test_reconciliation.py.
#
# This gateway's selector requires `app=fake-worker,lifecycle=restart`, so
# pods from test_reconciliation.py (which carry only `app=fake-worker`) are
# ignored here. The default `smg-gateway` does still match this test's
# `lifecycle=restart` workers (its selector is the broader subset), but the
# restart test never queries port 30000 — it only reads from this gateway,
# so worker counts stay deterministic.
apiVersion: apps/v1
kind: Deployment
metadata:
name: smg-gateway-restart
namespace: smg-test
spec:
replicas: 1
selector:
matchLabels:
app: smg-gateway-restart
template:
metadata:
labels:
app: smg-gateway-restart
spec:
serviceAccountName: smg-gateway
containers:
- name: gateway
image: smg-gateway:test
imagePullPolicy: Never
args:
- "--service-discovery"
- "--selector"
- "app=fake-worker"
- "lifecycle=restart"
- "--service-discovery-port"
- "8000"
- "--service-discovery-namespace"
- "smg-test"
- "--port"
- "30005"
- "--prometheus-port"
- "29005"
- "--disable-health-check"
- "--worker-startup-timeout-secs"
- "30"
- "--log-level"
- "debug"
ports:
- containerPort: 30005
name: http
- containerPort: 29005
name: metrics
readinessProbe:
httpGet:
path: /liveness
port: 30005
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
httpGet:
path: /liveness
port: 30005
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: smg-gateway-restart
namespace: smg-test
spec:
type: NodePort
selector:
app: smg-gateway-restart
ports:
- name: http
port: 30005
targetPort: 30005
- name: metrics
port: 29005
targetPort: 29005
@@ -0,0 +1,30 @@
# Cluster-wide RBAC for the multi-namespace discovery test.
# Distinct ServiceAccount/ClusterRole names so it does not collide with the
# namespace-scoped Role in rbac.yaml that the default gateway uses.
apiVersion: v1
kind: ServiceAccount
metadata:
name: smg-gateway-cluster
namespace: smg-test
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: smg-gateway-cluster
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: smg-gateway-cluster
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: smg-gateway-cluster
subjects:
- kind: ServiceAccount
name: smg-gateway-cluster
namespace: smg-test