Skip to content

Commit d793daf

Browse files
committed
Changes made for terminating pods
1 parent bbc5253 commit d793daf

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

kubernetes/client/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,9 @@
810810
from kubernetes.client.models.v2_resource_metric_status import V2ResourceMetricStatus
811811
from kubernetes.client.models.version_info import VersionInfo
812812

813+
814+
try:
815+
import kubernetes.client.helpers.patch as _patch
816+
_patch.apply_patch()
817+
except ImportError:
818+
pass

kubernetes/client/helpers/patch.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from kubernetes import client
2+
from kubernetes.client.models import V1PodList
3+
4+
def apply_patch():
5+
"""Monkeypatch ApiClient.deserialize safely."""
6+
if getattr(client.ApiClient, "_is_patched_for_terminating", False):
7+
return # already patched
8+
9+
original_deserialize = client.ApiClient.deserialize
10+
11+
def _patched_deserialize(self, response, response_type):
12+
result = original_deserialize(self, response, response_type)
13+
if response_type == "V1PodList" and isinstance(result, V1PodList):
14+
for pod in result.items:
15+
if pod.metadata and pod.metadata.deletion_timestamp:
16+
if pod.status and pod.status.phase == "Running":
17+
pod.status.phase = "Terminating"
18+
return result
19+
20+
client.ApiClient.deserialize = _patched_deserialize
21+
client.ApiClient._is_patched_for_terminating = True

scripts/insert_patch_import.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# add_patch_import.sh - Ensure monkey-patch loader is added to client/__init__.py
3+
4+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
5+
pushd "${SCRIPT_ROOT}" > /dev/null
6+
SCRIPT_ROOT=`pwd`
7+
popd > /dev/null
8+
CLIENT_ROOT="${SCRIPT_ROOT}/../kubernetes"
9+
CONFIG_PATH="$CLIENT_ROOT/client"
10+
CONFIG_FILE="$CONFIG_PATH/__init__.py"
11+
# Normalize Windows-style backslashes to Unix-style forward slashes
12+
CONFIG_FILE="$(echo "$CONFIG_FILE" | sed 's|\\|/|g')"
13+
14+
# Ensure file exists
15+
if [ ! -f "$CONFIG_FILE" ]; then
16+
echo "Error: $CONFIG_FILE does not exist." >&2
17+
exit 1
18+
fi
19+
20+
PATCH_SNIPPET='try:
21+
import kubernetes.client.helpers.patch as _patch
22+
_patch.apply_patch()
23+
except ImportError:
24+
pass'
25+
26+
# Check if snippet already exists
27+
if grep -q "your_project.k8s_helpers.patch" "$CONFIG_FILE"; then
28+
echo "Patch snippet already present in $CONFIG_FILE, skipping."
29+
else
30+
echo "" >> "$CONFIG_FILE"
31+
echo "$PATCH_SNIPPET" >> "$CONFIG_FILE"
32+
echo "Patch snippet added to $CONFIG_FILE."
33+
fi

scripts/release.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ git diff-index --quiet --cached HEAD || git commit -am "update changelog"
209209
scripts/update-client.sh
210210
#edit comfiguration.py files
211211
scripts/insert_proxy_config.sh
212+
#insert patch import
213+
scripts/insert_patch_import.sh
212214
# Apply hotfixes
213215
rm -r kubernetes/test/
214216
git add .

0 commit comments

Comments
 (0)