Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: prevent location-only pod updates #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion patroni/dcs/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ..exceptions import DCSError
from ..postgresql.mpp import AbstractMPP
from ..utils import deep_compare, iter_response_objects, keepalive_socket_options, \
Retry, RetryFailedError, tzutc, uri, USER_AGENT
parse_bool, Retry, RetryFailedError, tzutc, uri, USER_AGENT
if TYPE_CHECKING: # pragma: no cover
from ..config import Config

Expand Down Expand Up @@ -758,6 +758,8 @@ def __init__(self, config: Dict[str, Any], mpp: AbstractMPP) -> None:
self._standby_leader_label_value = config.get('standby_leader_label_value', 'master')
self._tmp_role_label = config.get('tmp_role_label')
self._ca_certs = os.environ.get('PATRONI_KUBERNETES_CACERT', config.get('cacert')) or SERVICE_CERT_FILENAME
self._prevent_xlog_position_only_pod_updates = bool(
parse_bool(config.get('prevent_xlog_position_only_pod_updates')))
super(Kubernetes, self).__init__({**config, 'namespace': ''}, mpp)
if self._mpp.is_enabled():
self._labels[self._mpp.k8s_group_label] = str(self._mpp.group)
Expand Down Expand Up @@ -1321,11 +1323,19 @@ def touch_member(self, data: Dict[str, Any]) -> bool:

member = cluster and cluster.get_member(self._name, fallback_to_leader=False)
pod_labels = member and member.data.pop('pod_labels', None)
# XXX: add a parameter here
saved_xlog_location = data.get('xlog_location')
if self._prevent_xlog_position_only_pod_updates and saved_xlog_location is not None:
# avoid updating if the only change is the xlog location
if member and member.data.get('xlog_location') is not None:
data['xlog_location'] = member.data['xlog_location']
ret = member and pod_labels is not None\
and all(pod_labels.get(k) == v for k, v in role_labels.items())\
and deep_compare(data, member.data)

if not ret:
# we decided to update anyway, set back the xlog location
data['xlog_location'] = saved_xlog_location
metadata = {'namespace': self._namespace, 'name': self._name, 'labels': role_labels,
'annotations': {'status': json.dumps(data, separators=(',', ':'))}}
body = k8s_client.V1Pod(metadata=k8s_client.V1ObjectMeta(**metadata))
Expand Down
1 change: 1 addition & 0 deletions patroni/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ def validate_watchdog_mode(value: Any) -> None:
Optional("ports"): [{"name": str, "port": IntValidator(max=65535, expected_type=int, raise_assert=True)}],
Optional("cacert"): str,
Optional("retriable_http_codes"): Or(int, [int]),
Optional('prevent_xlog_position_only_pod_updates'): bool
},
}),
Optional("citus"): {
Expand Down
Loading