Skip to content

Commit

Permalink
CHORE for [DPE-5095] move over code to be re-used by K8s into correct…
Browse files Browse the repository at this point in the history
… lib (#464)

## Issue
K8s charm needs to implement get_invalid_integration_status

## Solution
Add it to a lib so it can be easily re-used

---------

Co-authored-by: Neha Oudin <17551419+Gu1nness@users.noreply.github.com>
  • Loading branch information
MiaAltieri and Gu1nness committed Aug 23, 2024
1 parent 3eaf3a6 commit 7210c64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 16 additions & 2 deletions lib/charms/mongodb/v0/set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See LICENSE file for licensing details.
import json
import logging
from typing import Tuple
from typing import Optional, Tuple

from charms.mongodb.v1.mongodb import MongoConfiguration, MongoDBConnection
from ops.charm import CharmBase
Expand All @@ -22,7 +22,7 @@

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

AUTH_FAILED_CODE = 18
UNAUTHORISED_CODE = 13
Expand Down Expand Up @@ -223,6 +223,20 @@ def prioritize_statuses(self, statuses: Tuple) -> StatusBase:
# if all statuses are active report mongodb status over sharding status
return mongodb_status

def get_invalid_integration_status(self) -> Optional[StatusBase]:
"""Returns a status if an invalid integration is present."""
if not self.charm.cluster.is_valid_mongos_integration():
return BlockedStatus(
"Relation to mongos not supported, config role must be config-server"
)

if not self.charm.backups.is_valid_s3_integration():
return BlockedStatus(
"Relation to s3-integrator is not supported, config role must be config-server"
)

return self.charm.get_cluster_mismatched_revision_status()


def build_unit_status(mongodb_config: MongoConfiguration, unit_host: str) -> StatusBase:
"""Generates the status of a unit based on its status reported by mongod."""
Expand Down
16 changes: 1 addition & 15 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def _on_storage_detaching(self, event: StorageDetachingEvent) -> None:
def _on_update_status(self, event: UpdateStatusEvent):
# user-made mistakes might result in other incorrect statues. Prioritise informing users of
# their mistake.
invalid_integration_status = self.get_invalid_integration_status()
invalid_integration_status = self.status.get_invalid_integration_status()
if invalid_integration_status:
self.status.set_and_share_status(invalid_integration_status)
return
Expand Down Expand Up @@ -1495,20 +1495,6 @@ def _is_removing_last_replica(self) -> bool:
"""Returns True if the last replica (juju unit) is getting removed."""
return self.app.planned_units() == 0 and len(self.peers_units) == 0

def get_invalid_integration_status(self) -> Optional[StatusBase]:
"""Returns a status if an invalid integration is present."""
if not self.cluster.is_valid_mongos_integration():
return BlockedStatus(
"Relation to mongos not supported, config role must be config-server"
)

if not self.backups.is_valid_s3_integration():
return BlockedStatus(
"Relation to s3-integrator is not supported, config role must be config-server"
)

return self.get_cluster_mismatched_revision_status()

def is_relation_feasible(self, rel_interface) -> bool:
"""Returns true if the proposed relation is feasible."""
if self.is_sharding_component() and rel_interface in Config.Relations.DB_RELATIONS:
Expand Down

0 comments on commit 7210c64

Please sign in to comment.