Skip to content

Commit c50e2ac

Browse files
authored
fix(e2e): resolve recommend-mode Chainsaw intermittent timeout (#92)
* fix(e2e): resolve recommend-mode Chainsaw intermittent timeout The verify-status step asserted Ready=False/InsufficientData, a transient state the operator passes through before collecting Prometheus data. With minimumDataPoints=1 and a 15s scrape interval, the operator can transition to Ready=True/Monitoring within seconds, causing the static assert to timeout waiting for a condition that already passed. Replace the static assert with a script-based poll that accepts either InsufficientData or Monitoring as valid states. Add a verify-no-resizes step to confirm Recommend mode does not apply changes. Closes #87 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca> * fix(ci): add issues:write permission and single API call for pr-size labels The pr-size workflow failed with HTTP 401 on gh pr edit --add-label because label management uses the Issues API, which needs issues:write permission (not just pull-requests:write). Also replaced 6 sequential gh pr edit calls with a single REST API PUT that fetches current labels, filters out size/* labels, and sets the new one in one call. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca> --------- Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 0434c08 commit c50e2ac

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

.github/workflows/pr-size.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
permissions:
77
contents: read
88
pull-requests: write
9+
issues: write
910

1011
jobs:
1112
size-label:
@@ -43,11 +44,13 @@ jobs:
4344
4445
echo "PR #${PR_NUMBER}: +${ADDITIONS} -${DELETIONS} = ${TOTAL} lines -> ${SIZE}"
4546
46-
# Remove any existing size labels, then add the correct one
47-
for label in size/xs size/s size/m size/l size/xl; do
48-
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --remove-label "$label" 2>/dev/null || true
49-
done
50-
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --add-label "$SIZE"
47+
# Fetch current labels, swap the size/* label in one API call
48+
REPO="${{ github.repository }}"
49+
KEEP=$(gh api "repos/${REPO}/issues/${PR_NUMBER}" --jq \
50+
'[.labels[].name | select(startswith("size/") | not)]')
51+
FINAL=$(echo "$KEEP" | jq --arg s "$SIZE" '. + [$s]')
52+
echo "$FINAL" | jq '{labels: .}' | \
53+
gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" --method PUT --input -
5154
5255
# Post a warning comment for XL PRs
5356
if [ "$SIZE" = "size/xl" ]; then

test/e2e/recommend-mode/chainsaw-test.yaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@ spec:
9494
status:
9595
readyReplicas: 1
9696
- name: verify-status
97+
try:
98+
- script:
99+
timeout: 3m
100+
content: |
101+
# The operator may transition quickly from InsufficientData to Monitoring
102+
# when minimumDataPoints is 1 and Prometheus scrapes fast. Accept either
103+
# state as valid — both prove the policy discovered the workload and
104+
# the controller reconciled it.
105+
for i in $(seq 1 36); do
106+
reason=$(kubectl get attunepolicy recommend-test -n e2e-recommend-mode \
107+
-o jsonpath='{.status.conditions[?(@.type=="Ready")].reason}' 2>/dev/null)
108+
discovered=$(kubectl get attunepolicy recommend-test -n e2e-recommend-mode \
109+
-o jsonpath='{.status.workloads.discovered}' 2>/dev/null)
110+
if [ "$discovered" = "1" ]; then
111+
if [ "$reason" = "InsufficientData" ] || [ "$reason" = "Monitoring" ]; then
112+
echo "OK: workloads discovered=$discovered, Ready reason=$reason"
113+
exit 0
114+
fi
115+
fi
116+
echo "Waiting... discovered=$discovered reason=$reason"
117+
sleep 5
118+
done
119+
echo "FAIL: timed out waiting for policy to discover workloads"
120+
kubectl get attunepolicy recommend-test -n e2e-recommend-mode -o yaml
121+
exit 1
122+
- name: verify-no-resizes
97123
try:
98124
- assert:
99125
resource:
@@ -103,10 +129,8 @@ spec:
103129
name: recommend-test
104130
namespace: e2e-recommend-mode
105131
status:
106-
conditions:
107-
- type: Ready
108-
status: "False"
109-
reason: InsufficientData
132+
workloads:
133+
resized: 0
110134
catch:
111135
- describe:
112136
apiVersion: attune.io/v1alpha1

0 commit comments

Comments
 (0)