-
Notifications
You must be signed in to change notification settings - Fork 4
235 lines (196 loc) · 7.04 KB
/
Copy pathci.yaml
File metadata and controls
235 lines (196 loc) · 7.04 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
GO_VERSION: '1.25'
REGISTRY: ghcr.io
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.11.4
args: --timeout=5m
reconcile-guard:
name: Reconcile Guard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for unconditional Update on managed resources
run: |
# Detect bare r.Update/r.Create calls in the controller that bypass
# controllerutil.CreateOrUpdate. Only r.Update(ctx, instance) and
# r.Status().Update(ctx, instance) are allowed (CR-level updates).
VIOLATIONS=$(grep -n 'r\.Update(ctx,' internal/controller/instance_controller.go \
| grep -v 'instance)' \
| grep -v '// reconcile-guard:allow' || true)
if [ -n "$VIOLATIONS" ]; then
echo "::error::Found bare r.Update() calls on managed resources. Use controllerutil.CreateOrUpdate instead."
echo "Violations:"
echo "$VIOLATIONS"
echo ""
echo "If this is intentional, add '// reconcile-guard:allow' to the line."
exit 1
fi
echo "No unconditional Update calls on managed resources found."
helm-rbac-sync:
name: Helm RBAC Sync
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Helm chart RBAC matches kubebuilder markers
run: bash hack/check-helm-rbac-sync.sh
helm-crd-sync:
name: Helm CRD Sync
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Helm chart CRD templates match generated CRDs
run: bash hack/sync-chart-crds.sh --check
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run tests
run: make test
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: ./cover.out
fail_ci_if_error: false
security-scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run gosec
uses: securego/gosec@master
with:
args: -exclude-generated -exclude-dir=test ./...
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
severity: 'CRITICAL,HIGH'
build:
name: Build
needs: [lint, test, security-scan]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Lowercase image name
id: image
run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}
tags: |
type=sha,prefix=
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
# Only build arm64 on main (where we push). PRs only need amd64 to
# verify the build -- arm64 cross-compilation via QEMU adds ~15 min.
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
e2e:
name: E2E Tests
needs: [lint, test, security-scan]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Lowercase image name
id: image
run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Create kind cluster
uses: helm/kind-action@v1
with:
cluster_name: e2e-test
- name: Build operator image for kind
run: |
docker build -t ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:e2e .
- name: Load image into kind
run: |
kind load docker-image ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:e2e --name e2e-test
- name: Install CRDs
run: make install
- name: Deploy operator
run: |
make deploy IMG=${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:e2e
- name: Wait for operator
run: |
kubectl wait --for=condition=available --timeout=180s deployment/paperclip-operator-controller-manager -n paperclip-operator-system
- name: Debug operator status
if: failure()
run: |
echo "=== Deployment status ==="
kubectl get deployment -n paperclip-operator-system
echo "=== Pod status ==="
kubectl get pods -n paperclip-operator-system
echo "=== Pod logs ==="
kubectl logs -n paperclip-operator-system -l control-plane=controller-manager --tail=100 || true
echo "=== Pod describe ==="
kubectl describe pods -n paperclip-operator-system || true
- name: Run E2E tests
run: make test-e2e
- name: Install operator-sdk
run: |
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
curl -sSLo /usr/local/bin/operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v1.42.0/operator-sdk_${OS}_${ARCH}"
chmod +x /usr/local/bin/operator-sdk
operator-sdk version
- name: Run scorecard tests
run: operator-sdk scorecard bundle --wait-time 120s || true
- name: Dump operator logs
if: failure()
run: |
echo "=== Operator pod status ==="
kubectl get pods -n paperclip-operator-system
echo "=== Instance resources ==="
kubectl get instances -A -o wide || true
echo "=== Operator logs (all) ==="
kubectl logs -n paperclip-operator-system -l control-plane=controller-manager --tail=-1 || true