Skip to content

Commit ee46820

Browse files
committed
add probes and support newer Python versions
Signed-off-by: Sylvain Hellegouarch <[email protected]>
1 parent 1d0672b commit ee46820

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-22.04
2828
strategy:
2929
matrix:
30-
python-version: [3.7, 3.8, 3.9, "3.10"]
30+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
3131
steps:
3232
- uses: actions/checkout@v3
3333
- name: Set up Python ${{ matrix.python-version }}

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
## [Unreleased][]
44

5-
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.32.1...HEAD
5+
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.33.0...HEAD
6+
7+
## [0.33.0][] - 2023-10-29
8+
9+
[0.33.0]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.32.1...0.33.0
10+
11+
### Added
12+
13+
* Probes to retrieve and verify node statuses
14+
* Advertize support for Python 3.11 and Python 3.12
615

716
## [0.32.1][] - 2023-10-28
817

chaosk8s/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from logzero import logger
1313

1414
__all__ = ["create_k8s_api_client", "discover", "__version__"]
15-
__version__ = "0.32.1"
15+
__version__ = "0.33.0"
1616

1717

1818
def get_config_path() -> str:

chaosk8s/node/probes.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import json
2+
from typing import Dict, List
23

34
from chaoslib.types import Configuration, Secrets
45
from kubernetes import client
6+
from logzero import logger
57

68
from chaosk8s import create_k8s_api_client
79

8-
__all__ = ["get_nodes"]
10+
__all__ = [
11+
"get_nodes",
12+
"all_nodes_must_be_ready_to_schedule",
13+
"get_all_node_status_conditions",
14+
]
915

1016

1117
def get_nodes(
@@ -26,3 +32,43 @@ def get_nodes(
2632
ret = v1.list_node(_preload_content=False)
2733

2834
return json.loads(ret.read().decode("utf-8"))
35+
36+
37+
def get_all_node_status_conditions(
38+
configuration: Configuration = None, secrets: Secrets = None
39+
) -> List[Dict[str, str]]:
40+
"""
41+
Get all nodes conditions.
42+
"""
43+
api = create_k8s_api_client(secrets)
44+
45+
v1 = client.CoreV1Api(api)
46+
nodes = v1.list_node()
47+
48+
result = []
49+
50+
for node in nodes.items:
51+
n = {"name": node.metadata.name}
52+
for cond in node.status.conditions:
53+
n[cond.type] = cond.status
54+
result.append(n)
55+
56+
logger.debug(f"Nodes statuses: {result}")
57+
58+
return result
59+
60+
61+
def all_nodes_must_be_ready_to_schedule(
62+
configuration: Configuration = None, secrets: Secrets = None
63+
) -> bool:
64+
"""
65+
Verifies that all nodes in the cluster are in `Ready` condition and can
66+
be scheduled.
67+
"""
68+
result = get_all_node_status_conditions(configuration, secrets)
69+
70+
for statuses in result:
71+
if statuses.get("Ready") != "True":
72+
return False
73+
74+
return True

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def get_version_from_package() -> str:
3838
'Programming Language :: Python :: 3.8',
3939
'Programming Language :: Python :: 3.9',
4040
'Programming Language :: Python :: 3.10',
41+
'Programming Language :: Python :: 3.11',
42+
'Programming Language :: Python :: 3.12',
4143
'Programming Language :: Python :: Implementation',
4244
'Programming Language :: Python :: Implementation :: CPython'
4345
]

0 commit comments

Comments
 (0)