Skip to content

Commit

Permalink
Support multiple uris for federation upstream (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunyiLyu committed Jun 2, 2021
1 parent ceca6c1 commit 28cbd05
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions api/v1beta1/federation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type FederationSpec struct {
RabbitmqClusterReference RabbitmqClusterReference `json:"rabbitmqClusterReference"`
// Secret contains the AMQP URI(s) for the upstream.
// The Secret must contain the key `uri` or operator will error.
// `uri` should be one or multiple uris separated by ','.
// Required property.
// +kubebuilder:validation:Required
UriSecret *corev1.LocalObjectReference `json:"uriSecret"`
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/rabbitmq.com_federations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ spec:
type: boolean
uriSecret:
description: Secret contains the AMQP URI(s) for the upstream. The
Secret must contain the key `uri` or operator will error. Required
property.
Secret must contain the key `uri` or operator will error. `uri`
should be one or multiple uris separated by ','. Required property.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
Expand Down
2 changes: 1 addition & 1 deletion docs/api/rabbitmq.com.ref.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ FederationSpec defines the desired state of Federation For how to configure fede
| *`name`* __string__ | Required property; cannot be updated
| *`vhost`* __string__ | Default to vhost '/'; cannot be updated
| *`rabbitmqClusterReference`* __xref:{anchor_prefix}-github-com-rabbitmq-messaging-topology-operator-api-v1beta1-rabbitmqclusterreference[$$RabbitmqClusterReference$$]__ | Reference to the RabbitmqCluster that the exchange will be created in. Required property.
| *`uriSecret`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#localobjectreference-v1-core[$$LocalObjectReference$$]__ | Secret contains the AMQP URI(s) for the upstream. The Secret must contain the key `uri` or operator will error. Required property.
| *`uriSecret`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#localobjectreference-v1-core[$$LocalObjectReference$$]__ | Secret contains the AMQP URI(s) for the upstream. The Secret must contain the key `uri` or operator will error. `uri` should be one or multiple uris separated by ','. Required property.
| *`prefetch-count`* __integer__ |
| *`ackMode`* __string__ |
| *`expires`* __integer__ |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-logr/logr v0.4.0
github.com/google/uuid v1.2.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1
github.com/michaelklishin/rabbit-hole/v2 v2.8.0
github.com/michaelklishin/rabbit-hole/v2 v2.9.0
github.com/onsi/ginkgo v1.16.3
github.com/onsi/gomega v1.13.0
github.com/rabbitmq/cluster-operator v1.7.0
Expand Down
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
Expand Down Expand Up @@ -509,8 +511,9 @@ github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182aff
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1 h1:hZD/8vBuw7x1WqRXD/WGjVjipbbo/HcDBgySYYbrUSk=
github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1/go.mod h1:DK1Cjkc0E49ShgRVs5jy5ASrM15svSnem3K/hiSGD8o=
github.com/michaelklishin/rabbit-hole/v2 v2.8.0 h1:5tehiLwdVtCeDcrxOlvoveRqU/AJMOcMeQntSf63fdc=
github.com/michaelklishin/rabbit-hole/v2 v2.8.0/go.mod h1:VZQTDutXFmoyrLvlRjM79MEPb0+xCLLhV5yBTjwMWkM=
github.com/michaelklishin/rabbit-hole/v2 v2.9.0 h1:ryVSTfyKhB+Zk6qM5UyQiyQKOTa7ZG4UvMjMuVkb5Zc=
github.com/michaelklishin/rabbit-hole/v2 v2.9.0/go.mod h1:lX3i5PipF2LTXKJu+fYbTNfwFJboYlcqNerV0iT6Gdg=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mikefarah/yq/v4 v4.7.1/go.mod h1:lhxVpMWdGvoeon5cMtBD3MKRuLKPHgRidR8oDFRNCsw=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down Expand Up @@ -547,7 +550,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down Expand Up @@ -679,8 +681,9 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71 h1:2MR0pKUzlP3SGgj5NYJe/zRYDwOu9ku6YHy+Iw7l5DM=
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
Expand Down Expand Up @@ -1099,8 +1102,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
3 changes: 2 additions & 1 deletion internal/federation_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ package internal
import (
rabbithole "github.com/michaelklishin/rabbit-hole/v2"
topology "github.com/rabbitmq/messaging-topology-operator/api/v1beta1"
"strings"
)

func GenerateFederationDefinition(f *topology.Federation, uri string) rabbithole.FederationDefinition {
return rabbithole.FederationDefinition{
Uri: uri,
Uri: strings.Split(uri, ","),
Expires: f.Spec.Expires,
MessageTTL: int32(f.Spec.MessageTTL),
MaxHops: f.Spec.MaxHops,
Expand Down
9 changes: 7 additions & 2 deletions internal/federation_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ var _ = Describe("GenerationFederationDefinition", func() {
}
})

It("sets 'uri' correctly", func() {
It("sets 'uri' correctly for a single uri", func() {
definition := GenerateFederationDefinition(f, "a-rabbitmq-uri@test.com")
Expect(definition.Uri).To(Equal("a-rabbitmq-uri@test.com"))
Expect(definition.Uri).To(ConsistOf("a-rabbitmq-uri@test.com"))
})

It("sets 'uri' correctly for multiple uris", func() {
definition := GenerateFederationDefinition(f, "a-rabbitmq-uri@test.com0,a-rabbitmq-uri@test1.com,a-rabbitmq-uri@test2.com")
Expect(definition.Uri).To(ConsistOf("a-rabbitmq-uri@test.com0", "a-rabbitmq-uri@test1.com", "a-rabbitmq-uri@test2.com"))
})

It("sets 'PrefetchCount' correctly", func() {
Expand Down
6 changes: 4 additions & 2 deletions system_tests/federation_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("federation", func() {
namespace = MustHaveEnv("NAMESPACE")
ctx = context.Background()
federation = &topology.Federation{}
federationUri = "amqp://server-name-my-upstream-test-uri"
federationUri = "amqp://server-name-my-upstream-test-uri0,amqp://server-name-my-upstream-test-uri1,amqp://server-name-my-upstream-test-uri2"
federationUriSecret corev1.Secret
)

Expand Down Expand Up @@ -69,7 +69,9 @@ var _ = Describe("federation", func() {

Expect(upstream.Name).To(Equal(federation.Spec.Name))
Expect(upstream.Vhost).To(Equal(federation.Spec.Vhost))
Expect(upstream.Definition.Uri).To(Equal(federationUri))
Expect(upstream.Definition.Uri).To(ConsistOf("amqp://server-name-my-upstream-test-uri0",
"amqp://server-name-my-upstream-test-uri1",
"amqp://server-name-my-upstream-test-uri2"))
Expect(upstream.Definition.Queue).To(Equal(federation.Spec.Queue))
Expect(upstream.Definition.MessageTTL).To(Equal(int32(federation.Spec.MessageTTL)))
Expect(upstream.Definition.AckMode).To(Equal(federation.Spec.AckMode))
Expand Down

0 comments on commit 28cbd05

Please sign in to comment.