Skip to content

Commit

Permalink
feat: add replace_existing_checks option to agent.service.register()
Browse files Browse the repository at this point in the history
- Introduced `replace_existing_checks` parameter in the `register()` method to allow deletion of missing health checks from the request.
- Ensures idempotent registration of services and their checks without needing manual deregistration of checks.
  • Loading branch information
cpaillet committed Oct 1, 2024
1 parent 1601ee3 commit d62c1bf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions consul/api/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def register(
timeout=None,
enable_tag_override=False,
extra_checks=None,
replace_existing_checks=False,
):
"""
Add a new service to the local agent. There is more
Expand Down Expand Up @@ -184,6 +185,11 @@ def register(
*script*, *interval*, *ttl*, *http*, and *timeout* arguments
are deprecated. use *check* instead.
*replace_existing_checks* Missing health checks from the request will
be deleted from the agent.
Using this parameter allows to idempotently register a service and its
checks without having to manually deregister checks.
*enable_tag_override* is an optional bool that enable you
to modify a service tags from servers(consul agent role server)
Default is set to False.
Expand Down Expand Up @@ -214,15 +220,15 @@ def register(
payload["checks"] = [check] + extra_checks
if weights:
payload["weights"] = weights

else:
payload.update(
Check._compat( # pylint: disable=protected-access
script=script, interval=interval, ttl=ttl, http=http, timeout=timeout
)
)

params = []
if replace_existing_checks:
params.append(("replace-existing-checks", "true"))
headers = self.agent.prepare_headers(token)
return self.agent.http.put(
CB.bool(), "/v1/agent/service/register", params=params, headers=headers, data=json.dumps(payload)
Expand Down

0 comments on commit d62c1bf

Please sign in to comment.