Skip to content

Commit d90ecd3

Browse files
Add support for disabling the operator (#412)
Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent 48e9e2f commit d90ecd3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

poetry.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/charm.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import platform
1111
import subprocess
12+
import sys
13+
from pathlib import Path
1214
from typing import Dict, List, Literal, Optional, Set, get_args
1315

1416
import psycopg2
@@ -106,6 +108,16 @@ class PostgresqlOperatorCharm(TypedCharmBase[CharmConfig]):
106108
def __init__(self, *args):
107109
super().__init__(*args)
108110

111+
# Support for disabling the operator.
112+
disable_file = Path(f"{os.environ.get('CHARM_DIR')}/disable")
113+
if disable_file.exists():
114+
logger.warning(
115+
f"\n\tDisable file `{disable_file.resolve()}` found, the charm will skip all events."
116+
"\n\tTo resume normal operations, please remove the file."
117+
)
118+
self.unit.status = BlockedStatus("Disabled")
119+
sys.exit(0)
120+
109121
self.peer_relation_app = DataPeer(
110122
self,
111123
relation_name=PEER,

0 commit comments

Comments
 (0)