4242from crate .operator .config import config
4343from crate .operator .constants import (
4444 API_GROUP ,
45+ GC_USERNAME ,
4546 RESOURCE_CRATEDB ,
4647 SYSTEM_USERNAME ,
4748 BackupStorageProvider ,
6667from crate .operator .utils .kopf import StateBasedSubHandler , subhandler_partial
6768from crate .operator .utils .kubeapi import (
6869 get_cratedb_resource ,
70+ get_gc_user_password ,
6971 get_host ,
7072 get_system_user_password ,
7173 resolve_secret_key_ref ,
@@ -765,7 +767,7 @@ async def _start_restore_snapshot(
765767 raise kopf .PermanentError ("Snapshot could not be restored" )
766768
767769
768- class RestoreSystemUserPasswordSubHandler (StateBasedSubHandler ):
770+ class RestoreInternalUsersPasswordSubHandler (StateBasedSubHandler ):
769771 @crate .on .error (error_handler = crate .send_update_failed_notification )
770772 async def handle ( # type: ignore
771773 self ,
@@ -775,9 +777,9 @@ async def handle( # type: ignore
775777 ** kwargs : Any ,
776778 ):
777779 """
778- Restore the system user password from the secret in the namespace.
779- Use crash here because during a restore the system user password was
780- probably set to a different value.
780+ Restore the system user and grand-central user passwords from the secret
781+ in the namespace. Use crash here because during a restore the system user
782+ password was probably set to a different value.
781783
782784 :param namespace: The Kubernetes namespace of the CrateDB cluster.
783785 :param name: The CrateDB custom resource name defining the CrateDB cluster.
@@ -786,7 +788,6 @@ async def handle( # type: ignore
786788 async with GlobalApiClient () as api_client :
787789 core = CoreV1Api (api_client )
788790 password = await get_system_user_password (core , namespace , name )
789- password_quoted = QuotedString (password ).getquoted ().decode ()
790791
791792 cratedb = await get_cratedb_resource (namespace , name )
792793 pod_name = get_crash_pod_name (cratedb , name )
@@ -798,17 +799,53 @@ async def handle( # type: ignore
798799 # system user password.
799800
800801 # Reset the system user with the password from the CRD
801- command = (
802- f'ALTER USER " { SYSTEM_USERNAME } " SET (password= { password_quoted } );'
802+ await self . _reset_user_password (
803+ SYSTEM_USERNAME , password , namespace , pod_name , scheme , logger
803804 )
804- result = await run_crash_command (
805- namespace , pod_name , scheme , command , logger
805+
806+ await self ._restore_gc_admin_password (
807+ core , namespace , name , pod_name , scheme , logger
808+ )
809+
810+ async def _restore_gc_admin_password (
811+ self ,
812+ core : CoreV1Api ,
813+ namespace : str ,
814+ name : str ,
815+ pod_name : str ,
816+ scheme : str ,
817+ logger : logging .Logger ,
818+ ):
819+ try :
820+ gc_admin_password = await get_gc_user_password (core , namespace , name )
821+ await self ._reset_user_password (
822+ GC_USERNAME , gc_admin_password , namespace , pod_name , scheme , logger
806823 )
807- if "ALTER OK" in result :
808- logger .info ("... success" )
809- else :
810- logger .info ("... error. %s" , result )
811- raise kopf .TemporaryError (delay = config .BOOTSTRAP_RETRY_DELAY )
824+ except kopf .TemporaryError as e :
825+ logger .warning ("GC admin password reset failed; will retry: %s" , e )
826+ raise
827+ except Exception as e :
828+ logger .info (
829+ "GC admin secret not found or retrieval failed; skipping: %s" , e
830+ )
831+
832+ @staticmethod
833+ async def _reset_user_password (
834+ username : str ,
835+ password : str ,
836+ namespace : str ,
837+ pod_name : str ,
838+ scheme : str ,
839+ logger : logging .Logger ,
840+ ):
841+ password_quoted = QuotedString (password ).getquoted ().decode ()
842+ command = f'ALTER USER "{ username } " SET (password={ password_quoted } );'
843+ result = await run_crash_command (namespace , pod_name , scheme , command , logger )
844+ if "ALTER OK" in result :
845+ logger .info ("... %s password reset success" , username )
846+ else :
847+ logger .info ("... %s password reset error. %s" , username , result )
848+ raise kopf .TemporaryError (delay = config .BOOTSTRAP_RETRY_DELAY )
812849
813850
814851async def update_cratedb_admin_username_in_cratedb (
0 commit comments