feat: support consumer labels from metadata labels#409
feat: support consumer labels from metadata labels#409AlinsRan wants to merge 2 commits intoapi7:masterfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR adds support for custom labels on APISIX consumers and routes. A new ChangesLabel Preservation Enhancement
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Adds support for propagating Kubernetes metadata.labels into translated APISIX resources (Consumers and Routes) while ensuring controller-generated labels always take precedence on key conflicts. This enables user-defined labeling use cases (e.g., APISIX consumer label workflows) without breaking the controller’s label-based identification.
Changes:
- Introduce
label.GenLabelWithObjectLabelsto merge object metadata labels with controller labels (controller labels win on conflicts). - Use the new helper when translating
ApisixConsumerlabels andApisixRouteroute labels (replacing the previous overwrite-prone merge). - Add unit tests covering merge behavior and precedence guarantees.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/controller/label/label.go | Adds helper to merge object labels with controller-generated labels (controller wins). |
| internal/controller/label/label_test.go | Adds unit test verifying merge behavior and conflict precedence. |
| internal/adc/translator/apisixroute.go | Switches route label generation to the shared merge helper; removes manual merge logic. |
| internal/adc/translator/apisixroute_test.go | Adds coverage ensuring metadata labels don’t override controller labels for routes. |
| internal/adc/translator/apisixconsumer.go | Switches consumer label generation to include metadata labels while preserving controller precedence. |
| internal/adc/translator/apisixconsumer_test.go | Adds coverage ensuring consumer metadata labels are included without overriding controller labels. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Labels: map[string]string{ | ||
| "team": "payments", | ||
| "k8s/name": "user-value", | ||
| "k8s/resource-key": "user-resource-key", | ||
| }, |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
ApisixConsumer.metadata.labelsas APISIX consumer labelsApisixRoutewith the same merge behavior and add coverageCloses #398
Testing
go test ./internal/controller/label ./internal/adc/translatorgo test $(go list ./... | grep -v /e2e | grep -v /conformance)Summary by CodeRabbit
Release Notes
Bug Fixes
Tests