Skip to content

Commit

Permalink
[DPE-4941]: Get rid of legacy relations (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu1nness authored Jul 29, 2024
1 parent cc2a364 commit bee5e73
Show file tree
Hide file tree
Showing 19 changed files with 10 additions and 903 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ jobs:
- .
- tests/integration/sharding_tests/application
- tests/integration/relation_tests/new_relations/application-charm
- tests/integration/dummy_legacy_app
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion charm_internal_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7
8
32 changes: 3 additions & 29 deletions lib/charms/mongodb/v1/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from charms.mongodb.v1.mongodb import MongoDBConfiguration, MongoDBConnection
from ops.charm import CharmBase, EventBase, RelationBrokenEvent, RelationChangedEvent
from ops.framework import Object
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, Relation
from ops.model import Relation
from pymongo.errors import PyMongoError

from config import Config
Expand All @@ -31,12 +31,11 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 7
LIBPATCH = 8

logger = logging.getLogger(__name__)
REL_NAME = "database"

LEGACY_REL_NAME = "obsolete"
MONGOS_RELATIONS = "cluster"

# We expect the MongoDB container to use the default ports
Expand Down Expand Up @@ -96,14 +95,6 @@ def pass_hook_checks(self, event: EventBase) -> bool:
logger.info("Skipping code for relations.")
return False

# legacy relations have auth disabled, which new relations require
if self.model.get_relation(LEGACY_REL_NAME):
self.charm.status.set_and_share_status(
BlockedStatus("cannot have both legacy and new relations")
)
logger.error("Auth disabled due to existing connections to legacy relations")
return False

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

Expand All @@ -128,14 +119,6 @@ def _on_relation_event(self, event):
logger.info("Skipping %s: hook checks did not pass", type(event))
return

# If auth is disabled but there are no legacy relation users, this means that legacy
# users have left and auth can be re-enabled.
if self.substrate == "vm" and not self.charm.auth_enabled():
logger.debug("Enabling authentication.")
self.charm.status.set_and_share_status(MaintenanceStatus("re-enabling authentication"))
self.charm.restart_charm_services(auth=True)
self.charm.status.set_and_share_status(ActiveStatus())

departed_relation_id = None
if type(event) is RelationBrokenEvent:
# Only relation_deparated events can check if scaling down
Expand Down Expand Up @@ -181,15 +164,6 @@ def oversee_users(self, departed_relation_id: Optional[int], event):
relation is still on the list of all relations. Therefore, for proper
work of the function, we need to exclude departed relation from the list.
"""
# This hook gets called from other contexts within the charm so it is necessary to check
# for legacy relations which have auth disabled, which new relations require
if self.model.get_relation(LEGACY_REL_NAME):
self.charm.status.set_and_share_status(
BlockedStatus("cannot have both legacy and new relations")
)
logger.error("Auth disabled due to existing connections to legacy relations")
return

with MongoDBConnection(self.charm.mongodb_config) as mongo:
database_users = mongo.get_users()
relation_users = self._get_users_from_relations(departed_relation_id)
Expand Down Expand Up @@ -409,7 +383,7 @@ def _get_relations(self, rel=REL_NAME) -> List[Relation]:
"""
return (
self.model.relations[MONGOS_RELATIONS]
if self.charm.is_role(Config.Role.CONFIG_SERVER) and rel != LEGACY_REL_NAME
if self.charm.is_role(Config.Role.CONFIG_SERVER)
else self.model.relations[rel]
)

Expand Down
124 changes: 0 additions & 124 deletions lib/charms/mongodb/v1/mongodb_vm_legacy_provider.py

This file was deleted.

10 changes: 2 additions & 8 deletions lib/charms/mongodb/v1/shards_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OperationFailure,
PyMongoError,
)
from charms.mongodb.v1.mongodb_provider import LEGACY_REL_NAME, REL_NAME
from charms.mongodb.v1.mongodb_provider import REL_NAME
from charms.mongodb.v1.mongos import (
BalancerNotEnabledError,
MongosConnection,
Expand Down Expand Up @@ -63,7 +63,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 7
LIBPATCH = 8

KEYFILE_KEY = "key-file"
HOSTS_KEY = "host"
Expand Down Expand Up @@ -369,9 +369,6 @@ def get_config_server_status(self) -> Optional[StatusBase]:
):
return BlockedStatus("sharding interface cannot be used by replicas")

if self.model.relations[LEGACY_REL_NAME]:
return BlockedStatus(f"Sharding roles do not support {LEGACY_REL_NAME} interface.")

if self.model.relations[REL_NAME]:
return BlockedStatus(f"Sharding roles do not support {REL_NAME} interface.")

Expand Down Expand Up @@ -904,9 +901,6 @@ def get_relations_statuses(self) -> Optional[StatusBase]:
):
return BlockedStatus("sharding interface cannot be used by replicas")

if self.model.get_relation(LEGACY_REL_NAME):
return BlockedStatus(f"Sharding roles do not support {LEGACY_REL_NAME} interface.")

