Skip to content

Commit

Permalink
[#18572]yugabyted: Binding advertise_address to hostname for docker b…
Browse files Browse the repository at this point in the history
…ased deployments.

Summary:
In docker based deployments, yugabyted by default binds to the ip_address of the container. When the hostname machine restarts, yugabyted fails to restart as the ip-address of the container would have changed. Updating the default behavior of yugabyted to bind with container `hostname` in docker deployments.

### Tests

1. Start yugabyted node docker

```sh
docker run -d --name yugabyte --hostname yugabyte -p7000:7000 -p9000:9000 -p15433:15433 -p5433:5433 -p9042:9042 nchandrappa/yugabyte:2.25.0.0-hostname bin/yugabyted start --background=false
```

2. Stop YB container

```sh
docker stop <container-id>
```

3. Start YB container

```sh
docker start <container-id>
```
Jira: DB-7509

Test Plan: manual test

Reviewers: sgarg-yb

Reviewed By: sgarg-yb

Subscribers: yugabyted-dev

Differential Revision: https://phorge.dev.yugabyte.com/D39786
  • Loading branch information
nchandrappa committed Nov 8, 2024
1 parent 6b28bfd commit 59e080a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions bin/yugabyted
Original file line number Diff line number Diff line change
Expand Up @@ -7555,15 +7555,20 @@ class ControlScript(object):

if args.advertise_address is None:
if not self.configs.saved_data.get("advertise_address"):
if OS_NAME == "Linux":
# Case Scenario: When advertise_address has no value in conf file
# and the OS is Linux, set the advertise address to the private IP
# of the machine.
args.advertise_address = self.find_ip_address_of_node()

if str(os.path.exists("/.dockerenv")):
args.advertise_address = self.find_hostname_of_node()
else:
# Case Scenario: When advertise_address has no value in conf file
# and the OS is Mac, set the advertise address to 127.0.0.1.
args.advertise_address = IP_LOCALHOST
if OS_NAME == "Linux":
# Case Scenario: When advertise_address has no value in conf file
# and the OS is Linux, set the advertise address to the private IP
# of the machine.
args.advertise_address = self.find_ip_address_of_node()

else:
# Case Scenario: When advertise_address has no value in conf file
# and the OS is Mac, set the advertise address to 127.0.0.1.
args.advertise_address = IP_LOCALHOST
else:
# Case Scenario: When advertise_address has a value in conf file and then
# use that regardless of the OS.
Expand Down

0 comments on commit 59e080a

Please sign in to comment.