Skip to content

Commit

Permalink
Merge branch 'main' into start
Browse files Browse the repository at this point in the history
  • Loading branch information
desaintmartin authored Jul 25, 2024
2 parents 362158d + 4a84874 commit 3197818
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 46 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
fetch-depth: 0

- name: Conventional commit check
uses: cocogitto/cocogitto-action@v3.5
uses: cocogitto/cocogitto-action@v3.8
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf
uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
8 changes: 5 additions & 3 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version:
- '3.9'
- '3.10'

steps:
- uses: actions/checkout@v4
Expand All @@ -44,10 +46,10 @@ jobs:
- name: Check syntax with pyupgrade
run: |
find . -type f -regex '.*\.py$' -exec pyupgrade --py37-plus {} \;
find . -type f -regex '.*\.py$' -exec pyupgrade --py39-plus {} \;
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.8.0
uses: helm/kind-action@v1.10.0

- name: Test with pytest
run: |
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# wiremind-kubernetes


## v7.4.2 (2024-04-10)
## v7.4.5 (2024-07-25)
### Fix
- start/stop pods: Do not crash if related Deployment / Statefulset does not exist

## v7.4.4 (2024-04-22)
### Chore
- mark package as PEP 561-compliant for type hints

## v7.4.3 (2024-04-19)
### Fix
- correct class attributes typing

## v7.4.2 (2024-04-19)
### Fix
- kubernetes_helper: correct typing for `use_kubeconfig`

