-
Notifications
You must be signed in to change notification settings - Fork 7
225 lines (190 loc) · 8.15 KB
/
helm-test.yml
File metadata and controls
225 lines (190 loc) · 8.15 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
name: Helm Test
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect changed charts
id: set-matrix
run: |
# Get changed files
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
fi
echo "Changed files:"
echo "$CHANGED_FILES"
# Find changed charts
CHANGED_CHARTS=()
# Check if openlit chart changed
if echo "$CHANGED_FILES" | grep -E "^charts/openlit/" > /dev/null; then
CHANGED_CHARTS+=("openlit")
fi
# Check if openlit-controller chart changed
if echo "$CHANGED_FILES" | grep -E "^charts/openlit-controller/" > /dev/null; then
CHANGED_CHARTS+=("openlit-controller")
fi
# Create matrix
if [ ${#CHANGED_CHARTS[@]} -eq 0 ]; then
echo "matrix={\"include\":[]}" >> "$GITHUB_OUTPUT"
echo "No charts changed"
else
# Build JSON matrix manually
MATRIX_JSON="{\"include\":["
for i in "${!CHANGED_CHARTS[@]}"; do
if [ $i -gt 0 ]; then
MATRIX_JSON="$MATRIX_JSON,"
fi
MATRIX_JSON="$MATRIX_JSON{\"chart\":\"${CHANGED_CHARTS[$i]}\"}"
done
MATRIX_JSON="$MATRIX_JSON]}"
echo "matrix=$MATRIX_JSON" >> "$GITHUB_OUTPUT"
echo "Changed charts: ${CHANGED_CHARTS[*]}"
fi
test:
needs: detect-changes
if: needs.detect-changes.outputs.matrix != '{"include":[]}'
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.12.1
- name: Add Helm repositories
run: |
echo "📦 Adding OpenLIT Helm repository"
helm repo add openlit https://openlit.github.io/helm/
helm repo update
echo "✅ Helm repositories added and updated"
- name: Enforce version bump for chart changes
run: |
CHART_PATH="charts/${{ matrix.chart }}"
echo "Checking if ${{ matrix.chart }} chart version was bumped..."
# Get changed files for this specific test run
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
fi
# Check if this chart's files were changed
if echo "$CHANGED_FILES" | grep -E "^$CHART_PATH/" > /dev/null; then
echo "📁 Files changed in $CHART_PATH/"
# Check if version was bumped
OLD_VERSION=$(git show HEAD~1:$CHART_PATH/Chart.yaml | grep '^version:' | awk '{print $2}')
NEW_VERSION=$(grep '^version:' $CHART_PATH/Chart.yaml | awk '{print $2}')
echo "Previous version: $OLD_VERSION"
echo "Current version: $NEW_VERSION"
if [ "$OLD_VERSION" = "$NEW_VERSION" ]; then
echo ""
echo "❌ ERROR: Chart files changed but version not bumped!"
echo ""
echo "The following files were modified in $CHART_PATH/:"
echo "$CHANGED_FILES" | grep "^$CHART_PATH/" | sed 's/^/ - /'
echo ""
echo "🔧 Required action: Bump the version in $CHART_PATH/Chart.yaml"
echo " Current version: $OLD_VERSION"
echo " Suggested: Bump to next patch/minor/major version"
echo ""
echo "This ensures proper chart versioning before merging."
exit 1
else
echo "✅ Version properly bumped from $OLD_VERSION to $NEW_VERSION"
fi
else
echo "ℹ️ No files changed in $CHART_PATH/ (this shouldn't happen in matrix)"
fi
- name: Build chart dependencies
run: |
echo "📦 Building dependencies for chart: ${{ matrix.chart }}"
cd ./charts/${{ matrix.chart }}
helm dependency build
echo "✅ Dependencies built for ${{ matrix.chart }}"
- name: Run chart linting
run: |
echo "🔍 Linting chart: ${{ matrix.chart }}"
helm lint ./charts/${{ matrix.chart }}
echo "✅ Chart linting completed for ${{ matrix.chart }}"
- name: Create kind cluster
uses: helm/kind-action@v1.13.0
- name: Install Helm Chart
run: helm install ${{ matrix.chart }}-test ./charts/${{ matrix.chart }} --namespace ${{ matrix.chart }}-test --create-namespace
- name: Verify resources created
run: |
NAMESPACE=${{ matrix.chart }}-test
echo "=== Installed resources in namespace $NAMESPACE ==="
kubectl get all -n $NAMESPACE
- name: Wait for Pods to be ready
if: matrix.chart != 'openlit-controller'
run: sleep 60
- name: Check Pod status
run: |
kubectl get pods -n ${{ matrix.chart }}-test
- name: Print logs for chart pods
run: |
NAMESPACE=${{ matrix.chart }}-test
echo "=== Getting all pods in namespace $NAMESPACE ==="
PODS=$(kubectl get pods -n $NAMESPACE -o jsonpath='{.items[*].metadata.name}')
echo "Found pods: $PODS"
for POD in $PODS; do
echo ""
echo "=== Logs for pod $POD ==="
kubectl logs -n $NAMESPACE $POD --all-containers=true --ignore-errors=true || echo "Could not get logs for $POD"
done
- name: Check if pods are running
if: matrix.chart != 'openlit-controller'
run: |
NAMESPACE=${{ matrix.chart }}-test
echo "Checking pod status in namespace: $NAMESPACE"
# Get all pods and their status
kubectl get pods -n $NAMESPACE -o wide
# Check for any non-running pods
FAILED_PODS=$(kubectl get pods -n $NAMESPACE --field-selector=status.phase!=Running,status.phase!=Succeeded -o jsonpath='{.items[*].metadata.name}' 2>/dev/null || echo "")
if [ -n "$FAILED_PODS" ]; then
echo "❌ The following pods are not in Running/Succeeded state: $FAILED_PODS"
echo ""
echo "Pod details:"
kubectl describe pods -n $NAMESPACE $FAILED_PODS
exit 1
else
echo "✅ All pods are in Running/Succeeded state in namespace $NAMESPACE"
fi
- name: Verify controller resources (controller chart only)
if: matrix.chart == 'openlit-controller'
run: |
NAMESPACE=${{ matrix.chart }}-test
echo "=== Verifying controller DaemonSet ==="
kubectl get daemonset -n $NAMESPACE
DS_COUNT=$(kubectl get daemonset -n $NAMESPACE -o jsonpath='{.items}' | jq length)
if [ "$DS_COUNT" -eq 0 ]; then
echo "❌ No DaemonSet found"
exit 1
fi
echo "✅ DaemonSet created"
echo "=== Verifying RBAC resources ==="
kubectl get serviceaccount -n $NAMESPACE
kubectl get clusterrole | grep openlit-controller || true
kubectl get clusterrolebinding | grep openlit-controller || true
echo "=== Verifying ConfigMap ==="
kubectl get configmap -n $NAMESPACE | grep openlit-controller
echo "✅ All controller resources verified"