1
+ import json
1
2
import logging
2
3
import kopf
3
4
import paramiko
9
10
import random
10
11
import tempfile
11
12
import re
12
- import ast
13
13
from kubernetes import client , config
14
14
from kubernetes .stream import stream
15
15
from config import operator_config
@@ -2125,7 +2125,13 @@ def backup_postgresql_to_s3(
2125
2125
"backup_postgresql_to_s3 get backup info failed." )
2126
2126
logger .warning (
2127
2127
f"backup_postgresql_to_s3 get backup verbose info = { output } " )
2128
- backup_info = ast .literal_eval (output )
2128
+
2129
+ # process backup status
2130
+ backup_info = {BARMAN_BACKUP_LISTS : "" }
2131
+ try :
2132
+ backup_info = json .loads (output )
2133
+ except json .JSONDecodeError as e :
2134
+ logger .error (f"decode backup_info with error, { e } " )
2129
2135
new_backup_status = get_backup_status_from_backup_info (backup_info )
2130
2136
2131
2137
logger .warning (f"old_backup_status = { old_backup_status } " )
@@ -2186,7 +2192,9 @@ def backup_postgresql_to_s3(
2186
2192
backup_list_status .append (new_status )
2187
2193
2188
2194
# set backup status
2189
- set_cluster_status (meta , CLUSTER_STATUS_BACKUP , backup_list_status , logger )
2195
+ if len (backup_list_status ) > 0 :
2196
+ set_cluster_status (meta , CLUSTER_STATUS_BACKUP , backup_list_status ,
2197
+ logger )
2190
2198
2191
2199
# free conns
2192
2200
conns .free_conns ()
@@ -2496,8 +2504,12 @@ def pod_exec_command(name: str,
2496
2504
container = PODSPEC_CONTAINERS_POSTGRESQL_CONTAINER ,
2497
2505
stdin = False ,
2498
2506
stdout = True ,
2499
- tty = False )
2500
- return resp .replace ('\n ' , '' )
2507
+ tty = False ,
2508
+ _preload_content = False )
2509
+ # in order to keep json format.
2510
+ # more information please visit https://github.com/kubernetes-client/python/issues/811#issuecomment-663458763
2511
+ resp .run_forever ()
2512
+ return resp .read_stdout ().replace ('\n ' , '' )
2501
2513
except Exception as e :
2502
2514
if interrupt :
2503
2515
raise kopf .PermanentError (
@@ -2506,8 +2518,6 @@ def pod_exec_command(name: str,
2506
2518
logger .error (f"pod { name } exec command({ cmd } ) failed { e } " )
2507
2519
return FAILED
2508
2520
2509
- return resp .replace ('\n ' , '' )
2510
-
2511
2521
2512
2522
def docker_exec_command (role : str ,
2513
2523
ssh : paramiko .SSHClient ,
0 commit comments