Skip to content

Commit 34f1c45

Browse files
committed
fix: kubeconfig clean up
1 parent 49ce32c commit 34f1c45

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/kubectl_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ def popitem(self):
139139
"""重写 popitem 方法,在驱逐缓存项时清理 kubeconfig 文件"""
140140
key, path = super().popitem()
141141
# 删除 kubeconfig 文件
142-
if (path and os.path.exists(path) and
143-
self.do_not_cleanup_file and
144-
os.path.abspath(path) != os.path.abspath(self.do_not_cleanup_file)):
142+
if path and os.path.exists(path):
143+
if self.do_not_cleanup_file and os.path.samefile(path, self.do_not_cleanup_file):
144+
logger.debug(f"Skipped removal of protected kubeconfig file: {path}")
145+
return
145146
try:
146147
os.remove(path)
147148
logger.debug(f"Removed cached kubeconfig file: {path}")
@@ -156,7 +157,7 @@ def cleanup(self):
156157
for key, path in list(self.items()):
157158
if path and os.path.exists(path):
158159
# 只有当do_not_cleanup_file存在且路径不同时才清理
159-
if self.do_not_cleanup_file and os.path.abspath(path) == os.path.abspath(self.do_not_cleanup_file):
160+
if self.do_not_cleanup_file and os.path.samefile(path, self.do_not_cleanup_file):
160161
continue
161162
try:
162163
os.remove(path)

0 commit comments

Comments
 (0)