Skip to content

Commit

Permalink
Merge 9b46138 into eb01907
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek committed Apr 7, 2023
2 parents eb01907 + 9b46138 commit 6e39276
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/providers/apisix/translation/apisix_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/scaffold/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/suite-chore/consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
})
})

0 comments on commit 6e39276

Please sign in to comment.