@@ -714,13 +714,14 @@ def _on_webhook_mutator_pebble_ready(self, event) -> None:
714
714
generate_mutating_webhook (
715
715
client , self .unit , self .model .name , cert , self .mutator_service_name
716
716
)
717
+ client .close ()
717
718
718
719
# We must ensure that juju does not overwrite our termination period, so we should update
719
720
# it as needed. However, updating the termination period can result in an onslaught of
720
721
# events, including the upgrade event. To prevent this from messing with upgrades do not
721
722
# update the termination period when an upgrade is occurring.
722
723
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 ( )
724
725
725
726
def _configure_layers (self , container : Container ) -> None :
726
727
"""Configure the layers of the container."""
@@ -988,6 +989,7 @@ def get_current_termination_period(self) -> int:
988
989
"""Returns the current termination period for the stateful set of this juju application."""
989
990
client = Client ()
990
991
statefulset = client .get (StatefulSet , name = self .app .name , namespace = self .model .name )
992
+ client .close ()
991
993
return statefulset .spec .template .spec .terminationGracePeriodSeconds
992
994
993
995
def get_termination_period_for_pod (self ) -> int :
@@ -996,9 +998,10 @@ def get_termination_period_for_pod(self) -> int:
996
998
client = Client ()
997
999
pod = client .get (Pod , name = pod_name , namespace = self .model .name )
998
1000
termination_grace_period = pod .spec .terminationGracePeriodSeconds
1001
+ client .close ()
999
1002
return termination_grace_period
1000
1003
1001
- def update_termination_grace_period (self , seconds : int ) -> None :
1004
+ def update_termination_grace_period_to_one_year (self ) -> None :
1002
1005
"""Patch the termination grace period for the stateful set of this juju application."""
1003
1006
client = Client ()
1004
1007
patch_data = {
@@ -1018,6 +1021,7 @@ def update_termination_grace_period(self, seconds: int) -> None:
1018
1021
)
1019
1022
# Works because we're leader.
1020
1023
self .needs_new_termination_period = False
1024
+ client .close ()
1021
1025
1022
1026
def __handle_partition_on_stop (self ) -> None :
1023
1027
"""Raise partition to prevent other units from restarting if an upgrade is in progress.
@@ -1187,7 +1191,7 @@ def _handle_termination(self):
1187
1191
return
1188
1192
try :
1189
1193
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 ( )
1191
1195
except ApiError :
1192
1196
logger .info ("Failed to update termination period." )
1193
1197
return
0 commit comments