Skip to content

Commit

Permalink
Add support for disabling the operator
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Henrique Neppel <[email protected]>
  • Loading branch information
marceloneppel committed Mar 23, 2024
1 parent 3b3e0f2 commit ddf5e67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import platform
import subprocess
import sys
from pathlib import Path
from typing import Dict, List, Literal, Optional, Set, get_args

import psycopg2
Expand Down Expand Up @@ -106,6 +108,16 @@ class PostgresqlOperatorCharm(TypedCharmBase[CharmConfig]):
def __init__(self, *args):
super().__init__(*args)

# Support for disabling the operator.
disable_file = Path(f"{os.environ.get('CHARM_DIR')}/disable")
if disable_file.exists():
logger.warning(
f"\n\tDisable file `{disable_file.resolve()}` found, the charm will skip all events."
"\n\tTo resume normal operations, please remove the file."
)
self.unit.status = BlockedStatus("Disabled")
sys.exit(0)

self.peer_relation_app = DataPeer(
self,
relation_name=PEER,
Expand Down

0 comments on commit ddf5e67

Please sign in to comment.