From 57bbc0ca57c3097cd68ff54a04c4b33c57f7b09b Mon Sep 17 00:00:00 2001 From: Paulo Machado Date: Fri, 22 Mar 2024 16:44:24 -0300 Subject: [PATCH] DPE-2184 operator disable (#388) * operator pause * s/pause/disabled s/maintentance/blocked * update .gitignore --- .gitignore | 6 ++++++ lib/charms/mysql/v0/mysql.py | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 44012400f..74babdd13 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,9 @@ build # helm related .kube .config + +# Makefile +Makefile + +# local pyright settings +pyrightconfig.json diff --git a/lib/charms/mysql/v0/mysql.py b/lib/charms/mysql/v0/mysql.py index 418f540ce..562c48335 100644 --- a/lib/charms/mysql/v0/mysql.py +++ b/lib/charms/mysql/v0/mysql.py @@ -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 @@ -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" @@ -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,