2121logger = logging .getLogger (__name__ )
2222
2323
24- def get_db2u_instance_cr (custom_objects_api : client .CustomObjectsApi , mas_instance_id : str , mas_app_id : str ) -> dict :
25- cr_name = f"db2wh-{ mas_instance_id } -{ mas_app_id } "
24+ def get_db2u_instance_cr (custom_objects_api : client .CustomObjectsApi , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> dict :
25+ cr_name = { 'primary' : f"db2wh-{ mas_instance_id } -{ mas_app_id } " , 'standby' : f"db2wh- { mas_instance_id } - { mas_app_id } -sdb" }[ database_role ]
2626 namespace = f"db2u-{ mas_instance_id } "
2727 logger .debug (f"Getting Db2uInstance CR { cr_name } in { namespace } " )
2828
@@ -37,25 +37,25 @@ def get_db2u_instance_cr(custom_objects_api: client.CustomObjectsApi, mas_instan
3737 return db2u_instance_cr
3838
3939
40- def db2_pod_exec (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , command : list ) -> str :
41- pod_name = f"c-db2wh-{ mas_instance_id } -{ mas_app_id } -db2u-0"
40+ def db2_pod_exec (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , command : list , database_role = 'primary' ) -> str :
41+ pod_name = { 'primary' : f"c-db2wh-{ mas_instance_id } -{ mas_app_id } -db2u-0" , 'standby' : f"c-db2wh- { mas_instance_id } - { mas_app_id } -sdb-db2u-0" }[ database_role ]
4242 namespace = f"db2u-{ mas_instance_id } "
4343 return execInPod (core_v1_api , pod_name , namespace , command )
4444
4545
46- def db2_pod_exec_db2_get_db_cfg (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , db_name : str ) -> str :
46+ def db2_pod_exec_db2_get_db_cfg (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , db_name : str , database_role = 'primary' ) -> str :
4747 command = ["su" , "-lc" , f"db2 get db cfg for { db_name } " , "db2inst1" ]
48- return db2_pod_exec (core_v1_api , mas_instance_id , mas_app_id , command )
48+ return db2_pod_exec (core_v1_api , mas_instance_id , mas_app_id , command , database_role )
4949
5050
51- def db2_pod_exec_db2_get_dbm_cfg (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str ) -> str :
51+ def db2_pod_exec_db2_get_dbm_cfg (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> str :
5252 command = ["su" , "-lc" , "db2 get dbm cfg" , "db2inst1" ]
53- return db2_pod_exec (core_v1_api , mas_instance_id , mas_app_id , command )
53+ return db2_pod_exec (core_v1_api , mas_instance_id , mas_app_id , command , database_role )
5454
5555
56- def db2_pod_exec_db2set (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str ) -> str :
56+ def db2_pod_exec_db2set (core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> str :
5757 command = ["su" , "-lc" , "db2set" , "db2inst1" ]
58- return db2_pod_exec (core_v1_api , mas_instance_id , mas_app_id , command )
58+ return db2_pod_exec (core_v1_api , mas_instance_id , mas_app_id , command , database_role )
5959
6060
6161def cr_pod_v_matches (cr_k : str , cr_v : str , pod_v : str ) -> bool :
@@ -79,7 +79,7 @@ def cr_pod_v_matches(cr_k: str, cr_v: str, pod_v: str) -> bool:
7979 return pod_v == cr_v
8080
8181
82- def check_db_cfgs (db2u_instance_cr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str ) -> list :
82+ def check_db_cfgs (db2u_instance_cr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> list :
8383 """
8484 Runs check_db_cfg for each database in the provided Db2uInstance CR
8585
@@ -100,12 +100,12 @@ def check_db_cfgs(db2u_instance_cr: dict, core_v1_api: client.CoreV1Api, mas_ins
100100
101101 # Check each db cfg
102102 for cr_db in db2u_instance_cr_databases :
103- failures = [* failures , * check_db_cfg (cr_db , core_v1_api , mas_instance_id , mas_app_id )]
103+ failures = [* failures , * check_db_cfg (cr_db , core_v1_api , mas_instance_id , mas_app_id , database_role )]
104104
105105 return failures
106106
107107
108- def check_db_cfg (db_dr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str ) -> list :
108+ def check_db_cfg (db_dr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> list :
109109 """
110110 Check that the parameters in the provided db dict taken from the Db2uInstance CR align with those in the output of the
111111 db2 get db cfg command (i.e. the configuration that is actually active in DB2).
@@ -123,7 +123,7 @@ def check_db_cfg(db_dr: dict, core_v1_api: client.CoreV1Api, mas_instance_id: st
123123 failures = []
124124
125125 db_name = db_dr ["name" ]
126- db_cfg_pod = db2_pod_exec_db2_get_db_cfg (core_v1_api , mas_instance_id , mas_app_id , db_name )
126+ db_cfg_pod = db2_pod_exec_db2_get_db_cfg (core_v1_api , mas_instance_id , mas_app_id , db_name , database_role )
127127
128128 logger .info (f"Checking db cfg for { db_name } \n { H1_BREAK } " )
129129
@@ -154,7 +154,7 @@ def check_db_cfg(db_dr: dict, core_v1_api: client.CoreV1Api, mas_instance_id: st
154154 return failures
155155
156156
157- def check_dbm_cfg (db2u_instance_cr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str ) -> list :
157+ def check_dbm_cfg (db2u_instance_cr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> list :
158158 """
159159 Check that the database manager (dbmConfig) parameters from the Db2uInstance CR align with those in the output of the
160160 db2 get dbm cfg command (i.e. the configuration that is actually active in DB2).
@@ -178,7 +178,7 @@ def check_dbm_cfg(db2u_instance_cr: dict, core_v1_api: client.CoreV1Api, mas_ins
178178 logger .info ("spec.environment.instance.dbmConfig not found or empty, skipping dbm cfg checks\n " )
179179 return []
180180
181- dbm_cfg_pod = db2_pod_exec_db2_get_dbm_cfg (core_v1_api , mas_instance_id , mas_app_id )
181+ dbm_cfg_pod = db2_pod_exec_db2_get_dbm_cfg (core_v1_api , mas_instance_id , mas_app_id , database_role )
182182
183183 logger .debug (f"db2 dbm cfg output:\n { H2_BREAK } { dbm_cfg_pod } { H2_BREAK } " )
184184 logger .debug (f"db2 dbm cr settings:\n { H2_BREAK } \n { yaml .dump (dbm_cfg_cr , sort_keys = False , default_flow_style = False )} { H2_BREAK } " )
@@ -203,7 +203,7 @@ def check_dbm_cfg(db2u_instance_cr: dict, core_v1_api: client.CoreV1Api, mas_ins
203203 return failures
204204
205205
206- def check_reg_cfg (db2u_instance_cr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str ) -> list :
206+ def check_reg_cfg (db2u_instance_cr : dict , core_v1_api : client .CoreV1Api , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ) -> list :
207207 """
208208 Check that the registry parameters from the Db2uInstance CR align with those in the output of the
209209 db2set command (i.e. the configuration that is actually active in DB2).
@@ -228,7 +228,7 @@ def check_reg_cfg(db2u_instance_cr: dict, core_v1_api: client.CoreV1Api, mas_ins
228228 logger .info ("spec.environment.instance.registry not found or empty, skipping registry cfg checks\n " )
229229 return []
230230
231- reg_cfg_pod = db2_pod_exec_db2set (core_v1_api , mas_instance_id , mas_app_id )
231+ reg_cfg_pod = db2_pod_exec_db2set (core_v1_api , mas_instance_id , mas_app_id , database_role )
232232
233233 logger .debug (f"db2set output:\n { H2_BREAK } { reg_cfg_pod } { H2_BREAK } " )
234234 logger .debug (f"db2 cr registry settings:\n { H2_BREAK } \n { yaml .dump (reg_cfg_cr , sort_keys = False , default_flow_style = False )} { H2_BREAK } " )
@@ -254,15 +254,15 @@ def check_reg_cfg(db2u_instance_cr: dict, core_v1_api: client.CoreV1Api, mas_ins
254254 return failures
255255
256256
257- def validate_db2_config (k8s_client : client .api_client .ApiClient , mas_instance_id : str , mas_app_id : str ):
257+ def validate_db2_config (k8s_client : client .api_client .ApiClient , mas_instance_id : str , mas_app_id : str , database_role = 'primary' ):
258258
259259 core_v1_api = client .CoreV1Api (k8s_client )
260260 custom_objects_api = client .CustomObjectsApi (k8s_client )
261261
262- db2u_instance_cr = get_db2u_instance_cr (custom_objects_api , mas_instance_id , mas_app_id )
263- db_failures = check_db_cfgs (db2u_instance_cr , core_v1_api , mas_instance_id , mas_app_id )
264- dbm_failures = check_dbm_cfg (db2u_instance_cr , core_v1_api , mas_instance_id , mas_app_id )
265- reg_failures = check_reg_cfg (db2u_instance_cr , core_v1_api , mas_instance_id , mas_app_id )
262+ db2u_instance_cr = get_db2u_instance_cr (custom_objects_api , mas_instance_id , mas_app_id , database_role )
263+ db_failures = check_db_cfgs (db2u_instance_cr , core_v1_api , mas_instance_id , mas_app_id , database_role )
264+ dbm_failures = check_dbm_cfg (db2u_instance_cr , core_v1_api , mas_instance_id , mas_app_id , database_role )
265+ reg_failures = check_reg_cfg (db2u_instance_cr , core_v1_api , mas_instance_id , mas_app_id , database_role )
266266
267267 all_failures = [* db_failures , * dbm_failures , * reg_failures ]
268268
0 commit comments