Skip to content

feat: support consumer labels from metadata labels#2760

Merged
AlinsRan merged 3 commits into
apache:masterfrom
AlinsRan:feat/issue-398-consumer-metadata-labels-apache
May 12, 2026
Merged

feat: support consumer labels from metadata labels#2760
AlinsRan merged 3 commits into
apache:masterfrom
AlinsRan:feat/issue-398-consumer-metadata-labels-apache

Conversation

@AlinsRan
Copy link
Copy Markdown
Contributor

@AlinsRan AlinsRan commented May 8, 2026

Summary

  • reuse ApisixConsumer.metadata.labels and Consumer.metadata.labels as consumer labels
  • add a shared label helper so controller-generated labels always win on conflicts
  • align ApisixRoute with the same merge behavior and add coverage

Consumer labels

This change is mainly for propagating CRD labels into data plane resource labels.

Both ApisixConsumer.metadata.labels and Consumer.metadata.labels are 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

apiVersion: apisix.apache.org/v2
kind: ApisixConsumer
metadata:
  namespace: ingress-apisix
  name: alice
  labels:
    team: payments
    plan: gold
spec:
  ingressClassName: apisix
  authParameter:
    keyAuth:
      value:
        key: alice-primary-key

Consumer CRD example

apiVersion: apisix.apache.org/v1alpha1
kind: Consumer
metadata:
  namespace: ingress-apisix
  name: bob
  labels:
    team: platform
    tenant: internal
spec:
  gatewayRef:
    name: apisix
  credentials:
  - type: key-auth
    name: bob-key
    config:
      key: bob-primary-key

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"
  }
}

The same merge behavior also applies to Consumer resources, so labels defined on either CRD can be consumed directly on the data plane side.

Testing

  • go test ./internal/controller/label ./internal/adc/translator
  • go test $(go list ./... | grep -v /e2e | grep -v /conformance) (the benchmark package still requires a live Kubernetes endpoint in this environment)

AlinsRan and others added 3 commits May 8, 2026 15:27
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>
@AlinsRan AlinsRan merged commit b0fa3e5 into apache:master May 12, 2026
26 of 28 checks passed
@AlinsRan AlinsRan deleted the feat/issue-398-consumer-metadata-labels-apache branch May 12, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants