-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_k8s_deploy.py
More file actions
210 lines (176 loc) · 5.9 KB
/
test_k8s_deploy.py
File metadata and controls
210 lines (176 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
"""
Test script for Kubernetes deployment API.
Tests the deployment flow end-to-end and helps debug issues.
"""
import json
import requests
import sys
from pprint import pprint
# Configuration
BASE_URL = "http://localhost:8400"
CLUSTER_ID = "003fd5798ebbea9f"
SERVICE_ID = "openmemory-compose:mem0-ui"
NAMESPACE = "ushadow"
# Get auth token (adjust as needed)
def get_auth_token():
"""Get authentication token."""
# For testing, you might need to adjust this based on your auth setup
# Option 1: Login
# response = requests.post(f"{BASE_URL}/api/auth/login", json={"username": "...", "password": "..."})
# return response.json()["access_token"]
# Option 2: Use existing token
# return "your-token-here"
# Option 3: No auth (if auth is disabled for testing)
return None
def test_get_available_services():
"""Test: Get list of available services."""
print("\n" + "="*80)
print("TEST: Get Available Services")
print("="*80)
response = requests.get(f"{BASE_URL}/api/kubernetes/services/available")
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
services = data.get("services", [])
print(f"Found {len(services)} services")
# Find mem0-ui
mem0_ui = next((s for s in services if s["service_name"] == "mem0-ui"), None)
if mem0_ui:
print("\nmem0-ui service:")
pprint(mem0_ui)
return mem0_ui
else:
print("ERROR: mem0-ui not found in services")
return None
else:
print(f"ERROR: {response.text}")
return None
def test_get_env_config(service_name):
"""Test: Get environment configuration for service."""
print("\n" + "="*80)
print(f"TEST: Get Env Config for {service_name}")
print("="*80)
response = requests.get(f"{BASE_URL}/api/services/{service_name}/env")
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Required env vars: {len(data.get('required_env_vars', []))}")
print(f"Optional env vars: {len(data.get('optional_env_vars', []))}")
return data
else:
print(f"ERROR: {response.text}")
return None
def test_create_envmap():
"""Test: Create ConfigMap and Secret."""
print("\n" + "="*80)
print("TEST: Create Envmap")
print("="*80)
payload = {
"service_name": "mem0-ui",
"namespace": NAMESPACE,
"env_vars": {
"VITE_API_URL": "8765",
"API_URL": "http://mem0:8765"
}
}
print("Request payload:")
pprint(payload)
response = requests.post(
f"{BASE_URL}/api/kubernetes/{CLUSTER_ID}/envmap",
json=payload
)
print(f"\nStatus: {response.status_code}")
if response.status_code == 200:
data = response.json()
print("Response:")
pprint(data)
return data
else:
print(f"ERROR: {response.text}")
return None
def test_deploy_service():
"""Test: Deploy service to Kubernetes."""
print("\n" + "="*80)
print("TEST: Deploy Service")
print("="*80)
payload = {
"service_id": SERVICE_ID,
"namespace": NAMESPACE
}
print("Request payload:")
pprint(payload)
response = requests.post(
f"{BASE_URL}/api/kubernetes/{CLUSTER_ID}/deploy",
json=payload
)
print(f"\nStatus: {response.status_code}")
print("Response:")
try:
data = response.json()
pprint(data)
if response.status_code == 200:
print("\n✅ DEPLOYMENT SUCCESSFUL!")
return True
else:
print(f"\n❌ DEPLOYMENT FAILED")
print(f"Error: {data.get('detail', 'Unknown error')}")
return False
except Exception as e:
print(f"Failed to parse response: {e}")
print(response.text)
return False
def check_backend_version():
"""Check if backend has latest code."""
print("\n" + "="*80)
print("TEST: Check Backend Code Version")
print("="*80)
# Try to deploy and check logs
print("Checking if image variables are resolved...")
print("Looking for: image=ghcr.io/ushadow-io/u-mem0-ui:latest (resolved)")
print("NOT: image=ghcr.io/ushadow-io/u-mem0-ui:${OPENMEMORY_IMAGE_TAG:-latest} (unresolved)")
print("\nCheck backend logs for 'Service definition:' line")
def main():
"""Run all tests."""
print("="*80)
print("Kubernetes Deployment API Test Suite")
print("="*80)
print(f"Base URL: {BASE_URL}")
print(f"Cluster ID: {CLUSTER_ID}")
print(f"Service ID: {SERVICE_ID}")
print(f"Namespace: {NAMESPACE}")
# Test 1: Check backend version
check_backend_version()
# Test 2: Get available services
service = test_get_available_services()
if not service:
print("\n❌ Failed to get services")
sys.exit(1)
# Test 3: Get env config
env_config = test_get_env_config("mem0-ui")
if not env_config:
print("\n❌ Failed to get env config")
sys.exit(1)
# Test 4: Create envmap
envmap = test_create_envmap()
if not envmap:
print("\n❌ Failed to create envmap")
sys.exit(1)
# Test 5: Deploy service
success = test_deploy_service()
# Summary
print("\n" + "="*80)
print("TEST SUMMARY")
print("="*80)
if success:
print("✅ All tests passed - deployment successful!")
sys.exit(0)
else:
print("❌ Deployment failed - check logs above")
print("\nNext steps:")
print("1. Check backend logs: docker logs ushadow-purple-backend")
print("2. Check generated manifest: docker exec ushadow-purple-backend cat /tmp/k8s-manifests/{cluster-id}/ushadow/mem0-ui-deployment.yaml")
print("3. Check K8s deployment: kubectl get deployments,pods -n ushadow")
sys.exit(1)
if __name__ == "__main__":
main()