Support custom container registry for database images

Currently, trove guest agent is pulling container images from docker
hub, it's impossible to use private container registry, this patch
is adding that support.

Change-Id: I3d14810b43acbf5d2fe6afcc138d476e366042f4
This commit is contained in:
Lingxian Kong 2021-02-02 23:06:10 +13:00
parent 1e04b269ca
commit 52f7b67dc2
3 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
features:
- Added custom container registry configuration for trove guest agent, it's
now possible to use images in private registry rather than docker hub.

View File

@ -1500,6 +1500,24 @@ service_credentials_opts = [
help="Keystone region name of the Trove service project."),
]
guest_agent_group = cfg.OptGroup(
'guest_agent', title='Guest Agent options',
help="Config options used by guest agent.")
guest_agent_opts = [
cfg.StrOpt(
'container_registry',
help='URL to the registry. E.g. https://index.docker.io/v1/'
),
cfg.StrOpt(
'container_registry_username',
help='The registry username.'
),
cfg.StrOpt(
'container_registry_password',
help='The plaintext registry password.'
),
]
CONF = cfg.CONF
CONF.register_opts(path_opts)
@ -1522,6 +1540,7 @@ CONF.register_group(db2_group)
CONF.register_group(mariadb_group)
CONF.register_group(network_group)
CONF.register_group(service_credentials_group)
CONF.register_group(guest_agent_group)
CONF.register_opts(mysql_opts, mysql_group)
CONF.register_opts(percona_opts, percona_group)
@ -1537,6 +1556,7 @@ CONF.register_opts(db2_opts, db2_group)
CONF.register_opts(mariadb_opts, mariadb_group)
CONF.register_opts(network_opts, network_group)
CONF.register_opts(service_credentials_opts, service_credentials_group)
CONF.register_opts(guest_agent_opts, guest_agent_group)
CONF.register_opts(rpcapi_cap_opts, upgrade_levels)
@ -1557,6 +1577,7 @@ def list_opts():
(mariadb_group, mariadb_opts),
(network_group, network_opts),
(service_credentials_group, service_credentials_opts),
(guest_agent_group, guest_agent_opts),
]
return keystone_middleware_opts + keystone_loading_opts + trove_opts

View File

@ -88,6 +88,17 @@ class Manager(periodic_task.PeriodicTasks):
self.app = None
self.status = None
if CONF.guest_agent.container_registry:
try:
self.docker_client.login(
CONF.guest_agent.container_registry_username,
CONF.guest_agent.container_registry_password,
email="",
registry=CONF.guest_agent.container_registry)
except Exception as exc:
raise exception.GuestError(f"Failed to login the container "
f"registry, error: {str(exc)}")
@property
def manager_name(self):
"""This returns the passed-in name of the manager."""