Skip to content

Commit e66450e

Browse files
author
Mladen Rusev
committed
try code coverage script
1 parent 0ae6dbd commit e66450e

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

.github/workflows/tests.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ jobs:
6464

6565
- run: make -j test-unit test-helm
6666

67+
- name: Upload test artifacts
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: unit-artifacts
71+
path: _bin/artifacts
72+
6773
test-e2e:
6874
if: contains(github.event.pull_request.labels.*.name, 'test-e2e')
6975
runs-on: ubuntu-latest
@@ -125,6 +131,11 @@ jobs:
125131
CLOUDSDK_COMPUTE_ZONE: europe-west1-b
126132
CLUSTER_NAME: ${{ steps.timestamp.outputs.cluster_name }}
127133
134+
- name: Setup upterm session
135+
uses: owenthereal/action-upterm@v1
136+
with:
137+
limit-access-to-actor: true
138+
128139
- name: Delete GKE Cluster
129140
# 'always()' - Run this step regardless of success or failure.
130141
# '!contains(...)' - AND only run if the list of PR labels DOES NOT contain 'keep-e2e-cluster'.
@@ -136,3 +147,9 @@ jobs:
136147
--project=machineidentitysecurity-jsci-e \
137148
--zone=europe-west1-b \
138149
--quiet
150+
151+
- name: Upload test artifacts
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: e2e-artifacts
155+
path: _bin/artifacts

hack/e2e/test.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ if ! gcloud container clusters get-credentials "${CLUSTER_NAME}"; then
8383
fi
8484
kubectl create ns venafi || true
8585

86+
kubectl apply -n venafi -f - <<EOF
87+
apiVersion: v1
88+
kind: PersistentVolumeClaim
89+
metadata:
90+
name: coverage-pvc
91+
spec:
92+
accessModes:
93+
- ReadWriteOnce
94+
resources:
95+
requests:
96+
storage: 1Gi
97+
EOF
98+
8699
# Pull secret for Venafi OCI registry
87100
# IMPORTANT: we pick the first team as the owning team for the registry and
88101
# workload identity service account as it doesn't matter.
@@ -123,10 +136,13 @@ venctl components kubernetes apply \
123136
--venafi-kubernetes-agent \
124137
--venafi-kubernetes-agent-version "${RELEASE_HELM_CHART_VERSION}" \
125138
--venafi-kubernetes-agent-values-files "${script_dir}/values.venafi-kubernetes-agent.yaml" \
139+
--venafi-kubernetes-agent-values-files "${script_dir}/values.coverage-pvc.yaml" \
126140
--venafi-kubernetes-agent-custom-image-registry "${OCI_BASE}/images" \
127141
--venafi-kubernetes-agent-custom-chart-repository "oci://${OCI_BASE}/charts"
128142

129143
kubectl apply -n venafi -f venafi-components.yaml
144+
kubectl set env deployments/venafi-kubernetes-agent -n venafi GOCOVERDIR=/coverage
145+
kubectl rollout status deployment/venafi-kubernetes-agent -n venafi --timeout=2m
130146

131147
subject="system:serviceaccount:venafi:venafi-components"
132148
audience="https://${VEN_API_HOST}"
@@ -233,3 +249,47 @@ getCertificate() {
233249

234250
# Wait 5 minutes for the certificate to appear.
235251
for ((i=0;;i++)); do if getCertificate; then exit 0; fi; sleep 30; done | timeout -v -- 5m cat
252+
253+
echo "Identifying the agent pod to terminate..."
254+
export AGENT_POD_NAME=$(kubectl get pods -n venafi -l app.kubernetes.io/name=venafi-kubernetes-agent -o jsonpath="{.items[0].metadata.name}")
255+
256+
echo "Gracefully deleting agent pod '${AGENT_POD_NAME}' to flush coverage to the PVC..."
257+
kubectl delete pod -n venafi "${AGENT_POD_NAME}" --grace-period=30
258+
echo "Waiting for agent pod to terminate..."
259+
kubectl wait --for=delete pod/${AGENT_POD_NAME} -n venafi --timeout=90s
260+
261+
kubectl apply -n venafi -f - <<EOF
262+
apiVersion: v1
263+
kind: Pod
264+
metadata:
265+
name: coverage-helper-pod
266+
spec:
267+
containers:
268+
- name: helper
269+
image: alpine:latest
270+
command: ["sleep", "infinity"]
271+
volumeMounts:
272+
- name: coverage-storage
273+
mountPath: /coverage-data
274+
volumes:
275+
- name: coverage-storage
276+
persistentVolumeClaim:
277+
claimName: coverage-pvc
278+
EOF
279+
280+
echo "Waiting for the helper pod to be ready..."
281+
kubectl wait --for=condition=Ready pod/coverage-helper-pod -n venafi --timeout=2m
282+
283+
echo "Copying coverage files from the helper pod..."
284+
mkdir -p $COVERAGE_HOST_PATH
285+
# We copy from the helper pod's mount path.
286+
kubectl cp -n venafi "coverage-helper-pod:/coverage-data/." $COVERAGE_HOST_PATH
287+
288+
echo "Coverage files retrieved. Listing contents:"
289+
ls -la $COVERAGE_HOST_PATH
290+
291+
# --- MANDATORY CLEANUP ---
292+
#echo "Cleaning up helper pod and PersistentVolumeClaim..."
293+
#kubectl delete pod coverage-helper-pod -n venafi
294+
#kubectl delete pvc coverage-pvc -n venafi
295+
#echo "Cleanup complete."

hack/e2e/values.coverage-pvc.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
volumes:
2+
- name: coverage-storage
3+
persistentVolumeClaim:
4+
claimName: coverage-pvc
5+
6+
volumeMounts:
7+
- name: coverage-storage
8+
mountPath: /coverage

make/00_mod.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ kind_cluster_config := $(bin_dir)/scratch/kind_cluster.yaml
1313

1414
build_names := preflight
1515

16+
# HACK: The test-unit and test-e2e targets require the go binary to be built with the -cover flag set.
17+
# This allows us to do coverage reporting for our end-to-end tests.
18+
ifeq ($(findstring test-,$(MAKECMDGOALS)),test-)
19+
go_preflight_flags := -cover
20+
endif
21+
COVERAGE_HOST_PATH := $(CURDIR)/$(bin_dir)/artifacts
22+
1623
go_preflight_main_dir := .
1724
go_preflight_mod_dir := .
1825
go_preflight_ldflags := \

0 commit comments

Comments
 (0)