Skip to content

Commit 641b07d

Browse files
author
Nick Barber
committed
Use annotation instead of field on cluster
1 parent 6875e59 commit 641b07d

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

controllers/suite_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,8 @@ var _ = BeforeSuite(func() {
190190
ObjectMeta: metav1.ObjectMeta{
191191
Name: "example-rabbit",
192192
Namespace: "default",
193-
},
194-
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
195-
MessagingTopologyNamespaces: []string{
196-
"allowed",
193+
Annotations: map[string]string{
194+
"rabbitmq.topology.allowed-namespaces": "allowed",
197195
},
198196
},
199197
}
@@ -240,10 +238,8 @@ var _ = BeforeSuite(func() {
240238
ObjectMeta: metav1.ObjectMeta{
241239
Name: "allow-all-rabbit",
242240
Namespace: "default",
243-
},
244-
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
245-
MessagingTopologyNamespaces: []string{
246-
"*",
241+
Annotations: map[string]string{
242+
"rabbitmq.topology.allowed-namespaces": "*",
247243
},
248244
},
249245
}

internal/cluster_reference.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
910
topology "github.com/rabbitmq/messaging-topology-operator/api/v1beta1"
@@ -14,7 +15,7 @@ import (
1415

1516
var (
1617
NoSuchRabbitmqClusterError = errors.New("RabbitmqCluster object does not exist")
17-
ResourceNotAllowedError = errors.New("Resource is not allowed to reference defined cluster reference. Check the namespace of the resource is allowed as part of the cluster's .spec.messagingTopologyNamespaces field")
18+
ResourceNotAllowedError = errors.New("Resource is not allowed to reference defined cluster reference. Check the namespace of the resource is allowed as part of the cluster's `rabbitmq.topology.allowed-namespaces` annotation")
1819
)
1920

2021
func ParseRabbitmqClusterReference(ctx context.Context, c client.Client, rmq topology.RabbitmqClusterReference, requestNamespace string) (*rabbitmqv1beta1.RabbitmqCluster, *corev1.Service, *corev1.Secret, error) {
@@ -31,10 +32,12 @@ func ParseRabbitmqClusterReference(ctx context.Context, c client.Client, rmq top
3132

3233
if rmq.Namespace != "" && rmq.Namespace != requestNamespace {
3334
var isAllowed bool
34-
for _, allowedNamespace := range cluster.Spec.MessagingTopologyNamespaces {
35-
if requestNamespace == allowedNamespace || allowedNamespace == "*" {
36-
isAllowed = true
37-
break
35+
if allowedNamespaces, ok := cluster.Annotations["rabbitmq.topology.allowed-namespaces"]; ok {
36+
for _, allowedNamespace := range strings.Split(allowedNamespaces, ",") {
37+
if requestNamespace == allowedNamespace || allowedNamespace == "*" {
38+
isAllowed = true
39+
break
40+
}
3841
}
3942
}
4043
if isAllowed == false {

0 commit comments

Comments
 (0)