Skip to content

Commit

Permalink
Remove "primary" label on losing leadership
Browse files Browse the repository at this point in the history
  • Loading branch information
yuha0 committed Jan 28, 2024
1 parent c6cd4d1 commit d024064
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cloudflare-ddns/leaderelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ def _get_namespace(self):
def _prepare_callback(self, isleader, cb):
def wrapper():
logging.info("I am %s", "the leader" if isleader else "a follower")
patches = [
{
"op": "replace",
"path": "/metadata/labels/primary",
"value": str(isleader).lower(),
}
]
if isleader:
patches = [
{
"op": "replace",
"path": "/metadata/labels/primary",
"value": "true",
}
]
else:
patches = [
{
"op": "remove",
"path": "/metadata/labels/primary",
}
]
self.kclient.patch_namespaced_pod(self.candidate_id, self.ns, body=patches)
cb()

Expand Down

0 comments on commit d024064

Please sign in to comment.