Skip to content

Commit

Permalink
DPE-2184 operator disable (#388)
Browse files Browse the repository at this point in the history
* operator pause

* s/pause/disabled
s/maintentance/blocked

* update .gitignore
  • Loading branch information
paulomach authored Mar 22, 2024
1 parent 0a0d1e3 commit 57bbc0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,9 @@ build
# helm related
.kube
.config

# Makefile
Makefile

# local pyright settings
pyrightconfig.json
17 changes: 16 additions & 1 deletion lib/charms/mysql/v0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ def wait_until_mysql_connection(self) -> None:
import io
import json
import logging
import os
import re
import socket
import sys
import time
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, get_args

import ops
Expand Down Expand Up @@ -111,7 +114,7 @@ def wait_until_mysql_connection(self) -> None:

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

UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
UNIT_ADD_LOCKNAME = "unit-add"
Expand Down Expand Up @@ -376,6 +379,18 @@ class MySQLCharmBase(CharmBase, ABC):
def __init__(self, *args):
super().__init__(*args)

# disable support
disable_file = Path(
f"{os.environ.get('CHARM_DIR')}/disable"
) # pyright: ignore [reportArgumentType]
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 = ops.BlockedStatus("Disabled")
sys.exit(0)

self.secrets = SecretCache(self)
self.peer_relation_app = DataPeer(
self,
Expand Down

0 comments on commit 57bbc0c

Please sign in to comment.