Add label 'app.starlingx.io/component=platform' to namespace
Add support to 'app.starlingx.io/component' to be overwritten by user override, with possible values being 'platform' and 'application'. With 'platform' being the default value.This change will also restart the pods if the label in namespace change. Test Plan: PASS: Install portieris and check with 'kubectl edit namespace portieris' if the 'app.starlingx.io/component' with value 'platform'. PASS: Add 'app.starlingx.io/component: application' to user override and check if 'app.starlingx.component' changes to 'application'. PASS: Use 'system application-apply portieris' when there is a change to be applied to 'app.starlingx.component' and verify if the pod is restarted. PASS: Change the 'app.starlingx.io/component' to a not supported value during user override apply and verify if 'app.starlingx.io/component' still 'platform' or 'application'. PASS: Run tox.ini tests to the current patch of this review. Signed-off-by: Karla Felix <karla.karolinenogueirafelix@windriver.com> Change-Id: If215ed95c3d0d57b3555019880b90baa7e2e22b8
This commit is contained in:
parent
064e0223f7
commit
52b1721376
@ -11,3 +11,4 @@ HELM_CHART_PORTIERIS = 'portieris'
|
||||
HELM_CHART_PORTIERIS_CERTS = 'portieris-certs'
|
||||
HELM_CHART_PSP_ROLEBINDING = 'portieris-psp-rolebinding'
|
||||
HELM_NS_PORTIERIS = 'portieris'
|
||||
HELM_COMPONENT_LABEL_PORTIERIS = 'app.starlingx.io/component'
|
||||
|
@ -16,6 +16,7 @@ from sysinv.common import constants
|
||||
from sysinv.common import exception
|
||||
from sysinv.helm import lifecycle_base as base
|
||||
from sysinv.helm.lifecycle_hook import LifecycleHookInfo
|
||||
import yaml
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -33,6 +34,11 @@ class PortierisAppLifecycleOperator(base.AppLifecycleOperator):
|
||||
:param hook_info: LifecycleHookInfo object
|
||||
|
||||
"""
|
||||
if hook_info.lifecycle_type == constants.APP_LIFECYCLE_TYPE_OPERATION:
|
||||
if hook_info.operation == constants.APP_APPLY_OP:
|
||||
if hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_POST:
|
||||
return self.post_apply(app_op, app, hook_info)
|
||||
|
||||
if hook_info.lifecycle_type == constants.APP_LIFECYCLE_TYPE_OPERATION:
|
||||
if hook_info.operation == constants.APP_BACKUP:
|
||||
if hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_PRE:
|
||||
@ -52,6 +58,62 @@ class PortierisAppLifecycleOperator(base.AppLifecycleOperator):
|
||||
context, conductor_obj, app_op, app, hook_info
|
||||
)
|
||||
|
||||
def post_apply(self, app_op, app, hook_info):
|
||||
"""Pre Apply actions
|
||||
|
||||
Creates the local registry secret and migrates helm user overrides
|
||||
from one chart name to another
|
||||
|
||||
:param app_op: AppOperator object
|
||||
:param app: AppOperator.Application object
|
||||
:param hook_info: LifecycleHookInfo object
|
||||
"""
|
||||
LOG.info(
|
||||
"Executing post_apply for {} app".format(constants.HELM_APP_PORTIERIS)
|
||||
)
|
||||
|
||||
dbapi_instance = app_op._dbapi
|
||||
db_app_id = dbapi_instance.kube_app_get(app.name).id
|
||||
|
||||
client_core = app_op._kube._get_kubernetesclient_core()
|
||||
component_constant = app_constants.HELM_COMPONENT_LABEL_PORTIERIS
|
||||
|
||||
# chart overrides
|
||||
chart_overrides = self._get_helm_user_overrides(
|
||||
dbapi_instance,
|
||||
db_app_id)
|
||||
|
||||
override_label = {}
|
||||
|
||||
# Namespaces variables
|
||||
namespace = client_core.read_namespace(app_constants.HELM_APP_PORTIERIS)
|
||||
|
||||
# Old namespace variable
|
||||
old_namespace_label = (namespace.metadata.labels.get(component_constant)
|
||||
if component_constant in namespace.metadata.labels
|
||||
else None)
|
||||
|
||||
if component_constant in chart_overrides:
|
||||
# User Override variables
|
||||
dict_chart_overrides = yaml.safe_load(chart_overrides)
|
||||
override_label = dict_chart_overrides.get(component_constant)
|
||||
|
||||
if override_label == 'application':
|
||||
namespace.metadata.labels.update({component_constant: 'application'})
|
||||
app_op._kube.kube_patch_namespace(app_constants.HELM_APP_PORTIERIS, namespace)
|
||||
elif override_label == 'platform':
|
||||
namespace.metadata.labels.update({component_constant: 'platform'})
|
||||
app_op._kube.kube_patch_namespace(app_constants.HELM_APP_PORTIERIS, namespace)
|
||||
elif not override_label:
|
||||
namespace.metadata.labels.update({component_constant: 'platform'})
|
||||
app_op._kube.kube_patch_namespace(app_constants.HELM_APP_PORTIERIS, namespace)
|
||||
else:
|
||||
LOG.info(f'WARNING: Namespace label {override_label} not supported')
|
||||
|
||||
namespace_label = namespace.metadata.labels.get(component_constant)
|
||||
if old_namespace_label != namespace_label:
|
||||
self._delete_portieris_pods(app_op, client_core)
|
||||
|
||||
def pre_backup(self, app_op, app):
|
||||
LOG.debug(
|
||||
"Executing pre_backup for {} app".format(constants.HELM_APP_PORTIERIS)
|
||||
@ -179,3 +241,15 @@ class PortierisAppLifecycleOperator(base.AppLifecycleOperator):
|
||||
self._update_helm_user_overrides(
|
||||
dbapi_instance, db_app_id, "\n".join([portieris_override] + other_overrides)
|
||||
)
|
||||
|
||||
def _delete_portieris_pods(self, app_op, client_core):
|
||||
# pod list
|
||||
pods = client_core.list_namespaced_pod(app_constants.HELM_NS_PORTIERIS)
|
||||
|
||||
# Delete pods to force restart when it have any change in namespace_label
|
||||
for pod in pods.items:
|
||||
app_op._kube.kube_delete_pod(
|
||||
name=pod.metadata.name,
|
||||
namespace=app_constants.HELM_NS_PORTIERIS,
|
||||
grace_periods_seconds=0
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user