From cb56ea20d3d29ff8b686a393616374a18a80a163 Mon Sep 17 00:00:00 2001 From: Raihan Khan Date: Fri, 7 Jun 2024 18:31:19 +0600 Subject: [PATCH] Fix Rabbitmq getNodeName method (#116) Signed-off-by: raihankhan --- rabbitmq/http_client.go | 11 +++-------- rabbitmq/kubedb_client_builder.go | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/rabbitmq/http_client.go b/rabbitmq/http_client.go index d3a02d9b..a5d05d3d 100644 --- a/rabbitmq/http_client.go +++ b/rabbitmq/http_client.go @@ -106,15 +106,10 @@ func (c *HTTPClient) IsNodePrimaryReplica(queues []rabbithole.QueueInfo, node st return false } -func (c *HTTPClient) GetNodeNameFromPodURL(url string) (string, error) { - podClient, err := rabbithole.NewClient(url, c.Username, c.Password) +func (c *HTTPClient) GetNodeName() (string, error) { + overview, err := c.Overview() if err != nil { - klog.Error(err, "Failed to create new client for pod url", url) - return "", err - } - overview, err := podClient.Overview() - if err != nil { - klog.Error(err, "Failed to get node overview from node client", url) + klog.Error(err, "Failed to get node overview from node client") return "", err } return overview.Node, nil diff --git a/rabbitmq/kubedb_client_builder.go b/rabbitmq/kubedb_client_builder.go index a6d8f2fd..26ea1960 100644 --- a/rabbitmq/kubedb_client_builder.go +++ b/rabbitmq/kubedb_client_builder.go @@ -49,6 +49,7 @@ const ( rabbitmqQueueTypeClassic = "classic" ) +// NewKubeDBClientBuilder returns a client builder only for amqp client func NewKubeDBClientBuilder(kc client.Client, db *api.RabbitMQ) *KubeDBClientBuilder { return &KubeDBClientBuilder{ kc: kc, @@ -56,6 +57,14 @@ func NewKubeDBClientBuilder(kc client.Client, db *api.RabbitMQ) *KubeDBClientBui } } +// NewKubeDBClientBuilderForHTTP returns a KubeDB client builder only for http client +func NewKubeDBClientBuilderForHTTP(kc client.Client, db *api.RabbitMQ) *KubeDBClientBuilder { + return NewKubeDBClientBuilder(kc, db). + WithContext(context.TODO()). + WithAMQPClientDisabled(). + WithHTTPClientEnabled() +} + func (o *KubeDBClientBuilder) WithPod(podName string) *KubeDBClientBuilder { o.podName = podName return o @@ -158,7 +167,11 @@ func (o *KubeDBClientBuilder) GetAMQPconnURL(username string, password string) s } func (o *KubeDBClientBuilder) GetHTTPconnURL() string { - return fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", o.db.OffshootName(), o.db.Namespace, api.RabbitMQManagementUIPort) + protocolScheme := rmqhttp.HTTP + if o.podName != "" { + return fmt.Sprintf("%s://%s.%s.%s.svc:%d", protocolScheme, o.podName, o.db.GoverningServiceName(), o.db.Namespace, api.RabbitMQManagementUIPort) + } + return fmt.Sprintf("%s://%s.%s.svc.cluster.local:%d", protocolScheme, o.db.ServiceName(), o.db.Namespace, api.RabbitMQManagementUIPort) } // RabbitMQ server have a default virtual host "/"