Using general naming for app openstack

To make a downstream release of stx-openstack, we often have to also
rename all the app's helm and puppet plugins namespace and also change
code on sysinv. This change decouples the name of the openstack
application from its plugins in order to ease downstream development
and release.

Tests report: https://paste.opendev.org/show/810225/

Story: 2009669
Task: 43899

Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Change-Id: I4d4199b085b25e15ffeec77348e6d517bd808302
This commit is contained in:
Thiago Brito 2021-10-19 18:32:45 -03:00
parent 767278b5cb
commit 699f4c9eb6
6 changed files with 113 additions and 62 deletions

View File

@ -474,14 +474,15 @@ def _delete(host_fs):
if host_fs['name'] == constants.FILESYSTEM_NAME_IMAGE_CONVERSION:
try:
app = pecan.request.dbapi.kube_app_get(constants.HELM_APP_OPENSTACK)
app = utils.find_openstack_app(pecan.request.dbapi)
if app.status != constants.APP_UPLOAD_SUCCESS:
raise wsme.exc.ClientSideError(_("Deleting filesystem %s is not allowed "
"when stx-openstack is in %s state" %
(host_fs['name'], app.status)))
raise wsme.exc.ClientSideError(
_("Deleting filesystem %s is not allowed when %s is in %s "
"state" % (host_fs['name'], app.name, app.status))
)
except exception.KubeAppNotFound:
LOG.info("Application %s not found, deleting %s fs" %
(constants.HELM_APP_OPENSTACK, host_fs['name']))
LOG.info("Application %s not found, deleting %s fs"
% (app.name, host_fs['name']))
ihost = pecan.request.dbapi.ihost_get(host_fs['forihostid'])
try:

View File

@ -1536,7 +1536,7 @@ SYSTEM_SECURITY_FEATURE_SPECTRE_MELTDOWN_OPTS = {
SYSTEM_SECURITY_FEATURE_SPECTRE_MELTDOWN_DEFAULT_OPTS = SYSTEM_SECURITY_FEATURE_SPECTRE_MELTDOWN_V1_OPTS
# Helm: Supported application (aka chart bundles)
HELM_APP_OPENSTACK = 'stx-openstack'
HELM_APP_OPENSTACK = 'openstack'
HELM_APP_PLATFORM = 'platform-integ-apps'
HELM_APP_OIDC_AUTH = 'oidc-auth-apps'
HELM_APP_CERT_MANAGER = 'cert-manager'
@ -1558,7 +1558,7 @@ OPENSTACK_APP_APPLY_MODES = [
OPENSTACK_NORMAL
]
# Appliction Apply Modes
# Application Apply Modes
HELM_APP_APPLY_MODES = {
HELM_APP_OPENSTACK: OPENSTACK_APP_APPLY_MODES
}

View File

@ -1895,9 +1895,16 @@ def is_app_applied(dbapi, app_name):
return False
def find_openstack_app(dbapi):
return dbapi.kube_app_get_endswith(constants.HELM_APP_OPENSTACK)
def is_openstack_applied(dbapi):
""" Checks whether the OpenStack application is applied successfully. """
return is_app_applied(dbapi, constants.HELM_APP_OPENSTACK)
try:
return find_openstack_app(dbapi).active
except exception.KubeAppNotFound:
return False
def is_url(url_str):
@ -2483,6 +2490,26 @@ def generate_synced_metadata_fqpn(app_name, app_version):
'metadata.yaml')
def is_app_openstack(app_name):
return app_name.endswith("openstack")
def find_app_plugin_name(app_name):
return "openstack" if is_app_openstack(app_name) else app_name
def find_kube_app(dbapi, app_name):
try:
if is_app_openstack(app_name):
app_name = find_openstack_app(dbapi).name
app = dbapi.kube_app_get(app_name)
except exception.KubeAppNotFound:
LOG.exception("Application %s not found." % app_name)
raise
return app
def is_chart_enabled(dbapi, app_name, chart_name, namespace):
"""
Check if the chart is enable at an application level
@ -2495,7 +2522,7 @@ def is_chart_enabled(dbapi, app_name, chart_name, namespace):
enabled.
"""
try:
db_app = dbapi.kube_app_get(app_name)
db_app = find_kube_app(dbapi, app_name)
db_chart = dbapi.helm_override_get(db_app.id, chart_name, namespace)
except exception.KubeAppNotFound:
LOG.exception("is_chart_enabled: %s application unknown" % (app_name))

