-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1139,6 +1139,106 @@ jobs: | |
| kubectl delete restapi multi-ns-api -n test-ns | ||
| kubectl delete namespace test-ns | ||
|
|
||
| - 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." | ||
|
|
||
| - 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." | ||
|
|
||
|
Comment on lines
+1171
to
+1241
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 changesFor 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.
🤖 Prompt for AI Agents |
||
| - name: Delete test RestApi | ||
| run: | | ||
| echo "Deleting RestApi test-api..." | ||
|
|
@@ -1347,6 +1447,7 @@ jobs: | |
| kubectl delete ns scoped-test ignored-ns --ignore-not-found | ||
|
|
||
|
|
||
|
|
||
| - name: Debug on failure - Dump logs | ||
| if: failure() | ||
| run: | | ||
|
|
||
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.yamlwith 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