Skip to content

Commit 495f6ac

Browse files
committed
feat(ci): make ci coverage include new deployment policies suite
1 parent 9a6f2d8 commit 495f6ac

File tree

2 files changed

+97
-25
lines changed

2 files changed

+97
-25
lines changed

.github/workflows/operator-ci.yaml

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,22 @@ jobs:
5454
# Standard E2E tests on all supported K8s versions
5555
k8s-version: ["1.31.14", "1.32.11", "1.33.7", "1.34.3", "1.35.0"]
5656
test-suite: ["e2e"]
57+
make-targets: ["setup-kind-cluster e2e-tests"]
5758
include:
58-
# Deployment policy tests on 15-node cluster (K8s 1.34 only)
59+
# Deployment policy tests on 15-node cluster (K8s 1.35 only)
5960
- k8s-version: "1.35.0"
6061
test-suite: deployment-policy
6162
kind-config: k8s-tests/chainsaw/deployment-policy/kind-config.yaml
62-
make-target: deployment-policy-tests
63+
make-targets: "setup-kind-cluster deployment-policy-tests"
6364
# CLI e2e tests on K8s 1.34 only
6465
- k8s-version: "1.35.0"
6566
test-suite: cli-e2e
66-
make-target: cli-e2e-tests
67+
make-targets: "setup-kind-cluster cli-e2e-tests"
68+
- k8s-version: "1.35.0"
69+
test-suite: unit-tests
70+
make-targets: "vet lint unit-tests"
6771
fail-fast: false # Continue testing other versions if one fails
68-
name: ${{ matrix.test-suite }}-tests (k8s-${{ matrix.k8s-version }})
72+
name: ${{ matrix.test-suite }} (k8s-${{ matrix.k8s-version }})
6973
steps:
7074
- uses: actions/checkout@v4
7175
with:
@@ -77,16 +81,18 @@ jobs:
7781
go-version: ${{ env.GO_VERSION }}
7882
cache-dependency-path: operator/go.sum
7983
- name: Log in to the Container registry
84+
if: matrix.test-suite != 'unit-tests' # unit tests don't need a container registry login
8085
uses: docker/login-action@v3
8186
with:
8287
registry: ${{ env.REGISTRY }}
8388
username: ${{ github.actor }}
8489
password: ${{ secrets.GITHUB_TOKEN }}
8590
- name: Create Kubernetes KinD Cluster v${{ matrix.k8s-version }}
91+
if: matrix.test-suite != 'unit-tests' # unit tests don't need a kind cluster
8692
id: kind
8793
uses: helm/kind-action@v1
8894
with:
89-
version: v0.30.0
95+
version: v0.31.0
9096
node_image: kindest/node:v${{ matrix.k8s-version }}
9197
config: ${{ matrix.kind-config || 'operator/config/local-dev/kind-config.yaml' }}
9298
cluster_name: kind
@@ -118,18 +124,53 @@ jobs:
118124
- name: Run ${{ matrix.test-suite }} tests
119125
run: |
120126
cd operator
121-
if [ "${{ matrix.test-suite }}" = "e2e" ]; then
122-
make setup-kind-cluster
123-
make test
124-
elif [ "${{ matrix.test-suite }}" = "cli-e2e" ]; then
125-
make setup-kind-cluster
126-
make ${{ matrix.make-target }}
127-
else
128-
make ${{ matrix.make-target }}
129-
fi
130-
# Upload coverage to Coveralls using goveralls (Go-specific tool)
131-
- name: Upload coverage to Coveralls
132-
if: matrix.test-suite == 'e2e' && matrix.k8s-version == '1.35.0'
127+
make ${{ matrix.make-targets }} merge-coverage
128+
# Save coverage artifacts from any test suite that generates them
129+
- name: Upload coverage artifact
130+
if: hashFiles('operator/reporting/cover.out') != ''
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: coverage-${{ matrix.test-suite }}-k8s-${{ matrix.k8s-version }}
134+
path: operator/reporting/cover.out
135+
retention-days: 1
136+
if-no-files-found: ignore
137+
138+
# Merge coverage from all test suites and upload to Coveralls
139+
upload-coverage:
140+
runs-on: ubuntu-latest
141+
needs: [tests]
142+
# Only upload coverage for PRs and main branch pushes, not for tags
143+
if: success() && !startsWith(github.ref, 'refs/tags/')
144+
steps:
145+
- uses: actions/checkout@v4
146+
- name: Setup Go ${{ env.GO_VERSION }}
147+
uses: actions/setup-go@v5
148+
with:
149+
go-version: ${{ env.GO_VERSION }}
150+
- name: Download all coverage artifacts
151+
uses: actions/download-artifact@v4
152+
with:
153+
pattern: coverage-*
154+
path: coverage-artifacts
155+
merge-multiple: false
156+
- name: Merge coverage files
157+
run: |
158+
cd operator
159+
mkdir -p reporting
160+
# Combine all coverage files
161+
for file in ../coverage-artifacts/*/cover.out; do
162+
if [ -f "$file" ]; then
163+
echo "Merging coverage from $file"
164+
cat "$file" >> reporting/all-cover.out
165+
fi
166+
done
167+
# Create final merged coverage file
168+
echo "mode: set" > reporting/cover.out
169+
tail -n +2 reporting/all-cover.out | sed '/mode: set/d' >> reporting/cover.out
170+
# Show total coverage
171+
echo "📊 Total Combined Coverage:"
172+
go tool cover -func reporting/cover.out | grep total
173+
- name: Upload to Coveralls
133174
uses: coverallsapp/github-action@v2
134175
with:
135176
github-token: ${{ secrets.GITHUB_TOKEN }}

operator/Makefile

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ $(REPORTING):
142142
mkdir -p $@
143143

144144
.PHONY: test
145-
test:: reporting manifests generate fmt vet lint unit-tests e2e-tests helm-tests operator-agent-tests ## Run all tests.
145+
test:: reporting manifests generate fmt vet lint unit-tests e2e-tests cli-e2e-tests helm-tests operator-agent-tests ## Run all tests.
146146

147147
ifndef CI
148148
## we double define test so we can do thing different if in ci vs local
@@ -176,11 +176,30 @@ e2e-tests: chainsaw install run ## Run end to end tests.
176176
$(MAKE) kill
177177
go tool covdata textfmt -i=$(REPORTING)/int -o reporting/int.coverprofile
178178

179-
cli-e2e-tests: chainsaw install run build-cli ## Run CLI end to end tests.
179+
cli-e2e-tests: chainsaw install run build-cli-with-coverage ## Run CLI end to end tests with coverage.
180180
## Tests the kubectl-skyhook CLI commands against a real cluster
181181
## Requires nodes labeled with skyhook.nvidia.com/test-node=skyhooke2e
182+
@mkdir -p $(REPORTING)/cli-cover
183+
@# Replace CLI binary with a wrapper that sets GOCOVERDIR for coverage collection
184+
@mv bin/skyhook bin/skyhook.orig 2>/dev/null || true
185+
@echo '#!/bin/bash' > bin/skyhook
186+
@echo 'SCRIPT_DIR="$$(cd "$$(dirname "$${BASH_SOURCE[0]}")" && pwd)"' >> bin/skyhook
187+
@echo 'export GOCOVERDIR="$$SCRIPT_DIR/../reporting/cli-cover"' >> bin/skyhook
188+
@echo 'exec "$$SCRIPT_DIR/skyhook-cover" "$$@"' >> bin/skyhook
189+
@chmod +x bin/skyhook
182190
$(CHAINSAW) test --test-dir ../k8s-tests/chainsaw/cli $(CHAINSAW_ARGS)
183191
$(MAKE) kill
192+
@# Restore original CLI binary
193+
@mv bin/skyhook.orig bin/skyhook 2>/dev/null || true
194+
@# Extract coverage from operator running in cluster
195+
go tool covdata textfmt -i=$(REPORTING)/int -o reporting/cli-int.coverprofile
196+
@# Extract coverage from CLI binary if any was generated
197+
@if [ -d "$(REPORTING)/cli-cover" ] && [ -n "$$(ls -A $(REPORTING)/cli-cover 2>/dev/null)" ]; then \
198+
go tool covdata textfmt -i=$(REPORTING)/cli-cover -o=$(REPORTING)/cli-e2e.coverprofile; \
199+
echo "✅ CLI coverage collected"; \
200+
else \
201+
echo "ℹ️ No CLI coverage data (this is OK - CLI is covered by unit tests)"; \
202+
fi
184203

185204
helm-tests: helm chainsaw
186205
## Here we need to run the operator so that the old CRD can deleted along with
@@ -197,12 +216,14 @@ operator-agent-tests: chainsaw install ## Run operator agent tests.
197216
$(CHAINSAW) test --test-dir ../k8s-tests/operator-agent $(CHAINSAW_ARGS)
198217
$(MAKE) kill
199218
## ../k8s-tests/operator-agent/setup.sh kind-worker teardown
219+
go tool covdata textfmt -i=$(REPORTING)/int -o reporting/int.coverprofile
200220

201221
deployment-policy-tests: chainsaw install run ## Run all deployment policy E2E tests (requires 15-node cluster).
202222
## requires a 15-node cluster to be running with access
203223
## use 'make create-deployment-policy-cluster' to create the cluster
204224
$(CHAINSAW) test --test-dir ../k8s-tests/chainsaw/deployment-policy $(CHAINSAW_ARGS)
205225
$(MAKE) kill
226+
go tool covdata textfmt -i=$(REPORTING)/int -o reporting/int.coverprofile
206227

207228
create-deployment-policy-cluster: ## Create a 15-node Kind cluster for deployment policy tests.
208229
@echo "🔧 Creating 15-node Kind cluster for deployment policy tests..."
@@ -255,11 +276,14 @@ endif
255276
.PHONY: merage-coverage
256277
merge-coverage:
257278
## merge coverage file into one so we can run totals and html reporting
258-
cat $(REPORTING)/*.coverprofile > reporting/temp-cover.out
259-
echo "mode: set" > $(REPORTING)/cover.out
260-
## skip first line with +2
261-
tail -n +2 $(REPORTING)/temp-cover.out | sed '/mode: set/d' >> $(REPORTING)/cover.out
262-
$(sedrp) 's|^/.*skyhook/operator/(.*)$$|github\.com/NVIDIA/skyhook/operator/\1|g' $(REPORTING)/cover.out
279+
@if ls $(REPORTING)/*.coverprofile 1> /dev/null 2>&1; then \
280+
cat $(REPORTING)/*.coverprofile > reporting/temp-cover.out; \
281+
echo "mode: set" > $(REPORTING)/cover.out; \
282+
tail -n +2 $(REPORTING)/temp-cover.out | sed '/mode: set/d' >> $(REPORTING)/cover.out; \
283+
$(sedrp) 's|^/.*skyhook/operator/(.*)$$|github\.com/NVIDIA/skyhook/operator/\1|g' $(REPORTING)/cover.out; \
284+
else \
285+
echo "No coverage files found - skipping merge"; \
286+
fi
263287

264288
.PHONY: lint
265289
lint: golangci-lint license-check ## Run golangci-lint linter & yamllint
@@ -280,15 +304,22 @@ build-manager: manifests generate fmt vet lint ## Build manager binary.
280304

281305
.PHONY: build-cli
282306
CLI_LDFLAGS := -ldflags "-X github.com/NVIDIA/skyhook/operator/internal/version.VERSION=$(VERSION) -X github.com/NVIDIA/skyhook/operator/internal/version.GIT_SHA=$(GIT_SHA)"
283-
build-cli: fmt vet ## Build CLI binary.
307+
build-cli: ## Build CLI binary.
284308
go build $(GOFLAGS) $(CLI_LDFLAGS) -o bin/skyhook cmd/cli/main.go
285309

310+
build-cli-with-coverage: ## Build CLI binary with coverage instrumentation.
311+
go build $(GOFLAGS) -cover $(CLI_LDFLAGS) -o bin/skyhook-cover cmd/cli/main.go
312+
286313
.PHONY: run
287314
ENABLE_WEBHOOKS?=false
288315
BACKGROUND?=true
289316
AGENT_IMAGE?=$(IMG_REPO)/agentless:6.2.0
290317
LOG_LEVEL?=info
318+
ifndef CI
319+
run: manifests generate reporting install kill ## Run a controller from your host.
320+
else
291321
run: manifests generate fmt vet lint reporting install kill ## Run a controller from your host.
322+
endif
292323
mkdir -p $(REPORTING)/int
293324
rm -rf $(REPORTING)/int/*
294325
go build $(GOFLAGS) -cover $(GO_LDFLAGS) -o $(LOCALBIN)/manager cmd/manager/main.go

0 commit comments

Comments
 (0)