Skip to content

Commit 8eedd67

Browse files
authored
Merge pull request #199 from nginx/areste-integration-test
Basic integration test for NIC
2 parents d1bf1af + 068e447 commit 8eedd67

File tree

3 files changed

+211
-0
lines changed

3 files changed

+211
-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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
# List of expected files/directories based on the common and NIC job lists
20+
EXPECTED_ITEMS=(
21+
"manifest.json"
22+
"supportpkg.log"
23+
"k8s/crd.json"
24+
"k8s/nodes.json"
25+
"k8s/version.json"
26+
)
27+
28+
# Check for expected items
29+
MISSING_ITEMS=()
30+
FOUND_ITEMS=()
31+
32+
for item in "${EXPECTED_ITEMS[@]}"; do
33+
FULL_PATH="$EXTRACTED_DIR/$item"
34+
if [ -e "$FULL_PATH" ]; then
35+
FOUND_ITEMS+=("$item")
36+
echo "✓ Found: $item"
37+
else
38+
MISSING_ITEMS+=("$item")
39+
echo "✗ Missing: $item"
40+
fi
41+
done
42+
43+
# Check if manifest.json is valid JSON and contains expected fields
44+
MANIFEST_FILE="$EXTRACTED_DIR/manifest.json"
45+
if [ -f "$MANIFEST_FILE" ]; then
46+
if jq empty "$MANIFEST_FILE" 2>/dev/null; then
47+
echo "✓ manifest.json is valid JSON"
48+
else
49+
echo "✗ manifest.json is not valid JSON"
50+
MISSING_ITEMS+=("valid manifest.json")
51+
fi
52+
fi
53+
54+
# Summary
55+
echo ""
56+
echo "=== VERIFICATION SUMMARY ==="
57+
echo "Found items: ${#FOUND_ITEMS[@]}"
58+
echo "Missing items: ${#MISSING_ITEMS[@]}"
59+
60+
if [ ${#MISSING_ITEMS[@]} -eq 0 ]; then
61+
echo "✅ All expected items found!"
62+
echo ""
63+
echo "Complete directory structure:"
64+
find "$EXTRACTED_DIR" -type f | sort | sed 's/^/ /'
65+
exit 0
66+
else
67+
echo "❌ Some expected items are missing:"
68+
for item in "${MISSING_ITEMS[@]}"; do
69+
echo " - $item"
70+
done
71+
echo ""
72+
echo "Actual directory structure:"
73+
find "$EXTRACTED_DIR" -type f | sort | sed 's/^/ /'
74+
exit 1
75+
fi
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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/kind-action@v1.12.0
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+
50+
# Verify installation
51+
kubectl get pods -n nginx-ingress
52+
53+
- name: Wait for NGINX Ingress Controller to be ready
54+
run: |
55+
kubectl wait --namespace nginx-ingress \
56+
--for=condition=ready pod \
57+
--selector=app.kubernetes.io/instance=my-release \
58+
--timeout=300s
59+
kubectl get pods -A
60+
61+
- name: Run nginx-supportpkg tool
62+
run: |
63+
./nginx-supportpkg -n nginx-ingress -p nic
64+
65+
- name: Verify output file exists
66+
run: |
67+
ls -la *.tar.gz
68+
if [ ! -f *.tar.gz ]; then
69+
echo "Error: No tarball file found"
70+
exit 1
71+
fi
72+
echo "Tarball found: $(ls *.tar.gz)"
73+
74+
- name: Verify tarball is valid
75+
run: |
76+
TARBALL=$(ls *.tar.gz | head -n 1)
77+
echo "Testing tarball: $TARBALL"
78+
79+
# Test if it's a valid gzipped tarball
80+
if ! gzip -t "$TARBALL"; then
81+
echo "Error: File is not a valid gzip file"
82+
exit 1
83+
fi
84+
85+
# Test if it's a valid tar archive
86+
if ! tar -tzf "$TARBALL" >/dev/null 2>&1; then
87+
echo "Error: File is not a valid tar archive"
88+
exit 1
89+
fi
90+
91+
echo "Tarball is valid"
92+
93+
- name: Extract and verify contents
94+
run: |
95+
TARBALL=$(ls *.tar.gz | head -n 1)
96+
echo "Extracting tarball: $TARBALL"
97+
98+
# Extract to a test directory
99+
mkdir -p extracted_test
100+
tar -xzf "$TARBALL" -C extracted_test
101+
102+
# List all extracted contents
103+
echo "Extracted contents:"
104+
find extracted_test -type f | sort
105+
106+
# Verify expected files exist
107+
bash .github/scripts/verify-contents.sh extracted_test
108+
109+
- name: Upload test artifacts
110+
if: always()
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: integration-test-artifacts
114+
path: |
115+
*.tar.gz
116+
extracted_test/

0 commit comments

Comments
 (0)