Skip to content

Commit 99320ea

Browse files
committed
rename update_termination_grace_period + close all k8s clients
1 parent a31f73c commit 99320ea

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/charm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,14 @@ def _on_webhook_mutator_pebble_ready(self, event) -> None:
714714
generate_mutating_webhook(
715715
client, self.unit, self.model.name, cert, self.mutator_service_name
716716
)
717+
client.close()
717718

718719
# We must ensure that juju does not overwrite our termination period, so we should update
719720
# it as needed. However, updating the termination period can result in an onslaught of
720721
# events, including the upgrade event. To prevent this from messing with upgrades do not
721722
# update the termination period when an upgrade is occurring.
722723
if self.get_current_termination_period() != ONE_YEAR and not self.upgrade_in_progress:
723-
self.update_termination_grace_period(ONE_YEAR)
724+
self.update_termination_grace_period_to_one_year()
724725

725726
def _configure_layers(self, container: Container) -> None:
726727
"""Configure the layers of the container."""
@@ -988,6 +989,7 @@ def get_current_termination_period(self) -> int:
988989
"""Returns the current termination period for the stateful set of this juju application."""
989990
client = Client()
990991
statefulset = client.get(StatefulSet, name=self.app.name, namespace=self.model.name)
992+
client.close()
991993
return statefulset.spec.template.spec.terminationGracePeriodSeconds
992994

993995
def get_termination_period_for_pod(self) -> int:
@@ -996,9 +998,10 @@ def get_termination_period_for_pod(self) -> int:
996998
client = Client()
997999
pod = client.get(Pod, name=pod_name, namespace=self.model.name)
9981000
termination_grace_period = pod.spec.terminationGracePeriodSeconds
1001+
client.close()
9991002
return termination_grace_period
10001003

1001-
def update_termination_grace_period(self, seconds: int) -> None:
1004+
def update_termination_grace_period_to_one_year(self) -> None:
10021005
"""Patch the termination grace period for the stateful set of this juju application."""
10031006
client = Client()
10041007
patch_data = {
@@ -1018,6 +1021,7 @@ def update_termination_grace_period(self, seconds: int) -> None:
10181021
)
10191022
# Works because we're leader.
10201023
self.needs_new_termination_period = False
1024+
client.close()
10211025

10221026
def __handle_partition_on_stop(self) -> None:
10231027
"""Raise partition to prevent other units from restarting if an upgrade is in progress.
@@ -1187,7 +1191,7 @@ def _handle_termination(self):
11871191
return
11881192
try:
11891193
if self.get_current_termination_period() != ONE_YEAR and not self.upgrade_in_progress:
1190-
self.update_termination_grace_period(ONE_YEAR)
1194+
self.update_termination_grace_period_to_one_year()
11911195
except ApiError:
11921196
logger.info("Failed to update termination period.")
11931197
return

0 commit comments

Comments
 (0)