This is an automated email from the ASF dual-hosted git repository.
lingsamuel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 4b1ad1bb feat: sync consumer crd labels to apisix (#1540)
4b1ad1bb is described below
commit 4b1ad1bb94845bcaf7f40119ccf256185bb62d59
Author: Abhishek Choudhary <[email protected]>
AuthorDate: Tue Apr 18 06:54:32 2023 +0530
feat: sync consumer crd labels to apisix (#1540)
* feat: sync consumer crd labels to apisix
* test-e2e: add e2e test case
---
.../apisix/translation/apisix_consumer.go | 3 ++
test/e2e/scaffold/k8s.go | 11 ++++++
test/e2e/suite-chore/consistency.go | 40 ++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/pkg/providers/apisix/translation/apisix_consumer.go
b/pkg/providers/apisix/translation/apisix_consumer.go
index c27eae64..16d4b97e 100644
--- a/pkg/providers/apisix/translation/apisix_consumer.go
+++ b/pkg/providers/apisix/translation/apisix_consumer.go
@@ -109,6 +109,9 @@ func (t *translator) TranslateApisixConsumerV2(ac
*configv2.ApisixConsumer) (*ap
}
consumer := apisixv1.NewDefaultConsumer()
+ for k, v := range ac.ObjectMeta.Labels {
+ consumer.Labels[k] = v
+ }
consumer.Username = apisixv1.ComposeConsumerName(ac.Namespace, ac.Name)
consumer.Plugins = plugins
return consumer, nil
diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go
index 2c69cadf..7467f62f 100644
--- a/test/e2e/scaffold/k8s.go
+++ b/test/e2e/scaffold/k8s.go
@@ -264,6 +264,17 @@ func (s *Scaffold) ensureNumApisixCRDsCreated(url string,
desired int) error {
return wait.Poll(3*time.Second, 35*time.Second, condFunc)
}
+// EnsureNumApisixConsumersCreated waits until desired number of Consumers are
created in
+// APISIX cluster.
+func (s *Scaffold) EnsureNumApisixConsumersCreated(desired int) error {
+ u := url.URL{
+ Scheme: "http",
+ Host: s.apisixAdminTunnel.Endpoint(),
+ Path: "/apisix/admin/consumers",
+ }
+ return s.ensureNumApisixCRDsCreated(u.String(), desired)
+}
+
// EnsureNumApisixRoutesCreated waits until desired number of Routes are
created in
// APISIX cluster.
func (s *Scaffold) EnsureNumApisixRoutesCreated(desired int) error {
diff --git a/test/e2e/suite-chore/consistency.go
b/test/e2e/suite-chore/consistency.go
index a16a6fe7..6ae42ce5 100644
--- a/test/e2e/suite-chore/consistency.go
+++ b/test/e2e/suite-chore/consistency.go
@@ -401,3 +401,43 @@ spec:
}))
})
})
+
+var _ = ginkgo.Describe("suite-chore: apisix consumer labels sync", func() {
+ suites := func(s *scaffold.Scaffold) {
+ ginkgo.JustBeforeEach(func() {
+ labels := map[string]string{"key": "value", "foo":
"bar"}
+ ac := `
+apiVersion: apisix.apache.org/v2
+kind: ApisixConsumer
+metadata:
+ name: foo
+ labels:
+ key: value
+ foo: bar
+spec:
+ authParameter:
+ jwtAuth:
+ secretRef:
+ name: jwt
+`
+ assert.Nil(ginkgo.GinkgoT(),
s.CreateResourceFromString(ac))
+ assert.Nil(ginkgo.GinkgoT(),
s.EnsureNumApisixConsumersCreated(1), "Checking number of consumers")
+
+ consumers, _ := s.ListApisixConsumers()
+ assert.Len(ginkgo.GinkgoT(), consumers, 1)
+ // check if labels exists
+ for _, route := range consumers {
+ eq := reflect.DeepEqual(route.Labels, labels)
+ assert.True(ginkgo.GinkgoT(), eq)
+ }
+ })
+ }
+
+ ginkgo.Describe("suite-chore: scaffold v2", func() {
+ suites(scaffold.NewScaffold(&scaffold.Options{
+ Name: "sync",
+ IngressAPISIXReplicas: 1,
+ ApisixResourceVersion:
scaffold.ApisixResourceVersion().V2,
+ }))
+ })
+})