File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 810
810
from kubernetes .client .models .v2_resource_metric_status import V2ResourceMetricStatus
811
811
from kubernetes .client .models .version_info import VersionInfo
812
812
813
+
814
+ try :
815
+ import kubernetes .client .helpers .patch as _patch
816
+ _patch .apply_patch ()
817
+ except ImportError :
818
+ pass
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -209,6 +209,8 @@ git diff-index --quiet --cached HEAD || git commit -am "update changelog"
209
209
scripts/update-client.sh
210
210
# edit comfiguration.py files
211
211
scripts/insert_proxy_config.sh
212
+ # insert patch import
213
+ scripts/insert_patch_import.sh
212
214
# Apply hotfixes
213
215
rm -r kubernetes/test/
214
216
git add .
You can’t perform that action at this time.
0 commit comments