Skip to content

Commit 57bbc0c

Browse files
authored
DPE-2184 operator disable (#388)
* operator pause * s/pause/disabled s/maintentance/blocked * update .gitignore
1 parent 0a0d1e3 commit 57bbc0c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ build
138138
# helm related
139139
.kube
140140
.config
141+
142+
# Makefile
143+
Makefile
144+
145+
# local pyright settings
146+
pyrightconfig.json

lib/charms/mysql/v0/mysql.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ def wait_until_mysql_connection(self) -> None:
7171
import io
7272
import json
7373
import logging
74+
import os
7475
import re
7576
import socket
77+
import sys
7678
import time
7779
from abc import ABC, abstractmethod
80+
from pathlib import Path
7881
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, get_args
7982

8083
import ops
@@ -111,7 +114,7 @@ def wait_until_mysql_connection(self) -> None:
111114

112115
# Increment this PATCH version before using `charmcraft publish-lib` or reset
113116
# to 0 if you are raising the major API version
114-
LIBPATCH = 55
117+
LIBPATCH = 56
115118

116119
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
117120
UNIT_ADD_LOCKNAME = "unit-add"
@@ -376,6 +379,18 @@ class MySQLCharmBase(CharmBase, ABC):
376379
def __init__(self, *args):
377380
super().__init__(*args)
378381

382+
# disable support
383+
disable_file = Path(
384+
f"{os.environ.get('CHARM_DIR')}/disable"
385+
) # pyright: ignore [reportArgumentType]
386+
if disable_file.exists():
387+
logger.warning(
388+
f"\n\tDisable file `{disable_file.resolve()}` found, the charm will skip all events."
389+
"\n\tTo resume normal operations, please remove the file."
390+
)
391+
self.unit.status = ops.BlockedStatus("Disabled")
392+
sys.exit(0)
393+
379394
self.secrets = SecretCache(self)
380395
self.peer_relation_app = DataPeer(
381396
self,

0 commit comments

Comments
 (0)