Skip to content

Commit b5d7713

Browse files
committed
Drop '-client' suffix from rmq service
- rename ClientService override to Service override - rename client_service.go to service.go
1 parent bc8bc2f commit b5d7713

18 files changed

+132
-128
lines changed

api/v1beta1/rabbitmqcluster_types.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ type RabbitmqClusterSpec struct {
7272
}
7373

7474
type RabbitmqClusterOverrideSpec struct {
75-
StatefulSet *StatefulSet `json:"statefulSet,omitempty"`
76-
ClientService *ClientService `json:"clientService,omitempty"`
75+
StatefulSet *StatefulSet `json:"statefulSet,omitempty"`
76+
Service *Service `json:"service,omitempty"`
7777
}
7878

79-
type ClientService struct {
79+
type Service struct {
8080
// +optional
8181
*EmbeddedLabelsAnnotations `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
8282
// Spec defines the behavior of a service.
@@ -151,7 +151,7 @@ type StatefulSetSpec struct {
151151
UpdateStrategy *appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty" protobuf:"bytes,7,opt,name=updateStrategy"`
152152
}
153153

154-
// It is used in ClientService and StatefulSet
154+
// It is used in Service and StatefulSet
155155
type EmbeddedLabelsAnnotations struct {
156156
// Map of string keys and values that can be used to organize and categorize
157157
// (scope and select) objects. May match selectors of replication controllers
@@ -277,12 +277,12 @@ type RabbitmqClusterPersistenceSpec struct {
277277
Storage *k8sresource.Quantity `json:"storage,omitempty"`
278278
}
279279

280-
// Settable attributes for the Client Service resource.
280+
// Settable attributes for the Service resource.
281281
type RabbitmqClusterServiceSpec struct {
282282
// +kubebuilder:validation:Enum=ClusterIP;LoadBalancer;NodePort
283283
// +kubebuilder:default:="ClusterIP"
284284
Type corev1.ServiceType `json:"type,omitempty"`
285-
// Annotations to add to the Client Service.
285+
// Annotations to add to the Service.
286286
Annotations map[string]string `json:"annotations,omitempty"`
287287
}
288288

@@ -396,7 +396,7 @@ type RabbitmqClusterList struct {
396396
}
397397

398398
func (cluster RabbitmqCluster) ChildResourceName(name string) string {
399-
return strings.Join([]string{cluster.Name, name}, "-")
399+
return strings.TrimSuffix(strings.Join([]string{cluster.Name, name}, "-"), "-")
400400
}
401401

402402
func init() {

api/v1beta1/zz_generated.deepcopy.go

+28-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/tsmgr/bind.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
template: |
1010
local clientFilterFunc(j) = std.length(std.findSubstr("rabbitmq-client", j.name)) > 0;
11-
local clientService = std.filter(clientFilterFunc, $.services)[0];
11+
local service = std.filter(clientFilterFunc, $.services)[0];
1212
local secretFilterFunc(j) = std.length(std.findSubstr("rabbitmq-default-user", j.name)) > 0;
1313
local defaultUser = std.filter(secretFilterFunc, $.secrets);
1414
1515
local vhost = "%2F";
16-
local ingress = if clientService.spec.type == "LoadBalancer" then
17-
if std.objectHas(clientService.status.loadBalancer.ingress[0], "hostname") then
18-
clientService.status.loadBalancer.ingress[0].hostname
16+
local ingress = if service.spec.type == "LoadBalancer" then
17+
if std.objectHas(service.status.loadBalancer.ingress[0], "hostname") then
18+
service.status.loadBalancer.ingress[0].hostname
1919
else
20-
clientService.status.loadBalancer.ingress[0].ip
20+
service.status.loadBalancer.ingress[0].ip
2121
else
22-
clientService.spec.clusterIP;
22+
service.spec.clusterIP;
2323
local defaultUserUsername = defaultUser[0].data['username'];
2424
local defaultUserPassword = defaultUser[0].data['password'];
2525
local mgmtURI = "http://" + ingress + ":15672";

config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ spec:
663663
type: array
664664
override:
665665
properties:
666-
clientService:
666+
service:
667667
properties:
668668
metadata:
669669
properties:
@@ -3700,12 +3700,12 @@ spec:
37003700
service:
37013701
default:
37023702
type: ClusterIP
3703-
description: Settable attributes for the Client Service resource.
3703+
description: Settable attributes for the Service resource.
37043704
properties:
37053705
annotations:
37063706
additionalProperties:
37073707
type: string
3708-
description: Annotations to add to the Client Service.
3708+
description: Annotations to add to the Service.
37093709
type: object
37103710
type:
37113711
default: ClusterIP

controllers/rabbitmqcluster_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (r *RabbitmqClusterReconciler) getChildResources(ctx context.Context, rmq r
268268
}
269269

270270
if err := r.Client.Get(ctx,
271-
types.NamespacedName{Name: rmq.ChildResourceName("client"), Namespace: rmq.Namespace},
271+
types.NamespacedName{Name: rmq.ChildResourceName(resource.ServiceSuffix), Namespace: rmq.Namespace},
272272
endPoints); err != nil && !errors.IsNotFound(err) {
273273
return nil, err
274274
} else if errors.IsNotFound(err) {

controllers/rabbitmqcluster_controller_test.go

+29-29
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ var _ = Describe("RabbitmqClusterController", func() {
109109
Expect(secret.OwnerReferences[0].Name).To(Equal(cluster.Name))
110110
})
111111

112-
By("creating a rabbitmq client service", func() {
113-
svc := service(ctx, cluster, "client")
114-
Expect(svc.Name).To(Equal(cluster.ChildResourceName("client")))
112+
By("creating a rabbitmq service", func() {
113+
svc := service(ctx, cluster, "")
114+
Expect(svc.Name).To(Equal(cluster.ChildResourceName("")))
115115
Expect(svc.OwnerReferences[0].Name).To(Equal(cluster.Name))
116116
Expect(svc.Spec.Type).To(Equal(corev1.ServiceTypeClusterIP))
117117
})
@@ -148,7 +148,7 @@ var _ = Describe("RabbitmqClusterController", func() {
148148
By("recording SuccessfulCreate events for all child resources", func() {
149149
allEventMsgs := aggregateEventMsgs(ctx, cluster, "SuccessfulCreate")
150150
Expect(allEventMsgs).To(ContainSubstring("created resource %s of Type *v1.StatefulSet", cluster.ChildResourceName("server")))
151-
Expect(allEventMsgs).To(ContainSubstring("created resource %s of Type *v1.Service", cluster.ChildResourceName("client")))
151+
Expect(allEventMsgs).To(ContainSubstring("created resource %s of Type *v1.Service", cluster.ChildResourceName("")))
152152
Expect(allEventMsgs).To(ContainSubstring("created resource %s of Type *v1.Service", cluster.ChildResourceName("nodes")))
153153
Expect(allEventMsgs).To(ContainSubstring("created resource %s of Type *v1.ConfigMap", cluster.ChildResourceName("plugins-conf")))
154154
Expect(allEventMsgs).To(ContainSubstring("created resource %s of Type *v1.ConfigMap", cluster.ChildResourceName("server-conf")))
@@ -259,10 +259,10 @@ var _ = Describe("RabbitmqClusterController", func() {
259259
})
260260
})
261261

262-
Context("Client service configurations", func() {
262+
Context("Service configurations", func() {
263263
AfterEach(func() {
264264
Expect(client.Delete(ctx, cluster)).To(Succeed())
265-
Expect(clientSet.CoreV1().Services(cluster.Namespace).Delete(ctx, cluster.ChildResourceName("client"), metav1.DeleteOptions{}))
265+
Expect(clientSet.CoreV1().Services(cluster.Namespace).Delete(ctx, cluster.ChildResourceName(""), metav1.DeleteOptions{}))
266266
})
267267

268268
It("creates the service type and annotations as configured in instance spec", func() {
@@ -277,7 +277,7 @@ var _ = Describe("RabbitmqClusterController", func() {
277277

278278
Expect(client.Create(ctx, cluster)).To(Succeed())
279279

280-
clientSvc := service(ctx, cluster, "client")
280+
clientSvc := service(ctx, cluster, "")
281281
Expect(clientSvc.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
282282
Expect(clientSvc.Annotations).Should(HaveKeyWithValue("annotations", "cr-annotation"))
283283
})
@@ -352,8 +352,8 @@ var _ = Describe("RabbitmqClusterController", func() {
352352

353353
Context("Custom Resource updates", func() {
354354
var (
355-
clientServiceName string
356-
stsName string
355+
svcName string
356+
stsName string
357357
)
358358
BeforeEach(func() {
359359
cluster = &rabbitmqv1beta1.RabbitmqCluster{
@@ -362,7 +362,7 @@ var _ = Describe("RabbitmqClusterController", func() {
362362
Namespace: defaultNamespace,
363363
},
364364
}
365-
clientServiceName = cluster.ChildResourceName("client")
365+
svcName = cluster.ChildResourceName("")
366366
stsName = cluster.ChildResourceName("server")
367367

368368
Expect(client.Create(ctx, cluster)).To(Succeed())
@@ -380,14 +380,14 @@ var _ = Describe("RabbitmqClusterController", func() {
380380
})).To(Succeed())
381381

382382
Eventually(func() map[string]string {
383-
clientServiceName := cluster.ChildResourceName("client")
384-
service, _ := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, clientServiceName, metav1.GetOptions{})
385-
return service.Annotations
383+
svcName := cluster.ChildResourceName("")
384+
svc, _ := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, svcName, metav1.GetOptions{})
385+
return svc.Annotations
386386
}, 3).Should(HaveKeyWithValue("test-key", "test-value"))
387387

388-
// verify that SuccessfulUpdate event is recorded for the client service
388+
// verify that SuccessfulUpdate event is recorded for the service
389389
Expect(aggregateEventMsgs(ctx, cluster, "SuccessfulUpdate")).To(
390-
ContainSubstring("updated resource %s of Type *v1.Service", cluster.ChildResourceName("client")))
390+
ContainSubstring("updated resource %s of Type *v1.Service", cluster.ChildResourceName("")))
391391
})
392392

393393
It("the CPU and memory requirements are updated", func() {
@@ -452,7 +452,7 @@ var _ = Describe("RabbitmqClusterController", func() {
452452
})).To(Succeed())
453453

454454
Eventually(func() map[string]string {
455-
service, err := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, clientServiceName, metav1.GetOptions{})
455+
service, err := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, svcName, metav1.GetOptions{})
456456
Expect(err).NotTo(HaveOccurred())
457457
return service.Labels
458458
}, 3).Should(HaveKeyWithValue("foo", "bar"))
@@ -482,7 +482,7 @@ var _ = Describe("RabbitmqClusterController", func() {
482482
}, 3).Should(HaveKeyWithValue(annotationKey, annotationValue))
483483

484484
Eventually(func() map[string]string {
485-
service, err := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, cluster.ChildResourceName("client"), metav1.GetOptions{})
485+
service, err := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, cluster.ChildResourceName(""), metav1.GetOptions{})
486486
Expect(err).NotTo(HaveOccurred())
487487
return service.Annotations
488488
}, 3).Should(HaveKeyWithValue(annotationKey, annotationValue))
@@ -570,7 +570,7 @@ var _ = Describe("RabbitmqClusterController", func() {
570570
})).To(Succeed())
571571

572572
Eventually(func() string {
573-
service, err := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, cluster.ChildResourceName("client"), metav1.GetOptions{})
573+
service, err := clientSet.CoreV1().Services(cluster.Namespace).Get(ctx, cluster.ChildResourceName(""), metav1.GetOptions{})
574574
Expect(err).NotTo(HaveOccurred())
575575
return string(service.Spec.Type)
576576
}, 3).Should(Equal("NodePort"))
@@ -623,7 +623,7 @@ var _ = Describe("RabbitmqClusterController", func() {
623623

624624
Context("Recreate child resources after deletion", func() {
625625
var (
626-
clientServiceName string
626+
svcName string
627627
headlessServiceName string
628628
stsName string
629629
configMapName string
@@ -635,7 +635,7 @@ var _ = Describe("RabbitmqClusterController", func() {
635635
Namespace: defaultNamespace,
636636
},
637637
}
638-
clientServiceName = cluster.ChildResourceName("client")
638+
svcName = cluster.ChildResourceName("")
639639
headlessServiceName = cluster.ChildResourceName("nodes")
640640
stsName = cluster.ChildResourceName("server")
641641
configMapName = cluster.ChildResourceName("server-conf")
@@ -652,15 +652,15 @@ var _ = Describe("RabbitmqClusterController", func() {
652652
oldConfMap, err := clientSet.CoreV1().ConfigMaps(defaultNamespace).Get(ctx, configMapName, metav1.GetOptions{})
653653
Expect(err).NotTo(HaveOccurred())
654654

655-
oldClientSvc := service(ctx, cluster, "client")
655+
oldClientSvc := service(ctx, cluster, "")
656656

657657
oldHeadlessSvc := service(ctx, cluster, "nodes")
658658

659659
oldSts := statefulSet(ctx, cluster)
660660

661661
Expect(clientSet.AppsV1().StatefulSets(defaultNamespace).Delete(ctx, stsName, metav1.DeleteOptions{})).NotTo(HaveOccurred())
662662
Expect(clientSet.CoreV1().ConfigMaps(defaultNamespace).Delete(ctx, configMapName, metav1.DeleteOptions{})).NotTo(HaveOccurred())
663-
Expect(clientSet.CoreV1().Services(defaultNamespace).Delete(ctx, clientServiceName, metav1.DeleteOptions{})).NotTo(HaveOccurred())
663+
Expect(clientSet.CoreV1().Services(defaultNamespace).Delete(ctx, svcName, metav1.DeleteOptions{})).NotTo(HaveOccurred())
664664
Expect(clientSet.CoreV1().Services(defaultNamespace).Delete(ctx, headlessServiceName, metav1.DeleteOptions{})).NotTo(HaveOccurred())
665665

666666
Eventually(func() bool {
@@ -672,7 +672,7 @@ var _ = Describe("RabbitmqClusterController", func() {
672672
}, 5).Should(BeTrue())
673673

674674
Eventually(func() bool {
675-
clientSvc, err := clientSet.CoreV1().Services(defaultNamespace).Get(ctx, clientServiceName, metav1.GetOptions{})
675+
clientSvc, err := clientSet.CoreV1().Services(defaultNamespace).Get(ctx, svcName, metav1.GetOptions{})
676676
if err != nil {
677677
return false
678678
}
@@ -1038,7 +1038,7 @@ var _ = Describe("RabbitmqClusterController", func() {
10381038
})
10391039
})
10401040

1041-
Context("Client Service Override", func() {
1041+
Context("Service Override", func() {
10421042

10431043
BeforeEach(func() {
10441044
cluster = &rabbitmqv1beta1.RabbitmqCluster{
@@ -1051,7 +1051,7 @@ var _ = Describe("RabbitmqClusterController", func() {
10511051
Type: "LoadBalancer",
10521052
},
10531053
Override: rabbitmqv1beta1.RabbitmqClusterOverrideSpec{
1054-
ClientService: &rabbitmqv1beta1.ClientService{
1054+
Service: &rabbitmqv1beta1.Service{
10551055
Spec: &corev1.ServiceSpec{
10561056
Ports: []corev1.ServicePort{
10571057
{
@@ -1081,11 +1081,11 @@ var _ = Describe("RabbitmqClusterController", func() {
10811081
waitForClusterDeletion(ctx, cluster, client)
10821082
})
10831083

1084-
It("creates a Client Service with the override applied", func() {
1084+
It("creates a Service with the override applied", func() {
10851085
amqpTargetPort := intstr.IntOrString{IntVal: int32(5672)}
10861086
managementTargetPort := intstr.IntOrString{IntVal: int32(15672)}
10871087
additionalTargetPort := intstr.IntOrString{IntVal: int32(15535)}
1088-
svc := service(ctx, cluster, "client")
1088+
svc := service(ctx, cluster, "")
10891089
Expect(svc.Spec.Type).To(Equal(corev1.ServiceTypeClusterIP))
10901090
Expect(svc.Spec.Ports).To(ConsistOf(
10911091
corev1.ServicePort{
@@ -1114,11 +1114,11 @@ var _ = Describe("RabbitmqClusterController", func() {
11141114

11151115
It("updates", func() {
11161116
Expect(updateWithRetry(cluster, func(r *rabbitmqv1beta1.RabbitmqCluster) {
1117-
cluster.Spec.Override.ClientService.Spec.Type = "LoadBalancer"
1117+
cluster.Spec.Override.Service.Spec.Type = "LoadBalancer"
11181118
})).To(Succeed())
11191119

11201120
Eventually(func() corev1.ServiceType {
1121-
svc := service(ctx, cluster, "client")
1121+
svc := service(ctx, cluster, "")
11221122
return svc.Spec.Type
11231123
}, 5).Should(Equal(corev1.ServiceTypeLoadBalancer))
11241124
})

controllers/reconcile_status.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func (r *RabbitmqClusterReconciler) setDefaultUserStatus(ctx context.Context, rm
1212
defaultUserStatus := &rabbitmqv1beta1.RabbitmqClusterDefaultUser{}
1313

1414
serviceRef := &rabbitmqv1beta1.RabbitmqClusterServiceReference{
15-
Name: rmq.ChildResourceName("client"),
15+
Name: rmq.ChildResourceName(""),
1616
Namespace: rmq.Namespace,
1717
}
1818
defaultUserStatus.ServiceReference = serviceRef

0 commit comments

Comments
 (0)