diff --git a/requirements.txt b/requirements.txt index 7a6e4eb5..54c43069 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,55 +1,58 @@ -about-time==4.2.1 ; python_version >= "3.9" and python_full_version < "3.13" -alive-progress==3.1.5 ; python_version >= "3.9" and python_full_version < "3.13" -boto3==1.34.62 ; python_version >= "3.9" and python_full_version < "3.13" -botocore==1.34.62 ; python_version >= "3.9" and python_full_version < "3.13" -cachetools==5.3.3 ; python_version >= "3.9" and python_full_version < "3.13" -certifi==2024.2.2 ; python_version >= "3.9" and python_full_version < "3.13" -charset-normalizer==3.3.2 ; python_version >= "3.9" and python_full_version < "3.13" -click==8.1.7 ; python_version >= "3.9" and python_full_version < "3.13" -colorama==0.4.6 ; python_version >= "3.9" and python_full_version < "3.13" -commonmark==0.9.1 ; python_version >= "3.9" and python_full_version < "3.13" -contourpy==1.2.0 ; python_version >= "3.9" and python_full_version < "3.13" -cycler==0.12.1 ; python_version >= "3.9" and python_full_version < "3.13" -dateparser==1.2.0 ; python_version >= "3.9" and python_full_version < "3.13" -fonttools==4.49.0 ; python_version >= "3.9" and python_full_version < "3.13" -google-auth==2.28.2 ; python_version >= "3.9" and python_full_version < "3.13" -grapheme==0.6.0 ; python_version >= "3.9" and python_full_version < "3.13" -httmock==1.4.0 ; python_version >= "3.9" and python_full_version < "3.13" -idna==3.7 ; python_version >= "3.9" and python_full_version < "3.13" -importlib-resources==6.3.0 ; python_version >= "3.9" and python_version < "3.10" -jmespath==1.0.1 ; python_version >= "3.9" and python_full_version < "3.13" -kiwisolver==1.4.5 ; python_version >= "3.9" and python_full_version < "3.13" -kubernetes==26.1.0 ; python_version >= "3.9" and python_full_version < "3.13" -matplotlib==3.8.3 ; python_version >= "3.9" and python_full_version < "3.13" -numpy==1.26.4 ; python_version >= "3.9" and python_full_version < "3.13" -oauthlib==3.2.2 ; python_version >= "3.9" and python_full_version < "3.13" -packaging==24.0 ; python_version >= "3.9" and python_full_version < "3.13" -pandas==2.2.2 ; python_version >= "3.9" and python_full_version < "3.13" -pillow==10.3.0 ; python_version >= "3.9" and python_full_version < "3.13" -prometheus-api-client==0.5.3 ; python_version >= "3.9" and python_full_version < "3.13" -prometrix==0.1.17 ; python_version >= "3.9" and python_full_version < "3.13" -pyasn1-modules==0.3.0 ; python_version >= "3.9" and python_full_version < "3.13" -pyasn1==0.5.1 ; python_version >= "3.9" and python_full_version < "3.13" -pydantic==1.10.15 ; python_version >= "3.9" and python_full_version < "3.13" -pygments==2.17.2 ; python_version >= "3.9" and python_full_version < "3.13" -pyparsing==3.1.2 ; python_version >= "3.9" and python_full_version < "3.13" -python-dateutil==2.9.0.post0 ; python_version >= "3.9" and python_full_version < "3.13" -pytz==2024.1 ; python_version >= "3.9" and python_full_version < "3.13" -pyyaml==6.0.1 ; python_version >= "3.9" and python_full_version < "3.13" -regex==2023.12.25 ; python_version >= "3.9" and python_full_version < "3.13" -requests-oauthlib==1.4.0 ; python_version >= "3.9" and python_full_version < "3.13" -requests==2.32.0 ; python_version >= "3.9" and python_full_version < "3.13" -rich==12.6.0 ; python_version >= "3.9" and python_full_version < "3.13" -rsa==4.9 ; python_version >= "3.9" and python_full_version < "3.13" -s3transfer==0.10.0 ; python_version >= "3.9" and python_full_version < "3.13" -setuptools==69.2.0 ; python_version >= "3.9" and python_full_version < "3.13" -shellingham==1.5.4 ; python_version >= "3.9" and python_full_version < "3.13" -six==1.16.0 ; python_version >= "3.9" and python_full_version < "3.13" -slack-sdk==3.27.1 ; python_version >= "3.9" and python_full_version < "3.13" -typer[all]==0.7.0 ; python_version >= "3.9" and python_full_version < "3.13" -typing-extensions==4.6.0 ; python_version >= "3.9" and python_full_version < "3.13" -tzdata==2024.1 ; python_version >= "3.9" and python_full_version < "3.13" -tzlocal==5.2 ; python_version >= "3.9" and python_full_version < "3.13" -urllib3==1.26.18 ; python_version >= "3.9" and python_full_version < "3.13" -websocket-client==1.7.0 ; python_version >= "3.9" and python_full_version < "3.13" -zipp==3.18.0 ; python_version >= "3.9" and python_version < "3.10" +about-time==4.2.1 +alive-progress==3.1.2 +boto3==1.28.21 +botocore==1.31.21 +cachetools==5.3.0 +certifi==2024.2.2 +charset-normalizer==3.0.1 +click==8.1.3 +colorama==0.4.6 +commonmark==0.9.1 +contourpy==1.0.7 +cycler==0.11.0 +dateparser==1.1.7 +fonttools==4.43.0 +google-auth==2.16.2 +grapheme==0.6.0 +httmock==1.4.0 +idna==3.4 +importlib-resources==5.12.0 +jmespath==1.0.1 +kiwisolver==1.4.4 +kubernetes==29.0.0 +matplotlib==3.7.1 +numpy==1.24.2 +oauthlib==3.2.2 +packaging==23.0 +pandas==1.5.3 +pillow==10.3.0 +pip==23.0.1 +prometheus-api-client==0.5.3 +prometrix==0.1.17 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +pydantic==1.10.15 +Pygments==2.17.2 +pyparsing==3.0.9 +python-dateutil==2.8.2 +pytz==2022.7.1 +pytz-deprecation-shim==0.1.0.post0 +PyYAML==6.0 +regex==2022.10.31 +requests==2.31.0 +requests-oauthlib==1.3.1 +rich==12.6.0 +rsa==4.9 +s3transfer==0.6.1 +setuptools==67.4.0 +shellingham==1.5.0.post1 +six==1.16.0 +slack-sdk==3.21.3 +typer==0.7.0 +typing_extensions==4.5.0 +tzdata==2022.7 +tzlocal==4.2 +urllib3==1.26.18 +websocket-client==1.5.1 +wheel==0.43.0 +zipp==3.15.0 \ No newline at end of file diff --git a/robusta_krr/core/integrations/kubernetes/__init__.py b/robusta_krr/core/integrations/kubernetes/__init__.py index a772a5c2..c968d742 100644 --- a/robusta_krr/core/integrations/kubernetes/__init__.py +++ b/robusta_krr/core/integrations/kubernetes/__init__.py @@ -26,6 +26,8 @@ logger = logging.getLogger("krr") +COREKINDS = ["Deployment", "DaemonSet", "StatefulSet", "Job", "CronJob", "ReplicaSet"] + AnyKubernetesAPIObject = Union[V1Deployment, V1DaemonSet, V1StatefulSet, V1Pod, V1Job] HPAKey = tuple[str, str, str] @@ -68,6 +70,7 @@ async def list_scannable_objects(self) -> list[K8sObjectData]: self._list_all_daemon_set(), self._list_all_jobs(), self._list_all_cronjobs(), + self._list_standalone_pods(), ) return [ @@ -239,7 +242,9 @@ async def _list_scannable_objects( result = [] try: for item in await self._list_namespaced_or_global_objects(kind, all_namespaces_request, namespaced_request): + logger.debug(f"Processing {kind} {item.metadata.name}") if filter_workflows is not None and not filter_workflows(item): + logger.debug(f"filter_workflows {filter_workflows(item)} for {kind} {item.metadata.name}") continue containers = extract_containers(item) @@ -364,7 +369,22 @@ def _list_all_jobs(self) -> list[K8sObjectData]: owner.kind == "CronJob" for owner in item.metadata.owner_references or [] ), ) + + def _list_standalone_pods(self) -> list[K8sObjectData]: + logger.debug("Listing standalone pods") + return self._list_scannable_objects( + kind="Pod", + all_namespaces_request=self.core.list_pod_for_all_namespaces, + namespaced_request=self.core.list_namespaced_pod, + extract_containers=lambda item: item.spec.containers, + filter_workflows=lambda item: any( + owner.kind == "Pod" + or owner.kind not in COREKINDS + for owner in item.metadata.owner_references or [] + ) + ) + def _list_all_cronjobs(self) -> list[K8sObjectData]: return self._list_scannable_objects( kind="CronJob", diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 440611eb..8b0d2967 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -216,6 +216,9 @@ async def load_pods(self, object: K8sObjectData, period: timedelta) -> list[PodD logger.debug(f"Adding historic pods for {object}") + if object.kind == 'Pod': + return [PodData(name=object.name, deleted=False)] + days_literal = min(int(period.total_seconds()) // 60 // 24, 32) period_literal = f"{days_literal}d" pod_owners: Iterable[str] diff --git a/robusta_krr/core/models/objects.py b/robusta_krr/core/models/objects.py index e4b400d9..2ef28978 100644 --- a/robusta_krr/core/models/objects.py +++ b/robusta_krr/core/models/objects.py @@ -8,8 +8,7 @@ from robusta_krr.utils.batched import batched from kubernetes.client.models import V1LabelSelector -KindLiteral = Literal["Deployment", "DaemonSet", "StatefulSet", "Job", "CronJob", "Rollout", "DeploymentConfig"] - +KindLiteral = Literal["Pod", "Deployment", "DaemonSet", "StatefulSet", "Job", "CronJob", "Rollout", "DeploymentConfig"] class PodData(pd.BaseModel): name: str