Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devel/debug_logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ To enable debug logging in the Kubernetes Python client, follow these steps:
api_client = client.ApiClient(configuration=c)

# Use the API client with debug logging enabled
apps_v1 = client.AppsV1Api(api_client=api_client)
apps_v1 = client.AppsV1Api(api_client=api_client)
2 changes: 1 addition & 1 deletion examples/enable_debug_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def main():


if __name__ == "__main__":
main()
main()
5 changes: 5 additions & 0 deletions kubernetes/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,8 @@
from kubernetes.client.models.v2_resource_metric_status import V2ResourceMetricStatus
from kubernetes.client.models.version_info import VersionInfo

try:
import kubernetes.client.helpers.patch as _patch
_patch.apply_patch()
except ImportError:
pass
21 changes: 21 additions & 0 deletions kubernetes/client/helpers/patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from kubernetes import client
from kubernetes.client.models import V1PodList

def apply_patch():
"""Monkeypatch ApiClient.deserialize safely."""
if getattr(client.ApiClient, "_is_patched_for_terminating", False):
return # already patched

original_deserialize = client.ApiClient.deserialize

def _patched_deserialize(self, response, response_type):
result = original_deserialize(self, response, response_type)
if response_type == "V1PodList" and isinstance(result, V1PodList):
for pod in result.items:
if pod.metadata and pod.metadata.deletion_timestamp:
if pod.status and pod.status.phase == "Running":
pod.status.phase = "Terminating"
return result

client.ApiClient.deserialize = _patched_deserialize
client.ApiClient._is_patched_for_terminating = True
28 changes: 28 additions & 0 deletions scripts/insert_patch_import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# add_patch_import.sh - Ensure monkey-patch loader is added to client/__init__.py

CLIENT_INIT="../kubernetes/client/__init__.py"

# Normalize Windows-style backslashes to Unix-style forward slashes
CLIENT_INIT="$(echo "$CLIENT_INIT" | sed 's|\\|/|g')"

# Ensure file exists
if [ ! -f "$CLIENT_INIT" ]; then
echo "Error: $CLIENT_INIT does not exist." >&2
exit 1
fi

PATCH_SNIPPET='try:
import kubernetes.client.helpers.patch as _patch
_patch.apply_patch()
except ImportError:
pass'

# Check if snippet already exists
if grep -q "your_project.k8s_helpers.patch" "$CLIENT_INIT"; then
echo "Patch snippet already present in $CLIENT_INIT, skipping."
else
echo "" >> "$CLIENT_INIT"
echo "$PATCH_SNIPPET" >> "$CLIENT_INIT"
echo "Patch snippet added to $CLIENT_INIT."
fi
3 changes: 2 additions & 1 deletion scripts/insert_proxy_config.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# insert_proxy_config.sh - run this after openapi-generator release.sh
CONFIG_PATH="../python_kubernetes/kubernetes/client"
CONFIG_PATH="../kubernetes/client"
# there is path error here, so we need to fix it related to #2390

# Compute the full file path
CONFIG_FILE="$CONFIG_PATH/configuration.py"
Expand Down
3 changes: 3 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ git diff-index --quiet --cached HEAD || git commit -am "update changelog"
scripts/update-client.sh
#edit comfiguration.py files
scripts/insert_proxy_config.sh
#insert patch import
scripts/insert_patch_import.sh
# Apply hotfixes

rm -r kubernetes/test/
git add .
git commit -m "temporary generated commit"
Expand Down