View File

@ -7893,6 +7893,22 @@ class Connection(api.Connection):
def kube_app_get(self, name):
return self._kube_app_get(name)
@objects.objectify(objects.kube_app)
def kube_app_get_endswith(self, name):
query = model_query(models.KubeApp)
try:
return query.filter(models.KubeApp.name.endswith(name)).one()
except NoResultFound:
raise exception.KubeAppNotFound(name="endswith '{}'".format(name))
except MultipleResultsFound:
LOG.exception(
exception.InvalidParameterValue(
err="Multiple app entries found ending with {}, returning "
"the first occurrence".format(name)
)
)
return query.filter(models.KubeApp.name.endswith(name)).first()
@objects.objectify(objects.kube_app)
def kube_app_update(self, app_id, values):
with _session_for_write() as session:

View File

@ -221,8 +221,9 @@ class HelmOperator(object):
def get_app_lifecycle_operator(self, app_name):
"""Return an AppLifecycle operator based on app name"""
if app_name in self.app_lifecycle_operators:
operator = self.app_lifecycle_operators[app_name]
plugin_name = utils.find_app_plugin_name(app_name)
if plugin_name in self.app_lifecycle_operators:
operator = self.app_lifecycle_operators[plugin_name]
else:
operator = self.app_lifecycle_operators['generic']
@ -269,8 +270,9 @@ class HelmOperator(object):
def get_armada_manifest_operator(self, app_name):
"""Return a manifest operator based on app name"""
if app_name in self.armada_manifest_operators:
manifest_op = self.armada_manifest_operators[app_name]
plugin_name = utils.find_app_plugin_name(app_name)
if plugin_name in self.armada_manifest_operators:
manifest_op = self.armada_manifest_operators[plugin_name]
else:
manifest_op = self.armada_manifest_operators['generic']
return manifest_op
@ -334,8 +336,10 @@ class HelmOperator(object):
namespaces = []
if chart_name in self.chart_operators:
app_plugin_name = utils.find_app_plugin_name(app_name)
namespaces = self.chart_operators[chart_name].get_namespaces_by_app(
app_name)
app_plugin_name)
return namespaces
def get_helm_chart_namespaces(self, chart_name):
@ -355,6 +359,7 @@ class HelmOperator(object):
@helm_context
def get_helm_chart_overrides(self, chart_name, cnamespace=None):
""" RPCApi: Gets the *chart* overrides for a supported chart. """
return self._get_helm_chart_overrides(chart_name, cnamespace)
def _get_helm_chart_overrides(self, chart_name, cnamespace=None):
@ -415,15 +420,11 @@ class HelmOperator(object):
overrides may be provided.
"""
try:
app = self.dbapi.kube_app_get(app_name)
except exception.KubeAppNotFound:
LOG.exception("Application %s not found." % app_name)
raise
app, plugin_name = self._find_kube_app_and_app_plugin_name(app_name)
app_namespaces = {}
if app_name in self.helm_system_applications:
for chart_name in self.helm_system_applications[app_name]:
if plugin_name in self.helm_system_applications:
for chart_name in self.helm_system_applications[plugin_name]:
try:
app_namespaces.update(
{chart_name:
@ -442,6 +443,7 @@ class HelmOperator(object):
@helm_context
def get_helm_application_overrides(self, app_name, cnamespace=None):
"""RPCApi: Gets the application overrides for a supported set of charts."""
return self._get_helm_application_overrides(app_name, cnamespace)
def _get_helm_application_overrides(self, app_name, cnamespace=None):
@ -487,8 +489,10 @@ class HelmOperator(object):
}
"""
overrides = {}
if app_name in self.helm_system_applications:
for chart_name in self.helm_system_applications[app_name]:
plugin_name = utils.find_app_plugin_name(app_name)
if plugin_name in self.helm_system_applications:
for chart_name in self.helm_system_applications[plugin_name]:
try:
overrides.update({chart_name:
self._get_helm_chart_overrides(
@ -648,7 +652,7 @@ class HelmOperator(object):
"""Generate system helm chart overrides
This method will generate system helm chart override an write them to a
yaml file.for use with the helm command. If the namespace is provided
yaml file for use with the helm command. If the namespace is provided
only the overrides file for that specified namespace will be written.
:param chart_name: name of a supported chart
@ -689,9 +693,9 @@ class HelmOperator(object):
"""Create the system overrides files for a supported application
This method will generate system helm chart overrides yaml files for a
set of supported charts that comprise an application.. If the namespace
set of supported charts that comprise an application. If the namespace
is provided only the overrides files for that specified namespace will
be written..
be written.
:param app_name: name of the bundle of charts required to support an
application
@ -706,23 +710,19 @@ class HelmOperator(object):
system overrides
"""
try:
app = self.dbapi.kube_app_get(app_name)
except exception.KubeAppNotFound:
LOG.exception("Application %s not found." % app_name)
raise
app, plugin_name = self._find_kube_app_and_app_plugin_name(app_name)
# Get a manifest operator to provide a single point of
# manipulation for the chart, chart group and manifest schemas
manifest_op = self.get_armada_manifest_operator(app_name)
manifest_op = self.get_armada_manifest_operator(app.name)
# Load the manifest into the operator
armada_manifest = utils.generate_synced_armada_manifest_fqpn(
app.name, app.app_version, app.manifest_file)
manifest_op.load(armada_manifest)
if app_name in self.helm_system_applications:
app_overrides = self._get_helm_application_overrides(app_name,
if plugin_name in self.helm_system_applications:
app_overrides = self._get_helm_application_overrides(plugin_name,
cnamespace)
for (chart_name, overrides) in iteritems(app_overrides):
if combined:
@ -828,6 +828,10 @@ class HelmOperator(object):
manifest_op.save_summary(path=path)
manifest_op.save_delete_manifest()
def _find_kube_app_and_app_plugin_name(self, app_name):
return utils.find_kube_app(self.dbapi, app_name), \
utils.find_app_plugin_name(app_name)
def remove_helm_chart_overrides(self, path, chart_name, cnamespace=None):
"""Remove the overrides files for a chart"""

View File

@ -141,33 +141,36 @@ class CephPuppet(openstack.OpenstackBasePuppet):
if cephfs_filesystems:
config['platform::ceph::params::cephfs_filesystems'] = cephfs_filesystems
if (utils.is_openstack_applied(self.dbapi) and
utils.is_chart_enabled(self.dbapi,
constants.HELM_APP_OPENSTACK,
self.HELM_CHART_SWIFT,
common.HELM_NS_OPENSTACK)):
app = self.dbapi.kube_app_get(constants.HELM_APP_OPENSTACK)
override = self.dbapi.helm_override_get(
app.id,
self.SERVICE_NAME_RGW,
common.HELM_NS_OPENSTACK)
password = override.system_overrides.get(
self.SERVICE_NAME_RGW, None)
if password:
swift_auth_password = password.encode('utf8', 'strict')
config.update(
{'platform::ceph::rgw::keystone::swift_endpts_enabled':
True})
config.pop('platform::ceph::rgw::keystone::rgw_admin_user')
config.update({'platform::ceph::rgw::keystone::rgw_admin_password':
swift_auth_password})
config.update({'platform::ceph::rgw::keystone::rgw_admin_domain':
self.RADOSGW_SERVICE_DOMAIN_NAME})
config.update({'platform::ceph::rgw::keystone::rgw_admin_project':
self.RADOSGW_SERVICE_PROJECT_NAME})
else:
raise exception.SysinvException(
"Unable to retreive containerized swift auth password")
if utils.is_openstack_applied(self.dbapi):
openstack_app = utils.find_openstack_app(self.dbapi)
if utils.is_chart_enabled(
self.dbapi,
openstack_app.name,
self.HELM_CHART_SWIFT,
common.HELM_NS_OPENSTACK
):
override = self.dbapi.helm_override_get(
openstack_app.id,
self.SERVICE_NAME_RGW,
common.HELM_NS_OPENSTACK)
password = override.system_overrides.get(
self.SERVICE_NAME_RGW, None)
if password:
swift_auth_password = password.encode('utf8', 'strict')
config.update(
{'platform::ceph::rgw::keystone::swift_endpts_enabled':
True})
config.pop('platform::ceph::rgw::keystone::rgw_admin_user')
config.update({'platform::ceph::rgw::keystone::rgw_admin_password':
swift_auth_password})
config.update({'platform::ceph::rgw::keystone::rgw_admin_domain':
self.RADOSGW_SERVICE_DOMAIN_NAME})
config.update({'platform::ceph::rgw::keystone::rgw_admin_project':
self.RADOSGW_SERVICE_PROJECT_NAME})
else:
raise exception.SysinvException(
"Unable to retreive containerized swift auth password")
return config