Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sync apisix upstream labels #1553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/providers/apisix/translation/apisix_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func (t *translator) translateExternalApisixUpstream(namespace, upstream string)
if err != nil {
return nil, err
}
for k, v := range au.ObjectMeta.Labels {
ups.Metadata.Labels[k] = v
}
ups.Name = apisixv1.ComposeExternalUpstreamName(namespace, upstream)
ups.ID = id.GenID(ups.Name)

Expand Down
39 changes: 39 additions & 0 deletions test/e2e/suite-chore/consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,42 @@ spec:
}))
})
})

var _ = ginkgo.Describe("suite-chore: apisix upstream labels sync", func() {
suites := func(s *scaffold.Scaffold) {
ginkgo.JustBeforeEach(func() {
labels := map[string]string{"key": "value", "foo": "bar"}
au := `
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
name: foo
labels:
foo: bar
key: value
spec:
timeout:
read: 10s
send: 10s
`
assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(au))
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1), "Checking number of upstreams")

upstreams, _ := s.ListApisixUpstreams()
assert.Len(ginkgo.GinkgoT(), upstreams, 1)
// check if labels exists
for _, route := range upstreams {
eq := reflect.DeepEqual(route.Metadata.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,
}))
})
})