|
24 | 24 | BYTES_1MB,
|
25 | 25 | MySQLAddInstanceToClusterError,
|
26 | 26 | MySQLCharmBase,
|
| 27 | + MySQLConfigureInstanceError, |
| 28 | + MySQLConfigureMySQLUsersError, |
27 | 29 | MySQLCreateClusterError,
|
28 | 30 | MySQLGetClusterPrimaryAddressError,
|
29 | 31 | MySQLGetMemberStateError,
|
30 | 32 | MySQLGetMySQLVersionError,
|
31 | 33 | MySQLInitializeJujuOperationsTableError,
|
32 | 34 | MySQLLockAcquisitionError,
|
33 | 35 | MySQLRebootFromCompleteOutageError,
|
| 36 | + MySQLServiceNotRunningError, |
34 | 37 | MySQLSetClusterPrimaryError,
|
35 | 38 | )
|
36 | 39 | from charms.mysql.v0.tls import MySQLTLS
|
|
73 | 76 | )
|
74 | 77 | from k8s_helpers import KubernetesHelpers
|
75 | 78 | from log_rotate_manager import LogRotateManager
|
76 |
| -from mysql_k8s_helpers import MySQL |
| 79 | +from mysql_k8s_helpers import MySQL, MySQLInitialiseMySQLDError |
77 | 80 | from relations.mysql import MySQLRelation
|
78 | 81 | from relations.mysql_provider import MySQLProvider
|
79 | 82 | from relations.mysql_root import MySQLRootRelation
|
@@ -114,7 +117,7 @@ class MySQLOperatorCharm(MySQLCharmBase, TypedCharmBase[CharmConfig]):
|
114 | 117 | # RotateMySQLLogsCharmEvents needs to be defined on the charm object for
|
115 | 118 | # the log rotate manager process (which runs juju-run/juju-exec to dispatch
|
116 | 119 | # a custom event)
|
117 |
| - on = RotateMySQLLogsCharmEvents() # pyright: ignore [reportAssignmentType] |
| 120 | + on = RotateMySQLLogsCharmEvents() # type: ignore |
118 | 121 |
|
119 | 122 | def __init__(self, *args):
|
120 | 123 | super().__init__(*args)
|
@@ -565,22 +568,34 @@ def _configure_instance(self, container) -> None:
|
565 | 568 | # Run mysqld for the first time to
|
566 | 569 | # bootstrap the data directory and users
|
567 | 570 | logger.debug("Initializing instance")
|
568 |
| - self._mysql.fix_data_dir(container) |
569 |
| - self._mysql.initialise_mysqld() |
570 |
| - |
571 |
| - # Add the pebble layer |
572 |
| - logger.debug("Adding pebble layer") |
573 |
| - container.add_layer(MYSQLD_SAFE_SERVICE, self._pebble_layer, combine=True) |
574 |
| - container.restart(MYSQLD_SAFE_SERVICE) |
575 |
| - |
576 |
| - logger.debug("Waiting for instance to be ready") |
577 |
| - self._mysql.wait_until_mysql_connection(check_port=False) |
578 |
| - |
579 |
| - logger.info("Configuring instance") |
580 |
| - # Configure all base users and revoke privileges from the root users |
581 |
| - self._mysql.configure_mysql_users(password_needed=False) |
582 |
| - # Configure instance as a cluster node |
583 |
| - self._mysql.configure_instance() |
| 571 | + try: |
| 572 | + self._mysql.fix_data_dir(container) |
| 573 | + self._mysql.initialise_mysqld() |
| 574 | + |
| 575 | + # Add the pebble layer |
| 576 | + logger.debug("Adding pebble layer") |
| 577 | + container.add_layer(MYSQLD_SAFE_SERVICE, self._pebble_layer, combine=True) |
| 578 | + container.restart(MYSQLD_SAFE_SERVICE) |
| 579 | + |
| 580 | + logger.debug("Waiting for instance to be ready") |
| 581 | + self._mysql.wait_until_mysql_connection(check_port=False) |
| 582 | + |
| 583 | + logger.info("Configuring instance") |
| 584 | + # Configure all base users and revoke privileges from the root users |
| 585 | + self._mysql.configure_mysql_users(password_needed=False) |
| 586 | + # Configure instance as a cluster node |
| 587 | + self._mysql.configure_instance() |
| 588 | + except ( |
| 589 | + MySQLInitialiseMySQLDError, |
| 590 | + MySQLServiceNotRunningError, |
| 591 | + MySQLConfigureMySQLUsersError, |
| 592 | + MySQLConfigureInstanceError, |
| 593 | + ): |
| 594 | + # On any error, reset the data directory so hook is retried |
| 595 | + # on empty data directory |
| 596 | + # https://github.com/canonical/mysql-k8s-operator/issues/447 |
| 597 | + self._mysql.reset_data_dir() |
| 598 | + raise |
584 | 599 |
|
585 | 600 | if self.has_cos_relation:
|
586 | 601 | if container.get_services(MYSQLD_EXPORTER_SERVICE)[
|
|
0 commit comments