## v7.4.1 (2023-11-23)
### Chore
- tests: e2e: apply expecteddeploymentscales CRD from wiremind helm chart repository
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4.2
7.4.5
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 120
target-version = ['py37']
target-version = ['py39']
exclude = '''
(
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --no-emit-index-url setup.py
#
cachetools==5.2.0
# via google-auth
certifi==2023.7.22
certifi==2024.7.4
# via
# kubernetes
# requests
charset-normalizer==2.1.1
# via requests
google-auth==2.11.1
# via kubernetes
idna==3.4
idna==3.7
# via requests
kubernetes==24.2.0
# via wiremind-kubernetes (setup.py)
Expand All @@ -30,7 +30,7 @@ python-dateutil==2.8.2
# via kubernetes
pyyaml==6.0
# via kubernetes
requests==2.31.0
requests==2.32.3
# via
# kubernetes
# requests-oauthlib
Expand All @@ -43,7 +43,7 @@ six==1.16.0
# google-auth
# kubernetes
# python-dateutil
urllib3==1.26.18
urllib3==1.26.19
# via
# kubernetes
# requests
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[options]
python_requires = >= 3.7
python_requires = >= 3.9

[flake8]
max-line-length = 120
Expand All @@ -14,7 +14,7 @@ ignore = W503, E203, E231, E501, Q000
jobs = 4

[mypy]
python_version = 3.7
python_version = 3.9
ignore_missing_imports = True
check_untyped_defs = True
disallow_untyped_defs = True
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
license="LGPLv3+",
packages=find_packages("src"),
package_dir={"": "src"},
package_data={"wiremind_kubernetes": ["py.typed"]},
include_package_data=True,
zip_safe=True,
install_requires=[
Expand All @@ -54,7 +55,7 @@
"mypy": extra_require_mypy,
"test": extra_require_test,
},
python_requires=">=3.7.0",
python_requires=">=3.9.0",
keywords=["kubernetes"],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
2 changes: 2 additions & 0 deletions src/wiremind_kubernetes/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class WiremindKubernetesException(Exception):
Base wiremind-kubernetes Exception.
"""

message: str

def __init__(self, message: Optional[str] = None):
super().__init__()
if message:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ class ClientWithArguments:
Currently add dry_run support for write functions and pretty to all.
"""

client: Any
read_additional_arguments: Dict[str, Any]
additional_arguments: Dict[str, Any]

def __init__(self, client: Any, dry_run: bool = False, pretty: bool = True):
self.client = client() # like kubernetes.client.CoreV1Api
self.read_additional_arguments: Dict[str, Any] = {}
self.read_additional_arguments = {}
# Only add it when its true because we set pretty client wide,
# read_cluster_custom_object which accepts it will not have it set, but it's ok for now.
if pretty:
self.read_additional_arguments["pretty"] = pretty
# Every request, either read or write, will have those arguments added
self.additional_arguments: Dict[str, Any] = self.read_additional_arguments.copy()
self.additional_arguments = self.read_additional_arguments.copy()
if dry_run:
# Dry run, in kube API, is not true or false, but either dry_run: All or not defined.
self.additional_arguments["dry_run"] = "All"
Expand Down
52 changes: 29 additions & 23 deletions src/wiremind_kubernetes/kubernetes_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ class KubernetesHelper:
A simple helper for Kubernetes manipulation.
"""

SCALE_DOWN_MAX_WAIT_TIME = 3600
SCALE_DOWN_MAX_WAIT_TIME: int = 3600

client_corev1_api: kubernetes.client.CoreV1Api
client_appsv1_api: kubernetes.client.AppsV1Api
client_batchv1_api: kubernetes.client.BatchV1Api
client_autoscalingv1_api: kubernetes.client.AutoscalingV1Api
client_custom_objects_api: kubernetes.client.CustomObjectsApi
client_rbac_authorization_v1_api: kubernetes.client.RbacAuthorizationV1Api
client_networking_v1_api: kubernetes.client.NetworkingV1Api
client_storage_v1_api: kubernetes.client.StorageV1Api

dry_run: bool
pretty: bool

def __init__(
self,
use_kubeconfig: bool = False,
use_kubeconfig: Optional[bool] = False,
dry_run: bool = False,
pretty: bool = True,
should_load_kubernetes_config: bool = True,
Expand All @@ -52,27 +64,17 @@ def __init__(
"""
if should_load_kubernetes_config:
load_kubernetes_config(use_kubeconfig=use_kubeconfig, context=context)
self.client_corev1_api: kubernetes.client.CoreV1Api = CoreV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_appsv1_api: kubernetes.client.AppsV1Api = AppV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_batchv1_api: kubernetes.client.BatchV1Api = BatchV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_autoscalingv1_api: kubernetes.client.AutoscalingV1Api = AutoscalingV1ApiWithArguments(
dry_run=dry_run, pretty=pretty
)
self.client_custom_objects_api: kubernetes.client.CustomObjectsApi = CustomObjectsApiWithArguments(
dry_run=dry_run, pretty=pretty
)
self.client_rbac_authorization_v1_api: kubernetes.client.RbacAuthorizationV1Api = (
RbacAuthorizationV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
)
self.client_networking_v1_api: kubernetes.client.NetworkingV1Api = NetworkingV1ApiWithArguments(
dry_run=dry_run, pretty=pretty
)
self.client_storage_v1_api: kubernetes.client.StorageV1Api = StorageV1ApiWithArguments(
dry_run=dry_run, pretty=pretty
)
self.client_corev1_api = CoreV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_appsv1_api = AppV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_batchv1_api = BatchV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_autoscalingv1_api = AutoscalingV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_custom_objects_api = CustomObjectsApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_rbac_authorization_v1_api = RbacAuthorizationV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_networking_v1_api = NetworkingV1ApiWithArguments(dry_run=dry_run, pretty=pretty)
self.client_storage_v1_api = StorageV1ApiWithArguments(dry_run=dry_run, pretty=pretty)

self.dry_run: bool = dry_run
self.pretty: bool = pretty
self.dry_run = dry_run
self.pretty = pretty


def _get_namespace_from_kube() -> str:
Expand All @@ -84,9 +86,11 @@ class NamespacedKubernetesHelper(KubernetesHelper):
A simple helper for Kubernetes manipulation.
"""

namespace: str

def __init__(
self,
use_kubeconfig: bool = False,
use_kubeconfig: Optional[bool] = False,
namespace: Union[None, str] = None,
dry_run: bool = False,
should_load_kubernetes_config: bool = True,
Expand Down Expand Up @@ -265,6 +269,8 @@ class KubernetesDeploymentManager(NamespacedKubernetesHelper):
a.start_pods()
"""

release_name: str

def __init__(self, release_name: str, **kwargs: Any):
self.release_name = release_name
super().__init__(**kwargs)
Expand Down
Empty file.
Empty file modified src/wiremind_kubernetes/utils.py
100755 → 100644
Empty file.

0 comments on commit 3197818

Please sign in to comment.