Skip to content

Commit 136de79

Browse files
committed
feat: add integration test
1 parent d1bf1af commit 136de79

File tree

3 files changed

+295
-0
lines changed

3 files changed

+295
-0
lines changed

.github/kind-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
name: test-cluster
4+
nodes:
5+
- role: control-plane
6+
kubeadmConfigPatches:
7+
- |
8+
kind: InitConfiguration
9+
nodeRegistration:
10+
kubeletExtraArgs:
11+
node-labels: "ingress-ready=true"
12+
extraPortMappings:
13+
- containerPort: 80
14+
hostPort: 80
15+
protocol: TCP
16+
- containerPort: 443
17+
hostPort: 443
18+
protocol: TCP
19+
- role: worker
20+

.github/scripts/verify-contents.sh

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/bin/bash
2+
set -e
3+
4+
EXTRACTED_DIR="$1"
5+
6+
if [ -z "$EXTRACTED_DIR" ]; then
7+
echo "Usage: $0 <extracted_directory>"
8+
exit 1
9+
fi
10+
11+
echo "Verifying contents in directory: $EXTRACTED_DIR"
12+
13+
# Check if extraction directory exists
14+
if [ ! -d "$EXTRACTED_DIR" ]; then
15+
echo "Error: Extracted directory does not exist: $EXTRACTED_DIR"
16+
exit 1
17+
fi
18+
19+
# Find the actual supportpkg directory (it should be nested)
20+
SUPPORTPKG_DIR=$(find "$EXTRACTED_DIR" -maxdepth 2 -type d -name "*supportpkg*" | head -n 1)
21+
22+
if [ -z "$SUPPORTPKG_DIR" ]; then
23+
echo "Error: Could not find supportpkg directory in extracted contents"
24+
echo "Available directories:"
25+
find "$EXTRACTED_DIR" -type d | head -20
26+
exit 1
27+
fi
28+
29+
echo "Found supportpkg directory: $SUPPORTPKG_DIR"
30+
31+
# List of expected files/directories based on the common and NIC job lists
32+
EXPECTED_ITEMS=(
33+
"manifest.json"
34+
"resources/k8s-version.json"
35+
"resources/nodes-info.json"
36+
"resources/nginx-ingress/pods.json"
37+
"resources/nginx-ingress/events.json"
38+
"resources/nginx-ingress/configmaps.json"
39+
"resources/nginx-ingress/services.json"
40+
"resources/nginx-ingress/deployments.json"
41+
"logs/nginx-ingress"
42+
)
43+
44+
# Optional items that might exist depending on what's deployed
45+
OPTIONAL_ITEMS=(
46+
"exec/nginx-ingress"
47+
"resources/nginx-ingress/statefulsets.json"
48+
"resources/nginx-ingress/replicasets.json"
49+
"resources/nginx-ingress/leases.json"
50+
"resources/nginx-ingress/daemonsets.json"
51+
"resources/nginx-ingress/secrets.json"
52+
"resources/ingresses.json"
53+
"resources/virtualservers.json"
54+
"resources/virtualserverroutes.json"
55+
)
56+
57+
# Check for expected items
58+
MISSING_ITEMS=()
59+
FOUND_ITEMS=()
60+
61+
for item in "${EXPECTED_ITEMS[@]}"; do
62+
FULL_PATH="$SUPPORTPKG_DIR/$item"
63+
if [ -e "$FULL_PATH" ]; then
64+
FOUND_ITEMS+=("$item")
65+
echo "✓ Found: $item"
66+
else
67+
MISSING_ITEMS+=("$item")
68+
echo "✗ Missing: $item"
69+
fi
70+
done
71+
72+
# Check optional items
73+
for item in "${OPTIONAL_ITEMS[@]}"; do
74+
FULL_PATH="$SUPPORTPKG_DIR/$item"
75+
if [ -e "$FULL_PATH" ]; then
76+
echo "✓ Found optional: $item"
77+
else
78+
echo "○ Optional missing: $item"
79+
fi
80+
done
81+
82+
# Check if logs directory contains pod logs
83+
LOGS_DIR="$SUPPORTPKG_DIR/logs/nginx-ingress"
84+
if [ -d "$LOGS_DIR" ]; then
85+
LOG_COUNT=$(find "$LOGS_DIR" -name "*.txt" | wc -l)
86+
if [ "$LOG_COUNT" -gt 0 ]; then
87+
echo "✓ Found $LOG_COUNT log files in nginx-ingress namespace"
88+
echo " Log files:"
89+
find "$LOGS_DIR" -name "*.txt" -exec basename {} \; | sed 's/^/ /'
90+
else
91+
echo "✗ No log files found in logs/nginx-ingress directory"
92+
MISSING_ITEMS+=("pod log files")
93+
fi
94+
fi
95+
96+
# Check if manifest.json is valid JSON and contains expected fields
97+
MANIFEST_FILE="$SUPPORTPKG_DIR/manifest.json"
98+
if [ -f "$MANIFEST_FILE" ]; then
99+
if jq empty "$MANIFEST_FILE" 2>/dev/null; then
100+
echo "✓ manifest.json is valid JSON"
101+
PRODUCT=$(jq -r '.product // "unknown"' "$MANIFEST_FILE")
102+
TOTAL_JOBS=$(jq -r '.totalJobs // "unknown"' "$MANIFEST_FILE")
103+
FAILED_JOBS=$(jq -r '.failedJobs // "unknown"' "$MANIFEST_FILE")
104+
105+
echo " Product: $PRODUCT"
106+
echo " Total jobs: $TOTAL_JOBS"
107+
echo " Failed jobs: $FAILED_JOBS"
108+
109+
# Verify we're testing the right product
110+
if [ "$PRODUCT" != "nic" ]; then
111+
echo "⚠ Warning: Expected product 'nic', got '$PRODUCT'"
112+
fi
113+
114+
# Check if there are failed jobs
115+
if [ "$FAILED_JOBS" != "0" ] && [ "$FAILED_JOBS" != "unknown" ]; then
116+
echo "⚠ Warning: Some jobs failed ($FAILED_JOBS failures)"
117+
fi
118+
else
119+
echo "✗ manifest.json is not valid JSON"
120+
MISSING_ITEMS+=("valid manifest.json")
121+
fi
122+
fi
123+
124+
# Check for kubernetes resource files content
125+
PODS_FILE="$SUPPORTPKG_DIR/resources/nginx-ingress/pods.json"
126+
if [ -f "$PODS_FILE" ]; then
127+
if jq empty "$PODS_FILE" 2>/dev/null; then
128+
POD_COUNT=$(jq '.items | length' "$PODS_FILE" 2>/dev/null || echo "0")
129+
echo "✓ Found $POD_COUNT pods in nginx-ingress namespace"
130+
else
131+
echo "✗ pods.json is not valid JSON"
132+
MISSING_ITEMS+=("valid pods.json")
133+
fi
134+
fi
135+
136+
# Summary
137+
echo ""
138+
echo "=== VERIFICATION SUMMARY ==="
139+
echo "Found items: ${#FOUND_ITEMS[@]}"
140+
echo "Missing items: ${#MISSING_ITEMS[@]}"
141+
142+
if [ ${#MISSING_ITEMS[@]} -eq 0 ]; then
143+
echo "✅ All expected items found!"
144+
echo ""
145+
echo "Complete directory structure:"
146+
find "$SUPPORTPKG_DIR" -type f | sort | sed 's/^/ /'
147+
exit 0
148+
else
149+
echo "❌ Some expected items are missing:"
150+
for item in "${MISSING_ITEMS[@]}"; do
151+
echo " - $item"
152+
done
153+
echo ""
154+
echo "Actual directory structure:"
155+
find "$SUPPORTPKG_DIR" -type f | sort | sed 's/^/ /'
156+
exit 1
157+
fi
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Integration Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [ main ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
integration-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.24'
21+
22+
- name: Build binary
23+
run: |
24+
go build -o nginx-supportpkg main.go
25+
chmod +x nginx-supportpkg
26+
27+
- name: Create KinD cluster
28+
uses: helm/[email protected]
29+
with:
30+
cluster_name: test-cluster
31+
config: .github/kind-config.yaml
32+
33+
- name: Wait for cluster to be ready
34+
run: |
35+
kubectl wait --for=condition=Ready nodes --all --timeout=300s
36+
kubectl cluster-info
37+
38+
- name: Install NGINX Ingress Controller with Helm
39+
run: |
40+
# Install Helm (it's pre-installed on GitHub runners but ensure latest version)
41+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
42+
43+
# Add and update helm repos (if needed)
44+
helm version
45+
46+
# Install NGINX Ingress Controller
47+
helm install my-release oci://ghcr.io/nginx/charts/nginx-ingress --version 2.2.2 \
48+
--namespace nginx-ingress --create-namespace \
49+
--wait --timeout=300s
50+
51+
# Verify installation
52+
kubectl get pods -n nginx-ingress
53+
kubectl get svc -n nginx-ingress
54+
55+
- name: Wait for NGINX Ingress Controller to be ready
56+
run: |
57+
kubectl wait --namespace nginx-ingress \
58+
--for=condition=ready pod \
59+
--selector=app.kubernetes.io/instance=my-release \
60+
--timeout=300s
61+
kubectl get pods -A
62+
63+
- name: Run nginx-supportpkg tool
64+
run: |
65+
./nginx-supportpkg -n nginx-ingress -p nic
66+
67+
- name: Verify output file exists
68+
run: |
69+
ls -la *.tar.gz
70+
if [ ! -f *.tar.gz ]; then
71+
echo "Error: No tarball file found"
72+
exit 1
73+
fi
74+
echo "Tarball found: $(ls *.tar.gz)"
75+
76+
- name: Verify tarball is valid
77+
run: |
78+
TARBALL=$(ls *.tar.gz | head -n 1)
79+
echo "Testing tarball: $TARBALL"
80+
81+
# Test if it's a valid gzipped tarball
82+
if ! gzip -t "$TARBALL"; then
83+
echo "Error: File is not a valid gzip file"
84+
exit 1
85+
fi
86+
87+
# Test if it's a valid tar archive
88+
if ! tar -tzf "$TARBALL" >/dev/null 2>&1; then
89+
echo "Error: File is not a valid tar archive"
90+
exit 1
91+
fi
92+
93+
echo "Tarball is valid"
94+
95+
- name: Extract and verify contents
96+
run: |
97+
TARBALL=$(ls *.tar.gz | head -n 1)
98+
echo "Extracting tarball: $TARBALL"
99+
100+
# Extract to a test directory
101+
mkdir -p extracted_test
102+
tar -xzf "$TARBALL" -C extracted_test
103+
104+
# List all extracted contents
105+
echo "Extracted contents:"
106+
find extracted_test -type f | sort
107+
108+
# Verify expected files exist
109+
bash .github/scripts/verify-contents.sh extracted_test
110+
111+
- name: Upload test artifacts
112+
if: always()
113+
uses: actions/upload-artifact@v3
114+
with:
115+
name: integration-test-artifacts
116+
path: |
117+
*.tar.gz
118+
extracted_test/

0 commit comments

Comments
 (0)