Skip to content

Commit c51d0f7

Browse files
Add troubleshooting script (#615)
Signed-off-by: Kevin M Granger <kgranger@redhat.com> Signed-off-by: Kevin M Granger <kgranger@redhat.com>
1 parent e5735f1 commit c51d0f7

3 files changed

Lines changed: 388 additions & 2 deletions

File tree

exporters/pelorus/utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
import logging
2727
import os
2828
import sys
29-
from typing import Any, Optional, Union, overload
29+
from typing import Any, Generator, Optional, Union, cast, overload
3030

3131
import requests
3232
import requests.auth
3333
from kubernetes import client, config
34+
from kubernetes.dynamic import Resource, ResourceInstance
3435
from openshift.dynamic import DynamicClient
3536

3637
import pelorus
@@ -284,3 +285,25 @@ def __call__(self, r: requests.PreparedRequest):
284285

285286
def join_url_path_components(*components: str) -> str:
286287
return "/".join(c.strip("/") for c in components)
288+
289+
290+
def paginate_resource(
291+
resource: Resource,
292+
query: dict[str, str],
293+
# completely arbitrary. Could experiment.
294+
limit: int = 50,
295+
) -> Generator[ResourceInstance, None, None]:
296+
"""
297+
Paginate requests for openshift resources.
298+
"""
299+
client = cast(DynamicClient, resource.client)
300+
301+
list_ = client.get(resource, **query, limit=limit)
302+
303+
yield from list_.items
304+
305+
continue_token = list_.metadata.get("continue")
306+
307+
while continue_token:
308+
list_ = client.get(resource, **query, limit=limit, _continue=continue_token)
309+
yield from list_.items

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ markers = [
1212
log_cli = true
1313

1414
[tool.pylama]
15-
paths = "exporters"
15+
paths = "exporters scripts"
1616
skip = "exporters/.eggs/*"
1717

1818
[tool.pylama.linter.pycodestyle]

0 commit comments

Comments
 (0)