Skip to content

Commit bdb67a6

Browse files
authored
Merge pull request ceph#62592 from adk3798/cephadm-rgw-only-bind-on-networks
mgr/cephadm: add only_bind_port_on_networks support for rgw Reviewed-by: Kushal Deb <[email protected]> Reviewed-by: Shweta Bhosale <[email protected]>
2 parents 3cb14d6 + 2a3213b commit bdb67a6

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/pybind/mgr/cephadm/services/cephadmservice.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,36 +1135,51 @@ def prepare_create(self, daemon_spec: CephadmDaemonDeploySpec) -> CephadmDaemonD
11351135
if extra_ssl_cert_provided and spec.generate_cert:
11361136
raise OrchestratorError("Cannot provide ssl_certificate in combination with generate_cert")
11371137

1138+
# pick ip RGW should bind to
1139+
ip_to_bind_to = ''
1140+
if spec.only_bind_port_on_networks and spec.networks:
1141+
assert daemon_spec.host is not None
1142+
ip_to_bind_to = self.mgr.get_first_matching_network_ip(daemon_spec.host, spec) or ''
1143+
if ip_to_bind_to:
1144+
daemon_spec.port_ips = {str(port): ip_to_bind_to}
1145+
else:
1146+
logger.warning(
1147+
f'Failed to find ip in {spec.networks} for host {daemon_spec.host}. '
1148+
f'{daemon_spec.name()} will bind to all IPs'
1149+
)
1150+
elif daemon_spec.ip:
1151+
ip_to_bind_to = daemon_spec.ip
1152+
11381153
if ftype == 'beast':
11391154
if spec.ssl:
1140-
if daemon_spec.ip:
1155+
if ip_to_bind_to:
11411156
args.append(
1142-
f"ssl_endpoint={build_url(host=daemon_spec.ip, port=port).lstrip('/')}")
1157+
f"ssl_endpoint={build_url(host=ip_to_bind_to, port=port).lstrip('/')}")
11431158
else:
11441159
args.append(f"ssl_port={port}")
11451160
if spec.generate_cert:
11461161
args.append(f"ssl_certificate=config://rgw/cert/{daemon_spec.name()}")
11471162
elif not extra_ssl_cert_provided:
11481163
args.append(f"ssl_certificate=config://rgw/cert/{spec.service_name()}")
11491164
else:
1150-
if daemon_spec.ip:
1151-
args.append(f"endpoint={build_url(host=daemon_spec.ip, port=port).lstrip('/')}")
1165+
if ip_to_bind_to:
1166+
args.append(f"endpoint={build_url(host=ip_to_bind_to, port=port).lstrip('/')}")
11521167
else:
11531168
args.append(f"port={port}")
11541169
elif ftype == 'civetweb':
11551170
if spec.ssl:
1156-
if daemon_spec.ip:
1171+
if ip_to_bind_to:
11571172
# note the 's' suffix on port
1158-
args.append(f"port={build_url(host=daemon_spec.ip, port=port).lstrip('/')}s")
1173+
args.append(f"port={build_url(host=ip_to_bind_to, port=port).lstrip('/')}s")
11591174
else:
11601175
args.append(f"port={port}s") # note the 's' suffix on port
11611176
if spec.generate_cert:
11621177
args.append(f"ssl_certificate=config://rgw/cert/{daemon_spec.name()}")
11631178
elif not extra_ssl_cert_provided:
11641179
args.append(f"ssl_certificate=config://rgw/cert/{spec.service_name()}")
11651180
else:
1166-
if daemon_spec.ip:
1167-
args.append(f"port={build_url(host=daemon_spec.ip, port=port).lstrip('/')}")
1181+
if ip_to_bind_to:
1182+
args.append(f"port={build_url(host=ip_to_bind_to, port=port).lstrip('/')}")
11681183
else:
11691184
args.append(f"port={port}")
11701185
else:

src/python-common/ceph/deployment/service_spec.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ def __init__(self,
12241224
extra_container_args: Optional[GeneralArgList] = None,
12251225
extra_entrypoint_args: Optional[GeneralArgList] = None,
12261226
custom_configs: Optional[List[CustomConfig]] = None,
1227+
only_bind_port_on_networks: bool = False,
12271228
rgw_realm_token: Optional[str] = None,
12281229
update_endpoints: Optional[bool] = False,
12291230
zone_endpoints: Optional[str] = None, # comma separated endpoints list
@@ -1277,6 +1278,8 @@ def __init__(self,
12771278
self.update_endpoints = update_endpoints
12781279
self.zone_endpoints = zone_endpoints
12791280
self.zonegroup_hostnames = zonegroup_hostnames
1281+
#: Whether to limit ip we bind to to what's specified in "networks" parameter
1282+
self.only_bind_port_on_networks = only_bind_port_on_networks
12801283

12811284
#: To track op metrics by user config value rgw_user_counters_cache must be set to true
12821285
self.rgw_user_counters_cache = rgw_user_counters_cache

0 commit comments

Comments
 (0)