Skip to content

Commit

Permalink
add probes and support newer Python versions
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
  • Loading branch information
Lawouach committed Oct 29, 2023
1 parent 1d0672b commit ee46820
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## [Unreleased][]

[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.32.1...HEAD
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.33.0...HEAD

## [0.33.0][] - 2023-10-29

[0.33.0]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.32.1...0.33.0

### Added

* Probes to retrieve and verify node statuses
* Advertize support for Python 3.11 and Python 3.12

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

Expand Down
2 changes: 1 addition & 1 deletion chaosk8s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from logzero import logger

__all__ = ["create_k8s_api_client", "discover", "__version__"]
__version__ = "0.32.1"
__version__ = "0.33.0"


def get_config_path() -> str:
Expand Down
48 changes: 47 additions & 1 deletion chaosk8s/node/probes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import json
from typing import Dict, List

from chaoslib.types import Configuration, Secrets
from kubernetes import client
from logzero import logger

from chaosk8s import create_k8s_api_client

__all__ = ["get_nodes"]
__all__ = [
"get_nodes",
"all_nodes_must_be_ready_to_schedule",
"get_all_node_status_conditions",
]


def get_nodes(
Expand All @@ -26,3 +32,43 @@ def get_nodes(
ret = v1.list_node(_preload_content=False)

return json.loads(ret.read().decode("utf-8"))


def get_all_node_status_conditions(
configuration: Configuration = None, secrets: Secrets = None
) -> List[Dict[str, str]]:
"""
Get all nodes conditions.
"""
api = create_k8s_api_client(secrets)

v1 = client.CoreV1Api(api)
nodes = v1.list_node()

result = []

for node in nodes.items:
n = {"name": node.metadata.name}
for cond in node.status.conditions:
n[cond.type] = cond.status
result.append(n)

logger.debug(f"Nodes statuses: {result}")

return result


def all_nodes_must_be_ready_to_schedule(
configuration: Configuration = None, secrets: Secrets = None
) -> bool:
"""
Verifies that all nodes in the cluster are in `Ready` condition and can
be scheduled.
"""
result = get_all_node_status_conditions(configuration, secrets)

for statuses in result:
if statuses.get("Ready") != "True":
return False

return True
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def get_version_from_package() -> str:
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython'
]
Expand Down

0 comments on commit ee46820

Please sign in to comment.