Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add preflight check (without app status check and move primary check) #405

Open
wants to merge 5 commits into
base: 6/edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,091 changes: 0 additions & 1,091 deletions lib/charms/data_platform_libs/v0/upgrade.py

This file was deleted.

5 changes: 0 additions & 5 deletions lib/charms/mongodb/v0/config_server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ def pass_hook_checks(self, event: EventBase) -> bool:
)
return False

if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if not self.charm.unit.is_leader():
return False

Expand Down
24 changes: 0 additions & 24 deletions lib/charms/mongodb/v0/mongodb_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ def is_tls_enabled(self, internal: bool):

def _on_set_tls_private_key(self, event: ActionEvent) -> None:
"""Set the TLS private key, which will be used for requesting the certificate."""
if not self.charm.upgrade.idle:
event.fail("Cannot set TLS key - upgrade is in progress.")
return

logger.debug("Request to set TLS private key received.")
if self.charm.is_role(Config.Role.MONGOS) and not self.charm.has_config_server():
logger.error(
Expand Down Expand Up @@ -145,21 +141,11 @@ def _on_tls_relation_joined(self, event: RelationJoinedEvent) -> None:
event.defer()
return

if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

self.request_certificate(None, internal=True)
self.request_certificate(None, internal=False)

def _on_tls_relation_broken(self, event: RelationBrokenEvent) -> None:
"""Disable TLS when TLS relation broken."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

logger.debug("Disabling external and internal TLS for unit: %s", self.charm.unit.name)

for internal in [True, False]:
Expand All @@ -179,11 +165,6 @@ def _on_tls_relation_broken(self, event: RelationBrokenEvent) -> None:

def _on_certificate_available(self, event: CertificateAvailableEvent) -> None:
"""Enable TLS when TLS certificate available."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

if self.charm.is_role(Config.Role.MONGOS) and not self.charm.config_server_db:
logger.debug(
"mongos requires config-server in order to start, do not restart with TLS until integrated to config-server"
Expand Down Expand Up @@ -251,11 +232,6 @@ def waiting_for_certs(self):

def _on_certificate_expiring(self, event: CertificateExpiringEvent) -> None:
"""Request the new certificate when old certificate is expiring."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

if self.charm.is_role(Config.Role.MONGOS) and not self.charm.has_config_server():
logger.info(
"mongos is not running (not integrated to config-server) deferring renewal of certificates."
Expand Down
10 changes: 0 additions & 10 deletions lib/charms/mongodb/v1/mongodb_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ def __init__(self, charm):

def on_s3_relation_joined(self, event: RelationJoinedEvent) -> None:
"""Checks for valid integration for s3-integrations."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if not self.is_valid_s3_integration():
logger.debug(
"Shard does not support s3 relations, please relate s3-integrator to config-server only."
Expand Down Expand Up @@ -329,11 +324,6 @@ def _pass_sanity_checks(self, event, action) -> bool:

No matter what backup-action is being run, these requirements must be met.
"""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if not self.is_valid_s3_integration():
self._fail_action_with_error_log(
event,
Expand Down
5 changes: 0 additions & 5 deletions lib/charms/mongodb/v1/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ def pass_hook_checks(self, event: EventBase) -> bool:
"""Runs the pre-hooks checks for MongoDBProvider, returns True if all pass."""
# We shouldn't try to create or update users if the database is not
# initialised. We will create users as part of initialisation.
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if not self.charm.db_initialised:
return False

Expand Down
20 changes: 0 additions & 20 deletions lib/charms/mongodb/v1/shards_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ def _on_relation_joined(self, event):

def pass_hook_checks(self, event: EventBase) -> bool:
"""Runs the pre-hooks checks for ShardingProvider, returns True if all pass."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if not self.charm.db_initialised:
logger.info("Deferring %s. db is not initialised.", str(type(event)))
event.defer()
Expand Down Expand Up @@ -547,11 +542,6 @@ def _handle_changed_secrets(self, event) -> None:
Changes in secrets do not re-trigger a relation changed event, so it is necessary to listen
to secret changes events.
"""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if (
not self.charm.unit.is_leader()
or not event.secret.label
Expand Down Expand Up @@ -655,11 +645,6 @@ def sync_cluster_passwords(

def _on_relation_joined(self, event: RelationJoinedEvent):
"""Sets status and flags in relation data relevant to sharding."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

# if re-using an old shard, re-set flags.
self.charm.unit_peer_data["drained"] = json.dumps(False)
self.charm.unit.status = MaintenanceStatus("Adding shard to config-server")
Expand Down Expand Up @@ -708,11 +693,6 @@ def _on_relation_changed(self, event):

def pass_hook_checks(self, event):
"""Runs the pre-hooks checks for ConfigServerRequirer, returns True if all pass."""
if not self.charm.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return False

if not self.charm.db_initialised:
logger.info("Deferring %s. db is not initialised.", str(type(event)))
event.defer()
Expand Down
39 changes: 3 additions & 36 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
from tenacity import Retrying, before_log, retry, stop_after_attempt, wait_fixed

from config import Config, Package
from events.upgrade import MongoDBDependencyModel, MongoDBUpgrade
from exceptions import AdminUserCreationError, ApplicationHostNotFoundError
from machine_helpers import MONGO_USER, ROOT_USER_GID, update_mongod_service
from upgrades.mongodb_upgrades import MongoDBUpgrade

AUTH_FAILED_CODE = 18
UNAUTHORISED_CODE = 13
Expand Down Expand Up @@ -131,12 +131,7 @@ def __init__(self, *args):
self.legacy_client_relations = MongoDBLegacyProvider(self)
self.tls = MongoDBTLS(self, Config.Relations.PEERS, substrate=Config.SUBSTRATE)
self.backups = MongoDBBackups(self)
self.upgrade = MongoDBUpgrade(
self,
dependency_model=MongoDBDependencyModel(
**Config.DEPENDENCIES # pyright: ignore[reportGeneralTypeIssues, reportArgumentType]
),
) # TODO future PR add dependency_model
self.upgrade = MongoDBUpgrade(self)
self.config_server = ShardingProvider(self)
self.cluster = ClusterProvider(self)
self.shard = ConfigServerRequirer(self)
Expand Down Expand Up @@ -368,7 +363,7 @@ def _on_config_changed(self, event: ConfigChangedEvent) -> None:
unresponsive therefore causing a cluster failure, error the component. This prevents it
from executing other hooks with a new role.
"""
if self.upgrade.idle and self.is_role_changed():
if self.is_role_changed():
# TODO in the future (24.04) support migration of components
logger.error(
f"cluster migration currently not supported, cannot change from { self.model.config['role']} to {self.role}"
Expand Down Expand Up @@ -442,11 +437,6 @@ def _on_relation_joined(self, event: RelationJoinedEvent) -> None:
if not self.unit.is_leader():
return

if not self.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

self._on_relation_handler(event)

self._update_related_hosts(event)
Expand All @@ -457,11 +447,6 @@ def _on_relation_handler(self, event: RelationEvent) -> None:
Args:
event: The triggering relation joined/changed event.
"""
if not self.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

# changing the monitor password will lead to non-leader units receiving a relation changed
# event. We must update the monitor and pbm URI if the password changes so that COS/pbm
# can continue to work
Expand Down Expand Up @@ -505,11 +490,6 @@ def _on_relation_handler(self, event: RelationEvent) -> None:

def _on_leader_elected(self, event: LeaderElectedEvent) -> None:
"""Generates necessary keyfile and updates replica hosts."""
if not self.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

if not self.get_secret(APP_SCOPE, Config.Secrets.SECRET_KEYFILE_NAME):
self._generate_secrets()

Expand All @@ -525,11 +505,6 @@ def _on_relation_departed(self, event: RelationDepartedEvent) -> None:
if not self.unit.is_leader() or event.departing_unit == self.unit:
return

if not self.upgrade.idle:
logger.info("cannot process %s, upgrade is in progress", event)
event.defer()
return

self._update_hosts(event)

def _on_storage_detaching(self, event: StorageDetachingEvent) -> None:
Expand Down Expand Up @@ -579,10 +554,6 @@ def _on_storage_detaching(self, event: StorageDetachingEvent) -> None:
logger.error("Failed to remove %s from replica set, error=%r", self.unit.name, e)

def _on_update_status(self, event: UpdateStatusEvent):
if not self.upgrade.idle:
logger.info("Processing upgrade, wait to check status")
return

# user-made mistakes might result in other incorrect statues. Prioritise informing users of
# their mistake.
invalid_integration_status = self.get_invalid_integration_status()
Expand Down Expand Up @@ -632,10 +603,6 @@ def _on_get_password(self, event: ActionEvent) -> None:

def _on_set_password(self, event: ActionEvent) -> None:
"""Set the password for the admin user."""
if not self.upgrade.idle:
event.fail("Cannot set password, upgrade is in progress.")
return

# check conditions for setting the password and fail if necessary
if not self.pass_pre_set_password_checks(event):
return
Expand Down
9 changes: 0 additions & 9 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ class Config:
MONGOD_CONF_DIR = f"{MONGODB_SNAP_DATA_DIR}/etc/mongod"
MONGOD_CONF_FILE_PATH = f"{MONGOD_CONF_DIR}/mongod.conf"
SNAP_PACKAGES = [("charmed-mongodb", "6/edge", 118)]
DEPENDENCIES = {
"mongod_service": {
"dependencies": {},
"name": "mongod",
"upgrade_supported": "^6.0.0,<7",
"version": "6.0.6",
},
# TODO: Future PR - implement mongos deps when supporting sharding upgrades
}

# Keep these alphabetically sorted
class Actions:
Expand Down
Loading
Loading