Skip to content

Commit

Permalink
Fix Rabbitmq getNodeName method (#116)
Browse files Browse the repository at this point in the history
Signed-off-by: raihankhan <[email protected]>
  • Loading branch information
raihankhan authored Jun 7, 2024
1 parent 19480f1 commit cb56ea2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 3 additions & 8 deletions rabbitmq/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion rabbitmq/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ 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,
db: db,
}
}

// 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
Expand Down Expand Up @@ -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 "/"
Expand Down

0 comments on commit cb56ea2

Please sign in to comment.