Skip to content

Commit f8d9ac5

Browse files
authored
Merge pull request #1113 from rabbitmq/cluster-size-hint
Set cluster size hint
2 parents e186a81 + 7a7f89f commit f8d9ac5

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
k8s:
5454
- v1.24.1
5555
rabbitmq-image:
56-
- rabbitmq:3.9.0-management # minimum supported version
56+
- rabbitmq:3.9.9-management # minimum supported version
5757
- rabbitmq:3.10-management
5858
- pivotalrabbitmq/rabbitmq:master-otp-min
5959
- pivotalrabbitmq/rabbitmq:master-otp-max

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ under `site/kubernetes`.
3737

3838
## Supported Versions
3939

40-
The operator deploys RabbitMQ `3.10.2` by default, and supports versions from `3.9` upwards. The operator requires Kubernetes `1.19` or newer.
40+
The operator deploys RabbitMQ `3.10.2` by default, and supports versions from `3.9.9` upwards. The operator requires Kubernetes `1.19` or newer.
4141

4242
## Versioning
4343

internal/resource/configmap.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package resource
1111

1212
import (
1313
"fmt"
14+
"strconv"
1415
"strings"
1516

1617
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -27,12 +28,12 @@ import (
2728
const (
2829
ServerConfigMapName = "server-conf"
2930
defaultRabbitmqConf = `
31+
queue_master_locator = min-masters
32+
disk_free_limit.absolute = 2GB
33+
cluster_partition_handling = pause_minority
3034
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
3135
cluster_formation.k8s.host = kubernetes.default
32-
cluster_formation.k8s.address_type = hostname
33-
cluster_partition_handling = pause_minority
34-
queue_master_locator = min-masters
35-
disk_free_limit.absolute = 2GB`
36+
cluster_formation.k8s.address_type = hostname`
3637

3738
defaultTLSConf = `
3839
ssl_options.certfile = /etc/rabbitmq-tls/tls.crt
@@ -89,6 +90,10 @@ func (builder *ServerConfigMapBuilder) Update(object client.Object) error {
8990
}
9091
defaultSection := operatorConfiguration.Section("")
9192

93+
if _, err := defaultSection.NewKey("cluster_formation.target_cluster_size_hint", strconv.Itoa(int(*builder.Instance.Spec.Replicas))); err != nil {
94+
return err
95+
}
96+
9297
if _, err := defaultSection.NewKey("cluster_name", builder.Instance.Name); err != nil {
9398
return err
9499
}

internal/resource/configmap_test.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package resource_test
1212
import (
1313
"bytes"
1414
"fmt"
15+
"k8s.io/utils/pointer"
1516

1617
. "github.com/onsi/ginkgo/v2"
1718
. "github.com/onsi/gomega"
@@ -27,13 +28,14 @@ import (
2728

2829
func defaultRabbitmqConf(instanceName string) string {
2930
return iniString(`
30-
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
31-
cluster_formation.k8s.host = kubernetes.default
32-
cluster_formation.k8s.address_type = hostname
33-
cluster_partition_handling = pause_minority
34-
queue_master_locator = min-masters
35-
disk_free_limit.absolute = 2GB
36-
cluster_name = ` + instanceName)
31+
queue_master_locator = min-masters
32+
disk_free_limit.absolute = 2GB
33+
cluster_partition_handling = pause_minority
34+
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
35+
cluster_formation.k8s.host = kubernetes.default
36+
cluster_formation.k8s.address_type = hostname
37+
cluster_formation.target_cluster_size_hint = 1
38+
cluster_name = ` + instanceName)
3739
}
3840

3941
var _ = Describe("GenerateServerConfigMap", func() {
@@ -143,6 +145,16 @@ var _ = Describe("GenerateServerConfigMap", func() {
143145
Expect(configMap.Data).To(HaveKeyWithValue("operatorDefaults.conf", expectedConfiguration))
144146
})
145147

148+
It("sets cluster size hint", func() {
149+
builder.Instance.Spec.Rabbitmq.AdditionalConfig = ""
150+
builder.Instance.Spec.Replicas = pointer.Int32Ptr(100)
151+
152+
Expect(configMapBuilder.Update(configMap)).To(Succeed())
153+
operatorDefaultConf, err := ini.Load([]byte(configMap.Data["operatorDefaults.conf"]))
154+
Expect(err).To(Not(HaveOccurred()))
155+
Expect(operatorDefaultConf.Section("").KeysHash()).To(HaveKeyWithValue("cluster_formation.target_cluster_size_hint", "100"))
156+
})
157+
146158
When("valid userDefinedConfiguration is provided", func() {
147159
It("adds configurations in a new rabbitmq configuration", func() {
148160
userDefinedConfiguration := "cluster_formation.peer_discovery_backend = my-backend\n" +
@@ -375,6 +387,7 @@ CONSOLE_LOG=new`
375387
Name: "rabbit-tls",
376388
},
377389
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
390+
Replicas: pointer.Int32Ptr(1),
378391
TLS: rabbitmqv1beta1.TLSSpec{
379392
SecretName: "some-secret",
380393
DisableNonTLSListeners: true,
@@ -406,6 +419,7 @@ CONSOLE_LOG=new`
406419
Name: "rabbit-tls",
407420
},
408421
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
422+
Replicas: pointer.Int32Ptr(1),
409423
TLS: rabbitmqv1beta1.TLSSpec{
410424
SecretName: "some-secret",
411425
DisableNonTLSListeners: true,
@@ -453,6 +467,7 @@ CONSOLE_LOG=new`
453467
Name: "rabbit-tls",
454468
},
455469
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
470+
Replicas: pointer.Int32Ptr(1),
456471
TLS: rabbitmqv1beta1.TLSSpec{
457472
SecretName: "some-secret",
458473
CaSecretName: "some-mutual-secret",

0 commit comments

Comments
 (0)