Skip to content

Commit

Permalink
set lock for hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
okozachenko1203 committed May 2, 2024
1 parent 386dc4f commit 8a762b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions magnum_cluster_api/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from oslo_log import log as logging
from oslo_utils import strutils

from magnum_cluster_api import clients, hacks, objects, utils
from magnum_cluster_api import clients, hacks, objects, sync, utils

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -78,5 +78,5 @@ def poll_health_status(self):
self.data["health_status"] = fields.ClusterHealthStatus.HEALTHY

self.poll_nodegroup_replicas()

hacks.set_certificate_expiry_days(k8s_api)
with sync.TaskLock("set_certificate_expiry_days"):
hacks.set_certificate_expiry_days(k8s_api)
21 changes: 21 additions & 0 deletions magnum_cluster_api/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,24 @@ def __init__(self, cluster_id: str, expire: int = DEFAULT_EXPIRE):
k8s_namespace="magnum-system",
expire=expire,
)


class TaskLock(sherlock.KubernetesLock):
"""
A task lock that is used to lock for a certain task across all of
the conductor nodes.
"""

DEFAULT_EXPIRE: int = 60

def __init__(self, task_id: str, expire: int = DEFAULT_EXPIRE):
sherlock.configure(
backend=sherlock.backends.KUBERNETES,
retry_interval=1,
)

super().__init__(
lock_name="task-%s" % task_id,
k8s_namespace="magnum-system",
expire=expire,
)

0 comments on commit 8a762b1

Please sign in to comment.