From 859eaf82b0bfc198e722ed6592691737a783c74b Mon Sep 17 00:00:00 2001 From: Arsenii Pastushenko Date: Fri, 23 Oct 2020 16:28:32 +0300 Subject: [PATCH] Reset replication on master after failover --- Changelog.md | 1 + pkg/controller/orchestrator/orchestrator_reconcile.go | 4 ++++ pkg/orchestrator/fake/client.go | 5 +++++ pkg/orchestrator/orchestrator.go | 9 +++++++++ 4 files changed, 19 insertions(+) diff --git a/Changelog.md b/Changelog.md index 474cbb07b..35ac65317 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * Update k8s client to `v0.18.2` * Update kubebuilder (to `v2.3.1`) along with controller-runtime (to `v0.6.0`) and controller-gen * Update rclone to `v1.52.3` + * Operator will now reset replication on master after failover ### Removed ### Fixed * Fix pod labels diff of map diff --git a/pkg/controller/orchestrator/orchestrator_reconcile.go b/pkg/controller/orchestrator/orchestrator_reconcile.go index 8a96e1a40..263dbfbee 100644 --- a/pkg/controller/orchestrator/orchestrator_reconcile.go +++ b/pkg/controller/orchestrator/orchestrator_reconcile.go @@ -293,6 +293,10 @@ func (ou *orcUpdater) updateClusterFailoverInProgressStatus(master *orc.Instance if master != nil && master.SecondsSinceLastSeen.Valid && master.SecondsSinceLastSeen.Int64 < 5 { ou.cluster.UpdateStatusCondition(api.ClusterConditionFailoverInProgress, core.ConditionFalse, "ClusterMasterHealthy", "Master is healthy in orchestrator") + + if err := ou.orcClient.ResetReplication(master.Key); err != nil { + ou.log.Error(err, "Error resetting master replication!") + } } } diff --git a/pkg/orchestrator/fake/client.go b/pkg/orchestrator/fake/client.go index f4e49c1fa..6a243a5db 100644 --- a/pkg/orchestrator/fake/client.go +++ b/pkg/orchestrator/fake/client.go @@ -348,3 +348,8 @@ func (o *OrcFakeClient) EndMaintenance(key InstanceKey) error { func (o *OrcFakeClient) Maintenance() ([]Maintenance, error) { return nil, nil } + +// ResetReplication resets replication on a node +func (o *OrcFakeClient) ResetReplication(key InstanceKey) error { + return nil +} diff --git a/pkg/orchestrator/orchestrator.go b/pkg/orchestrator/orchestrator.go index 239a92428..0b485ed10 100644 --- a/pkg/orchestrator/orchestrator.go +++ b/pkg/orchestrator/orchestrator.go @@ -39,6 +39,8 @@ type Interface interface { BeginMaintenance(key InstanceKey, owner, reason string) error EndMaintenance(key InstanceKey) error Maintenance() ([]Maintenance, error) + + ResetReplication(key InstanceKey) error } type orchestrator struct { @@ -154,3 +156,10 @@ func (o *orchestrator) Maintenance() ([]Maintenance, error) { return maintenances, nil } + +func (o *orchestrator) ResetReplication(key InstanceKey) error { + if err := o.makeGetAPIRequest(fmt.Sprintf("reset-slave/%s/%d", key.Hostname, key.Port), nil); err != nil { + return err + } + return nil +}