@@ -40,6 +40,7 @@ type SQLInterface interface {
4040 DisableSuperReadOnly (ctx context.Context ) (func (), error )
4141 ChangeMasterTo (ctx context.Context , host string , user string , pass string ) error
4242 MarkConfigurationDone (ctx context.Context ) error
43+ IsConfigured (ctx context.Context ) (bool , error )
4344 SetPurgedGTID (ctx context.Context ) error
4445 Host () string
4546}
@@ -125,14 +126,13 @@ func (r *nodeSQLRunner) ChangeMasterTo(ctx context.Context, masterHost, user, pa
125126
126127// MarkConfigurationDone write in a MEMORY table value. The readiness probe checks for that value to exist to succeed.
127128func (r * nodeSQLRunner ) MarkConfigurationDone (ctx context.Context ) error {
128- // nolint: gosec
129- query := fmt .Sprintf ("REPLACE INTO %s.%s VALUES ('%s', '1');" ,
130- constants .OperatorDbName , constants .OperatorStatusTableName , "configured" )
129+ return r .writeStatusValue (ctx , "configured" , "1" )
130+ }
131131
132- if err := r . runQuery ( ctx , query ); err != nil {
133- return fmt . Errorf ( "failed to mark configuration done, err: %s" , err )
134- }
135- return nil
132+ // IsConfigured returns true if MySQL was configured, a key was set in the status table
133+ func ( r * nodeSQLRunner ) IsConfigured ( ctx context. Context ) ( bool , error ) {
134+ val , err := r . readStatusValue ( ctx , "configured" )
135+ return val == "1" , err
136136}
137137
138138func (r * nodeSQLRunner ) Host () string {
@@ -239,6 +239,7 @@ func (r *nodeSQLRunner) SetPurgedGTID(ctx context.Context) error {
239239 return nil
240240}
241241
242+ // readStatusValue read from status table the value under the given key
242243func (r * nodeSQLRunner ) readStatusValue (ctx context.Context , key string ) (string , error ) {
243244 // nolint: gosec
244245 qq := fmt .Sprintf ("SELECT value FROM %s.%s WHERE name='%s'" ,
@@ -254,6 +255,19 @@ func (r *nodeSQLRunner) readStatusValue(ctx context.Context, key string) (string
254255 return value , nil
255256}
256257
258+ // writeStatusValue updates the value at the provided key
259+ func (r * nodeSQLRunner ) writeStatusValue (ctx context.Context , key , value string ) error {
260+ // nolint: gosec
261+ query := fmt .Sprintf ("REPLACE INTO %s.%s VALUES ('%s', '%s');" ,
262+ constants .OperatorDbName , constants .OperatorStatusTableName , key , value )
263+
264+ if err := r .runQuery (ctx , query ); err != nil {
265+ return err
266+ }
267+
268+ return nil
269+ }
270+
257271// isMySQLError checks if a mysql error is of the given code.
258272// more information about mysql error codes can be found here:
259273// https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html
0 commit comments