From 99aab747131bf8ab27a7db0d7b2d9f8f85adc861 Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Wed, 5 Jul 2023 17:38:27 +0000 Subject: Exclude certain labels and fix issue with missing selectors Issue-ID: INT-2246 Signed-off-by: Lukasz Rajewski Change-Id: I84974b10ea0b62ccb81a9747e67fe4d9a79f43ba --- src/onaptests/configuration/status_settings.py | 3 +++ src/onaptests/steps/cloud/check_status.py | 36 +++++++++++++------------- src/onaptests/steps/cloud/resources.py | 8 ++++++ src/onaptests/templates/status/base.html.j2 | 4 +++ 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/onaptests/configuration/status_settings.py b/src/onaptests/configuration/status_settings.py index 0ad0f30..57ee1b3 100644 --- a/src/onaptests/configuration/status_settings.py +++ b/src/onaptests/configuration/status_settings.py @@ -20,6 +20,9 @@ FULL_LOGS_CONTAINERS = [ # patterns to be excluded from the check WAIVER_LIST = ['integration'] +EXCLUDED_LABELS = { +} + SPECIFIC_LOGS_CONTAINERS = { 'sdc-be': ['/var/log/onap/sdc/sdc-be/error.log'], 'sdc-onboarding-be': ['/var/log/onap/sdc/sdc-onboarding-be/error.log'], diff --git a/src/onaptests/steps/cloud/check_status.py b/src/onaptests/steps/cloud/check_status.py index 40f7c72..1fcb96b 100644 --- a/src/onaptests/steps/cloud/check_status.py +++ b/src/onaptests/steps/cloud/check_status.py @@ -67,6 +67,17 @@ class CheckK8sResourcesStep(BaseStep): """Parse the resources.""" return [] + def _add_failing_resource(self, resource): + if (resource.labels and settings.EXCLUDED_LABELS + and (resource.labels.keys() and settings.EXCLUDED_LABELS.keys())): + for label in resource.labels.items(): + for waived_label in settings.EXCLUDED_LABELS.items(): + if label[0] in waived_label[0] and label[1] in waived_label[1]: + return + self.__logger.warning("a {} is in error: {}".format(self.resource_type, resource.name)) + self.failing_resources.append(resource) + self.failing = True + def execute(self): super().execute() os.makedirs(self.res_dir, exist_ok=True) @@ -163,9 +174,7 @@ class CheckK8sPvcsStep(CheckK8sResourcesStep): field_selector=field_selector).items if k8s.status.phase != "Bound": - self.__logger.warning("a PVC is in error: {}".format(pvc.name)) - self.failing_resources.append(pvc) - self.failing = True + self._add_failing_resource(pvc) self.all_resources.append(pvc) @BaseStep.store_state @@ -247,11 +256,9 @@ class CheckK8sJobsStep(CheckK8sResourcesUsingPodsStep): # timemout job if not k8s.status.completion_time: - self.__logger.warning("a Job is in error: {}".format(job.name)) if any( waiver_elt not in job.name for waiver_elt in settings.WAIVER_LIST): - self.failing_resources.append(job) - self.failing = True + self._add_failing_resource(job) # completed job if any(waiver_elt not in job.name for waiver_elt in settings.WAIVER_LIST): self.all_resources.append(job) @@ -555,9 +562,7 @@ class CheckK8sDeploymentsStep(CheckK8sResourcesUsingPodsStep): self.res_dir, deployment.name)) if k8s.status.unavailable_replicas: - self.__logger.warning("a Deployment is in error: {}".format(deployment.name)) - self.failing_resources.append(deployment) - self.failing = True + self._add_failing_resource(deployment) self.all_resources.append(deployment) @@ -598,9 +603,7 @@ class CheckK8sResplicaSetsStep(CheckK8sResourcesUsingPodsStep): if (not k8s.status.ready_replicas or (k8s.status.ready_replicas < k8s.status.replicas)): - self.__logger.warning("a ReplicaSet is in error: {}".format(replicaset.name)) - self.failing_resources.append(replicaset) - self.failing = True + self._add_failing_resource(replicaset) self.all_resources.append(replicaset) @@ -641,9 +644,7 @@ class CheckK8sStatefulSetsStep(CheckK8sResourcesUsingPodsStep): if ((not k8s.status.ready_replicas) or (k8s.status.ready_replicas < k8s.status.replicas)): - self.__logger.warning("a StatefulSet is in error: {}".format(statefulset.name)) - self.failing_resources.append(statefulset) - self.failing = True + self._add_failing_resource(statefulset) self.all_resources.append(statefulset) @@ -683,9 +684,7 @@ class CheckK8sDaemonSetsStep(CheckK8sResourcesUsingPodsStep): self.res_dir, daemonset.name)) if (k8s.status.number_ready < k8s.status.desired_number_scheduled): - self.__logger.warning("a DaemonSet is in error: {}".format(daemonset.name)) - self.failing_resources.append(daemonset) - self.failing = True + self._add_failing_resource(daemonset) self.all_resources.append(daemonset) @@ -782,6 +781,7 @@ class CheckNamespaceStatusStep(CheckK8sResourcesStep): details[step.resource_type] = { 'number_all': len(step.all_resources), 'number_failing': len(step.failing_resources), + 'all': self.map_by_name(step.all_resources), 'failing': self.map_by_name(step.failing_resources) } with (Path(self.res_dir).joinpath(settings.STATUS_DETAILS_JSON)).open('w') as file: diff --git a/src/onaptests/steps/cloud/resources.py b/src/onaptests/steps/cloud/resources.py index 4509dd4..e8d16f9 100644 --- a/src/onaptests/steps/cloud/resources.py +++ b/src/onaptests/steps/cloud/resources.py @@ -9,9 +9,17 @@ class K8sResource(): self.k8s = k8s self.name = "" self.events = [] + self.labels = None + self.annotations = None if self.k8s: self.name = self.k8s.metadata.name + self.labels = self.k8s.metadata.labels + self.annotations = self.k8s.metadata.annotations self.specific_k8s_init() + if not self.labels: + self.labels = {} + if not self.annotations: + self.annotations = {} def specific_k8s_init(self): """Do the specific part for k8s resource when k8s object is present.""" diff --git a/src/onaptests/templates/status/base.html.j2 b/src/onaptests/templates/status/base.html.j2 index 41e55de..d46782d 100644 --- a/src/onaptests/templates/status/base.html.j2 +++ b/src/onaptests/templates/status/base.html.j2 @@ -97,7 +97,11 @@ is-danger {% if k8s.spec.selector.match_labels %} {{ key_value_description_list('Selector', k8s.spec.selector.match_labels) | indent(width=6) }} {% else %} + {% if k8s.spec.selector.items %} {{ key_value_description_list('Selector', k8s.spec.selector) | indent(width=6) }} + {% else %} + {{ key_value_description_list('Selector', dict()) | indent(width=6) }} + {% endif %} {% endif %} {% endif %} {% if k8s.phase %} -- cgit 1.2.3-korg