Skip to content

Commit

Permalink
Merge pull request #279 from powerapi-ng/fix/k8s-monitor-signal-handler
Browse files Browse the repository at this point in the history
fix(processor/k8s): Add missing signal handler to monitor process
  • Loading branch information
gfieni authored Mar 13, 2024
2 parents 25dbbb8 + 4986935 commit 3cdcb7b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/powerapi/processor/pre/k8s/k8s_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from signal import signal, SIGTERM, SIGINT
from logging import Formatter, getLogger, StreamHandler, WARNING
from multiprocessing import Manager, Process

Expand Down Expand Up @@ -151,10 +152,21 @@ def _setup_k8s_api_client(self) -> client.CoreV1Api:
load_k8s_api_client_configuration(self.concerned_actor_state)
return client.CoreV1Api()

def _setup_signal_handlers(self):
"""
Setup signal handlers for the current Process.
"""
def stop_monitor(_, __):
self.stop_monitoring.set()

signal(SIGTERM, stop_monitor)
signal(SIGINT, stop_monitor)

def run(self):
"""
Main code executed by the Monitor
"""
self._setup_signal_handlers()
self.query_k8s()

def query_k8s(self) -> None:
Expand Down

0 comments on commit 3cdcb7b

Please sign in to comment.