-
Notifications
You must be signed in to change notification settings - Fork 32
Operator fixes #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Operator fixes #563
Conversation
WalkthroughThe operator integration test workflow was enhanced with two new test steps to verify ConfigMap update triggers and selected APIs status accuracy, plus a debug step to emit diagnostic logs when failures occur. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - name: Test ConfigMap Update Trigger | ||
| run: | | ||
| echo "=== Testing ConfigMap Update Trigger ===" | ||
| # Get current configHash | ||
| INITIAL_HASH=$(kubectl get gateway test-gateway -o jsonpath='{.status.configHash}') | ||
| echo "Initial configHash: $INITIAL_HASH" | ||
| # Update ConfigMap | ||
| echo "Updating ConfigMap..." | ||
| kubectl patch configmap test-gateway-config --type merge -p '{"data":{"values.yaml":"# Updated config\nnameOverride: \"\""}}' | ||
| # Wait for Operator to reconcile (give it some time to detect change) | ||
| # The operator should detect the hash change and update the status | ||
| echo "Waiting for operator to process ConfigMap change..." | ||
| sleep 60 | ||
| # Get new configHash | ||
| NEW_HASH=$(kubectl get gateway test-gateway -o jsonpath='{.status.configHash}') | ||
| echo "New configHash: $NEW_HASH" | ||
| if [ "$INITIAL_HASH" == "$NEW_HASH" ]; then | ||
| echo "FAILED: configHash did not change after ConfigMap update!" | ||
| echo "Expected different hash than $INITIAL_HASH" | ||
| exit 1 | ||
| fi | ||
| echo "SUCCESS: configHash updated successfully." | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ConfigMap patch replaces the entire configuration, likely breaking the gateway.
Line 1152 replaces values.yaml with minimal content that lacks all the required gateway configuration (controller image, router image, policy engine config, etc.). This would likely cause the gateway to fail, making this test validate a broken state rather than a genuine config update scenario.
Additionally, the fixed 60-second sleep (line 1157) without polling is brittle and slow.
🔎 Recommended fix: Use a non-breaking config update
- # Update ConfigMap
echo "Updating ConfigMap..."
- kubectl patch configmap test-gateway-config --type merge -p '{"data":{"values.yaml":"# Updated config\nnameOverride: \"\""}}'
+ # Make a small, non-breaking change like adding a comment or annotation
+ CURRENT_CONFIG=$(kubectl get configmap test-gateway-config -o jsonpath='{.data.values\.yaml}')
+ UPDATED_CONFIG=$(echo "$CURRENT_CONFIG" | sed '1s/^/# Test update '"$(date +%s)"'\n/')
+ kubectl patch configmap test-gateway-config --type merge -p "{\"data\":{\"values.yaml\":\"$UPDATED_CONFIG\"}}"
- # Wait for Operator to reconcile (give it some time to detect change)
- # The operator should detect the hash change and update the status
- echo "Waiting for operator to process ConfigMap change..."
- sleep 60
+ # Poll for hash change instead of fixed sleep
+ echo "Polling for configHash change..."
+ for i in {1..30}; do
+ NEW_HASH=$(kubectl get gateway test-gateway -o jsonpath='{.status.configHash}')
+ if [ "$INITIAL_HASH" != "$NEW_HASH" ]; then
+ break
+ fi
+ echo "Attempt $i/30: Hash unchanged, waiting..."
+ sleep 2
+ done| - name: Test Status Accuracy (Selected APIs) | ||
| run: | | ||
| echo "=== Testing Status Accuracy (SelectedAPIs) ===" | ||
| # Current state: test-gateway has 'test-api' (1 API) | ||
| # Verify initial count | ||
| COUNT=$(kubectl get gateway test-gateway -o jsonpath='{.status.selectedAPIs}') | ||
| echo "Initial SelectedAPIs count: $COUNT" | ||
| if [ "$COUNT" != "1" ]; then | ||
| echo "FAILED: Expected 1 selected API, got $COUNT" | ||
| exit 1 | ||
| fi | ||
| # Add a second API | ||
| echo "Creating second API (status-test-api)..." | ||
| cat <<EOF | kubectl apply -f - | ||
| apiVersion: gateway.api-platform.wso2.com/v1alpha1 | ||
| kind: RestApi | ||
| metadata: | ||
| name: status-test-api | ||
| namespace: default | ||
| spec: | ||
| displayName: status-test-api | ||
| version: v1.0 | ||
| context: /status-test | ||
| upstream: | ||
| main: | ||
| url: http://httpbin.default.svc.cluster.local:80 | ||
| operations: | ||
| - method: GET | ||
| path: /get | ||
| EOF | ||
| echo "Waiting for status-test-api to be programmed..." | ||
| kubectl wait --for=condition=Programmed restapi/status-test-api --timeout=120s | ||
| # Wait for Gateway status update | ||
| sleep 10 | ||
| # Verify count incremented | ||
| COUNT=$(kubectl get gateway test-gateway -o jsonpath='{.status.selectedAPIs}') | ||
| echo "SelectedAPIs count after adding API: $COUNT" | ||
| if [ "$COUNT" != "2" ]; then | ||
| echo "FAILED: Expected 2 selected APIs, got $COUNT" | ||
| kubectl get restapi | ||
| exit 1 | ||
| fi | ||
| # Delete second API | ||
| echo "Deleting status-test-api..." | ||
| kubectl delete restapi status-test-api | ||
| echo "Waiting for deletion..." | ||
| kubectl wait --for=delete restapi/status-test-api --timeout=60s | ||
| # Wait for Gateway status update | ||
| sleep 10 | ||
| # Verify count decremented | ||
| COUNT=$(kubectl get gateway test-gateway -o jsonpath='{.status.selectedAPIs}') | ||
| echo "SelectedAPIs count after deleting API: $COUNT" | ||
| if [ "$COUNT" != "1" ]; then | ||
| echo "FAILED: Expected 1 selected API, got $COUNT" | ||
| exit 1 | ||
| fi | ||
| echo "SUCCESS: Status SelectedAPIs updated accurately." | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Replace fixed sleeps with polling to improve test reliability.
Lines 1209 and 1229 use fixed 10-second sleeps to wait for the gateway status to update. This creates a race condition—if the operator takes longer than 10 seconds to reconcile, the test becomes flaky.
🔎 Suggested improvement: Poll for status changes
For line 1209, replace:
- # Wait for Gateway status update
- sleep 10
-
- # Verify count incremented
COUNT=$(kubectl get gateway test-gateway -o jsonpath='{.status.selectedAPIs}')
+
+ # Poll for status update with timeout
+ echo "Polling for selectedAPIs count to update..."
+ for i in {1..20}; do
+ COUNT=$(kubectl get gateway test-gateway -o jsonpath='{.status.selectedAPIs}')
+ if [ "$COUNT" == "2" ]; then
+ break
+ fi
+ echo "Attempt $i/20: Count is $COUNT, waiting..."
+ sleep 2
+ done
+
echo "SelectedAPIs count after adding API: $COUNT"Apply similar polling logic at line 1229 for the deletion verification.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In .github/workflows/operator-integration-test.yml around lines 1171 to 1241 the
script uses fixed 10s sleeps at lines ~1209 and ~1229 which makes the test
flaky; replace each fixed sleep with a polling loop that repeatedly queries
kubectl get gateway test-gateway -o jsonpath='{.status.selectedAPIs}' (or uses
kubectl wait with a JSONPath/condition if available), compare against the
expected value (2 after creation, 1 after deletion), retry at short intervals
(e.g., 1s) with an overall timeout (e.g., 60–120s), and fail if the timeout is
reached; ensure you remove the hardcoded sleep lines and add the polling loop
before the verification checks so the script only proceeds when the Gateway
status has actually updated.
Purpose
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.