-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-confighub-k8s
More file actions
executable file
·273 lines (227 loc) · 8.13 KB
/
test-confighub-k8s
File metadata and controls
executable file
·273 lines (227 loc) · 8.13 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash
set -e
# Mini TCK for ConfigHub + Kubernetes Integration
# Tests: 1 space + 1 unit + 1 kind cluster + 1 worker + 1 apply
# No dependencies on any project - pure ConfigHub + K8s verification
echo "🧪 ConfigHub + Kubernetes Mini TCK"
echo "==================================="
echo ""
echo "This test verifies:"
echo " - ConfigHub API connectivity"
echo " - Kubernetes cluster access"
echo " - Worker installation"
echo " - Unit apply workflow"
echo " - Live state verification"
echo ""
# Cleanup function
cleanup() {
echo ""
echo "🧹 Cleaning up test resources..."
# Get space ID if it exists
SPACE_ID=$(cub space list --format json 2>/dev/null | jq -r '.[] | select(.Slug == "confighub-tck") | .ID' 2>/dev/null || echo "")
if [ -n "$SPACE_ID" ]; then
echo " Cleaning up space: $SPACE_ID"
# List and delete all units in the space
cub unit list --space confighub-tck --format json 2>/dev/null | \
jq -r '.[].Slug' 2>/dev/null | \
while read slug; do
echo " Deleting unit: $slug"
cub unit delete "$slug" --space confighub-tck 2>/dev/null || true
done
# Uninstall worker
cub worker delete tck-worker --space confighub-tck 2>/dev/null || true
# Delete space
cub space delete confighub-tck 2>/dev/null || true
fi
# Delete Kind cluster
kind delete cluster --name confighub-tck 2>/dev/null || true
# Cleanup temp files
rm -f /tmp/tck-test-pod.yaml
echo "✅ Cleanup complete"
}
# Trap exit to cleanup
trap cleanup EXIT
# Check prerequisites
echo "Checking prerequisites..."
if ! command -v cub &> /dev/null; then
echo "❌ Error: 'cub' command not found"
echo " Install: brew install confighubai/tap/cub"
exit 1
fi
if ! command -v kind &> /dev/null; then
echo "❌ Error: 'kind' command not found"
echo " Install: brew install kind"
exit 1
fi
if ! command -v kubectl &> /dev/null; then
echo "❌ Error: 'kubectl' command not found"
echo " Install: brew install kubectl"
exit 1
fi
# Check ConfigHub authentication
if ! cub space list &>/dev/null; then
echo "❌ Error: ConfigHub authentication failed"
echo " Run: cub auth login"
exit 1
fi
echo "✅ All prerequisites met"
echo ""
# Clean up any leftover resources from previous runs
echo "Cleaning up any leftover resources..."
kind delete cluster --name confighub-tck 2>/dev/null || true
cub space delete confighub-tck 2>/dev/null || true
echo ""
# Step 1: Create Kind cluster
echo "Step 1: Create Kind cluster"
echo "----------------------------"
if kind get clusters 2>/dev/null | grep -q "^confighub-tck$"; then
echo "⚠️ Kind cluster 'confighub-tck' already exists, deleting..."
kind delete cluster --name confighub-tck
fi
kind create cluster --name confighub-tck --wait 60s
echo "✅ Kind cluster created"
echo ""
# Step 2: Create ConfigHub space
echo "Step 2: Create ConfigHub space"
echo "-------------------------------"
cub space create confighub-tck --label test=tck 2>/dev/null || true
echo "✅ ConfigHub space created"
echo ""
# Step 3: Create test unit (minimal nginx pod)
echo "Step 3: Create test unit (nginx pod)"
echo "-------------------------------------"
# Use unique name with timestamp to avoid conflicts
UNIT_NAME="test-pod-$(date +%s)"
cat > /tmp/tck-test-pod.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
name: ${UNIT_NAME}
namespace: default
labels:
app: tck-test
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
EOF
cub unit create \
--space confighub-tck \
--label type=test \
"${UNIT_NAME}" \
/tmp/tck-test-pod.yaml
echo "✅ Unit created in ConfigHub (${UNIT_NAME})"
echo ""
# Step 4: Create and install ConfigHub worker
echo "Step 4: Create and install ConfigHub worker"
echo "--------------------------------------------"
kubectl config use-context kind-confighub-tck
# First create the worker in ConfigHub
cub worker create tck-worker --space confighub-tck 2>/dev/null || true
# Then install it to the cluster
if ! cub worker install tck-worker \
--space confighub-tck \
--namespace confighub \
--include-secret \
--export | kubectl apply -f -; then
echo "❌ Worker installation failed"
echo " Checking worker status..."
cub worker list --space confighub-tck || true
kubectl get pods -n confighub || true
exit 1
fi
# Wait for worker deployment to be ready
echo "Waiting for worker deployment to be ready..."
if ! kubectl rollout status deployment/tck-worker -n confighub --timeout=90s 2>/dev/null; then
echo "❌ Worker deployment did not become ready"
kubectl get pods -n confighub || true
kubectl describe pod -n confighub -l app=tck-worker || true
exit 1
fi
# Wait for worker to connect to ConfigHub
echo "Waiting for worker to connect to ConfigHub..."
for i in {1..30}; do
WORKER_STATUS=$(cub worker list --space confighub-tck --format json 2>/dev/null | jq -r '.[0].Condition // "Unknown"' 2>/dev/null || echo "Unknown")
if [ "$WORKER_STATUS" = "Ready" ]; then
break
fi
sleep 2
done
if [ "$WORKER_STATUS" != "Ready" ]; then
echo "⚠️ Worker status: $WORKER_STATUS (may still be connecting)"
fi
echo "✅ Worker installed and connected"
echo ""
# Step 5: Set target and apply unit to Kubernetes
echo "Step 5: Set target and apply unit to Kubernetes"
echo "------------------------------------------------"
# Get the Kubernetes target ID (use the k8s-* target for YAML resources)
TARGET_SLUG="k8s-tck-worker"
# Verify target exists
if ! cub target list --space confighub-tck --names 2>/dev/null | grep -q "$TARGET_SLUG"; then
echo "❌ Could not find target: $TARGET_SLUG"
cub target list --space confighub-tck || true
exit 1
fi
echo "Using target: $TARGET_SLUG"
# Set the unit's target
cub unit set-target "${UNIT_NAME}" "$TARGET_SLUG" --space confighub-tck
# Apply the unit
cub unit apply "${UNIT_NAME}" --space confighub-tck
echo "✅ Unit applied"
echo ""
# Step 6: Verify deployment
echo "Step 6: Verify deployment"
echo "-------------------------"
echo "Waiting for pod to be ready (max 60s)..."
# Wait for pod to be ready
if ! kubectl wait --for=condition=ready "pod/${UNIT_NAME}" --timeout=60s 2>/dev/null; then
echo "❌ Pod did not become ready in time"
kubectl get pod "${UNIT_NAME}" -o yaml || true
exit 1
fi
echo "✅ Pod is ready in Kubernetes"
echo ""
# Step 7: Verify ConfigHub live state
echo "Step 7: Verify ConfigHub live state"
echo "------------------------------------"
LIVE_STATE=$(cub unit get-live-state "${UNIT_NAME}" --space confighub-tck --format json 2>/dev/null || echo "{}")
if echo "$LIVE_STATE" | jq -e '.status.phase == "Running"' > /dev/null 2>&1; then
echo "✅ ConfigHub live state shows: Running"
else
PHASE=$(echo "$LIVE_STATE" | jq -r '.status.phase // "Unknown"' 2>/dev/null || echo "Unknown")
echo "⚠️ ConfigHub live state shows: $PHASE"
if [ "$PHASE" != "Running" ]; then
echo " (Pod may still be starting)"
fi
fi
echo ""
# Final verification
echo "Step 8: Final verification"
echo "--------------------------"
POD_STATUS=$(kubectl get pod "${UNIT_NAME}" -o jsonpath='{.status.phase}' 2>/dev/null || echo "Unknown")
if [ "$POD_STATUS" = "Running" ]; then
echo "✅ Pod verified in Kubernetes: $POD_STATUS"
else
echo "❌ Pod not running in Kubernetes: $POD_STATUS"
kubectl describe pod "${UNIT_NAME}" || true
exit 1
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎉 SUCCESS! ConfigHub + Kubernetes integration verified"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Summary:"
echo " ✅ Kind cluster: confighub-tck"
echo " ✅ ConfigHub space: confighub-tck"
echo " ✅ ConfigHub unit: ${UNIT_NAME}"
echo " ✅ Worker: tck-worker (connected)"
echo " ✅ Pod status: $POD_STATUS"
echo " ✅ ConfigHub → Kubernetes flow: WORKING"
echo ""
echo "Your ConfigHub + Kubernetes environment is correctly configured!"
echo ""
echo "Note: All test resources will be cleaned up automatically."