68 lines
1.7 KiB
Bash
Executable File
68 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Create a ConfigMap with route patches for the backend
|
|
cat > /tmp/route-patches.js << 'EOF'
|
|
// Root route
|
|
app.get('/', (req, res) => {
|
|
res.json({ message: 'Welcome to the API' });
|
|
});
|
|
|
|
// Health check endpoint
|
|
app.get('/api', (req, res) => {
|
|
res.json({ status: 'ok', message: 'API is healthy' });
|
|
});
|
|
|
|
// Update existing routes if needed
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({ status: 'ok' });
|
|
});
|
|
EOF
|
|
|
|
kubectl create configmap route-patches -n sk1 --from-file=routes.js=/tmp/route-patches.js --dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Create a patch for the backend deployment to inject these routes
|
|
cat > /tmp/backend-patch-routes.yaml << EOF
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: backend
|
|
namespace: sk1
|
|
spec:
|
|
template:
|
|
spec:
|
|
containers:
|
|
- name: backend
|
|
env:
|
|
- name: DEBUG
|
|
value: "express:*"
|
|
# Add script to update routes on startup
|
|
lifecycle:
|
|
postStart:
|
|
exec:
|
|
command:
|
|
- sh
|
|
- -c
|
|
- |
|
|
echo "Patching routes..."
|
|
cat /routes/routes.js >> /app/index.js
|
|
# Force Express to reload routes
|
|
kill -SIGHUP 1
|
|
volumeMounts:
|
|
- name: route-patches
|
|
mountPath: /routes
|
|
volumes:
|
|
- name: route-patches
|
|
configMap:
|
|
name: route-patches
|
|
EOF
|
|
|
|
# Apply the patch
|
|
kubectl apply -f /tmp/backend-patch-routes.yaml
|
|
|
|
# Restart backend to apply changes
|
|
kubectl rollout restart deployment backend -n sk1
|
|
|
|
echo "Added missing API routes to backend"
|
|
echo "Waiting for backend to restart..."
|
|
kubectl rollout status deployment backend -n sk1 |