feat: support consumer labels from metadata labels#409
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Superseded by #410. Closing this fork-based PR so CI can use repository secrets from the same-repo branch workflow. |
Summary
ApisixConsumer.metadata.labelsandConsumer.metadata.labelsas consumer labelsApisixRoutewith the same merge behavior and add coverageConsumer labels
This change is mainly for propagating CRD labels into data plane resource labels.
Both
ApisixConsumer.metadata.labelsandConsumer.metadata.labelsare propagated to the generated APISIX consumer as custom labels, so users can inject business metadata such as tenant, team, or plan from the Kubernetes CRD into the data plane resource.If a user-defined label key conflicts with a controller-generated reserved label, the controller-generated value is preserved.
ApisixConsumer CRD example
Consumer CRD example
Data plane result example
The generated APISIX consumer will carry the injected labels together with controller-managed labels, for example:
{ "username": "ingress-apisix_alice", "labels": { "team": "payments", "plan": "gold", "k8s/name": "alice", "k8s/namespace": "ingress-apisix", "k8s/kind": "ApisixConsumer", "k8s/controller-name": "apisix.apache.org/apisix-ingress-controller", "manager-by": "apisix-ingress-controller", "k8s/resource-key": "ApisixConsumer/ingress-apisix/alice" } }The same merge behavior also applies to
Consumerresources, so labels defined on either CRD can be consumed directly on the data plane side.Testing
go test ./internal/controller/label ./internal/adc/translatorgo test $(go list ./... | grep -v /e2e | grep -v /conformance)Summary by CodeRabbit
Bug Fixes
Tests