if self.model.get_relation(REL_NAME):
return BlockedStatus(f"Sharding roles do not support {REL_NAME} interface.")

Expand Down
3 changes: 0 additions & 3 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ series:
provides:
database:
interface: mongodb_client
obsolete:
# Legacy Relation - these will be deprecated in a future release
interface: mongodb
cos-agent:
interface: cos_agent
config-server:
Expand Down
19 changes: 1 addition & 18 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from charms.mongodb.v1.mongodb_backups import MongoDBBackups
from charms.mongodb.v1.mongodb_provider import MongoDBProvider
from charms.mongodb.v1.mongodb_tls import MongoDBTLS
from charms.mongodb.v1.mongodb_vm_legacy_provider import MongoDBLegacyProvider
from charms.mongodb.v1.mongos import MongosConfiguration
from charms.mongodb.v1.shards_interface import ConfigServerRequirer, ShardingProvider
from charms.mongodb.v1.users import (
Expand Down Expand Up @@ -139,7 +138,6 @@ def __init__(self, *args):

# handle provider side of relations
self.client_relations = MongoDBProvider(self, substrate=Config.SUBSTRATE)
self.legacy_client_relations = MongoDBLegacyProvider(self)
self.tls = MongoDBTLS(self, Config.Relations.PEERS, substrate=Config.SUBSTRATE)
self.backups = MongoDBBackups(self)

Expand Down Expand Up @@ -382,11 +380,6 @@ def _on_install(self, event: InstallEvent) -> None:
self.status.set_and_share_status(BlockedStatus("couldn't install MongoDB"))
return

# if a new unit is joining a cluster with a legacy relation it should start without auth
auth = not self.client_relations._get_users_from_relations(
None, rel=Config.Relations.OBSOLETE_RELATIONS_NAME
)

# clear the default config file - user provided config files will be added in the config
# changed hook
try:
Expand All @@ -398,7 +391,6 @@ def _on_install(self, event: InstallEvent) -> None:

# Construct the mongod startup commandline args for systemd and reload the daemon.
update_mongod_service(
auth=auth,
machine_ip=self.unit_host(self.unit),
config=self.mongodb_config,
role=self.role,
Expand Down Expand Up @@ -1367,15 +1359,11 @@ def stop_charm_services(self):
if self.is_role(Config.Role.CONFIG_SERVER):
mongodb_snap.stop(services=["mongos"])

def restart_charm_services(self, auth=None):
def restart_charm_services(self):
"""Restarts the mongod service with its associated configuration."""
if auth is None:
auth = self.auth_enabled()

try:
self.stop_charm_services()
update_mongod_service(
auth,
self.unit_host(self.unit),
config=self.mongodb_config,
role=self.role,
Expand Down Expand Up @@ -1514,11 +1502,6 @@ def _is_removing_last_replica(self) -> bool:

def get_invalid_integration_status(self) -> Optional[StatusBase]:
"""Returns a status if an invalid integration is present."""
if self.client_relations._get_users_from_relations(
None, rel="obsolete"
) and self.client_relations._get_users_from_relations(None):
return BlockedStatus("cannot have both legacy and new relations")

if not self.cluster.is_valid_mongos_integration():
return BlockedStatus(
"Relation to mongos not supported, config role must be config-server"
Expand Down
3 changes: 1 addition & 2 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ class Relations:

NAME = "database"
PEERS = "database-peers"
OBSOLETE_RELATIONS_NAME = "obsolete"
SHARDING_RELATIONS_NAME = "sharding"
CONFIG_SERVER_RELATIONS_NAME = "config-server"
CLUSTER_RELATIONS_NAME = "cluster"
APP_SCOPE = "app"
UNIT_SCOPE = "unit"
DB_RELATIONS = [OBSOLETE_RELATIONS_NAME, NAME]
DB_RELATIONS = [NAME]
Scopes = Literal[APP_SCOPE, UNIT_SCOPE]

class Role:
Expand Down
4 changes: 2 additions & 2 deletions src/machine_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@


def update_mongod_service(
auth: bool, machine_ip: str, config: MongoDBConfiguration, role: str = "replication"
machine_ip: str, config: MongoDBConfiguration, role: str = "replication"
) -> None:
"""Updates the mongod service file with the new options for starting."""
# write our arguments and write them to /etc/environment - the environment variable here is
# read in in the charmed-mongob.mongod.service file.
mongod_start_args = get_mongod_args(config, auth, role=role, snap_install=True)
mongod_start_args = get_mongod_args(config, auth=True, role=role, snap_install=True)
add_args_to_env("MONGOD_ARGS", mongod_start_args)

if role == Config.Role.CONFIG_SERVER:
Expand Down
11 changes: 0 additions & 11 deletions tests/integration/dummy_legacy_app/charmcraft.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions tests/integration/dummy_legacy_app/metadata.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tests/integration/dummy_legacy_app/requirements.txt

This file was deleted.

Loading

0 comments on commit bee5e73

Please sign in to comment.