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

support replication of MantleBackup and PVC objects #37

Merged
merged 13 commits into from
Sep 12, 2024

Conversation

ushitora-anqou
Copy link
Contributor

No description provided.

@ushitora-anqou ushitora-anqou force-pushed the support-repl-of-mb-and-pvc-objects branch from 5aa69ce to 07addee Compare September 6, 2024 02:49
This commit changes the type of MantleBackup's SnapID field from int to
*int so that we can check if the value is missing or is zero.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
This commit avoid skipping MantleBackup's reconciliation early when
ReadyToUse is true, so that we can make sure that replication process is
performed even when the reconciliation is retried for some reasons after
ReadyToUse becomes true.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
The current implementation updates MantleBackup's status without getting
its present content. Thus, if we try to update MantleBackup's status several
times in one reconciliation iteration, we fail to do so because its
resourceVersion field is invalid in the second update.

In order to resolve the problem above, this commit introduces a new
function named updateMantleBackupStatus. It not only gets the status
every time before updating it, but also allows us to update it in a
similiar manner to ctrl.CreateOrUpdate.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
…hotting

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
@ushitora-anqou ushitora-anqou force-pushed the support-repl-of-mb-and-pvc-objects branch 2 times, most recently from de0cbae to b4a15d8 Compare September 10, 2024 06:14
@ushitora-anqou ushitora-anqou marked this pull request as ready for review September 10, 2024 07:24
Copy link
Contributor

@satoru-takeuchi satoru-takeuchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewd 6 commits. I'll let you know after finishing the remaining review of two commits.

@@ -105,8 +113,10 @@ func executeCommandImpl(command []string, input io.Reader) ([]byte, error) {
var executeCommand = executeCommandImpl

func (r *MantleBackupReconciler) updateStatus(ctx context.Context, backup *mantlev1.MantleBackup, condition metav1.Condition) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming this function to updateStatusCondition and updateMantleBackupStatus to updateStatus? It's a bit complicated to understand why both updateStatus() and updateMantleBackupStatus are for updating MantleBackup.status and the former calls the latter inside it. By the above mentioned renaming, the purpose of both function will be clear. The new UpdateStatus is to update any fields of status. On the other hand, updateStatusCondition is only to update status.conditions.

Copy link
Contributor Author

@ushitora-anqou ushitora-anqou Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this in the following commits:
4c40f2b
7e21cad

@@ -332,10 +332,6 @@ func (r *MantleBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{Requeue: true}, nil
}

if cond := meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse); cond != nil && cond.Status == metav1.ConditionTrue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about create a new function for snapshot creation and call this only if conditions["ReadyToUse"] is "True"? It improved the readbility of Reconcile. In addition, we can reduce the number of k8s API calls and RBD command executions.

Copy link
Contributor Author

@ushitora-anqou ushitora-anqou Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the following commits:
8a27991
eda8e4c

Copy link
Contributor

@satoru-takeuchi satoru-takeuchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read all commits in your first version.

Comment on lines 28 to 29
labelLocalBackupTargetPVCUID = "local-backup-target-pvc-uid"
labelRemoteBackupTargetPVCUID = "remote-backup-target-pvc-uid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the prefix, "mantle.cybozu.io/", before both label names (like "mantle.cybozu.io/local-backup-target-pvc-uid")? It is to apply unique name to the mantle-related labels.

Copy link
Contributor Author

@ushitora-anqou ushitora-anqou Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the following commits:

0b44995


// Call CreateOrUpdatePVC
client := r.primarySettings.Client
respPVC, err := client.CreateOrUpdatePVC(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
respPVC, err := client.CreateOrUpdatePVC(
resp, err := client.CreateOrUpdatePVC(

Because the response of CreateOrUpdatePVC does not contain PVC's full definition. It only contains uid.

Copy link
Contributor Author

@ushitora-anqou ushitora-anqou Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

return errors.New("finalizer not found")
}
if mb.Labels == nil ||
mb.Labels["local-backup-target-pvc-uid"] != string(secondaryPVC.GetUID()) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mb.Labels["local-backup-target-pvc-uid"] != string(secondaryPVC.GetUID()) &&
mb.Labels["local-backup-target-pvc-uid"] != string(secondaryPVC.GetUID()) ||

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

return err
}

mb, err := getMB(secondaryK8sCluster, namespace, backupName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mb, err := getMB(secondaryK8sCluster, namespace, backupName)
secondaryMB, err := getMB(secondaryK8sCluster, namespace, backupName)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

}

if backupReceived.Labels == nil || backupReceived.Annotations == nil {
return nil, fmt.Errorf("received MantleBackup is invalid: %s: %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("received MantleBackup is invalid: %s: %s",
return nil, fmt.Errorf("both labels and annotations must not be nil in the received MantleBackup: %s: %s",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

// Make sure the remote-uids are equal.
errMsg := ""
if pvc.Annotations == nil {
errMsg = "annotation is nil in pvc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errMsg = "annotation is nil in pvc"
errMsg = "annotations field is nil in pvc"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

if !backup.CreationTimestamp.IsZero() {
errMsg := ""
if backup.Labels == nil {
errMsg = "label not found"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errMsg = "label not found"
errMsg = "labes field is in in backup"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

}

if backup.Annotations == nil {
errMsg = "annotation is nil in backup"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errMsg = "annotation is nil in backup"
errMsg = "annotation field is nil in backup"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b44995

}
}

// Attach local-backup-target-pvc-uid label
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you enrich the comment to let reads to know this CreateOrUpdate is to assure that snapshot corresponding to the MantleBackup only exists iff local-backup-target-pvc-uid is applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 95d7d5c

_, ok2 := backup.Labels[labelRemoteBackupTargetPVCUID]
if ok1 && ok2 {
logger.Warn(
"skipping to reconcile the MantleBackup because it has both local/remote-backup-target-pvc-uid labels",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"skipping to reconcile the MantleBackup because it has both local/remote-backup-target-pvc-uid labels",
"skipping to reconcile the MantleBackup created by a remote mantle-controller to prevent accidental data loss",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6cb0005

@ushitora-anqou ushitora-anqou force-pushed the support-repl-of-mb-and-pvc-objects branch from f0ad64a to 95d7d5c Compare September 12, 2024 04:58
@ushitora-anqou
Copy link
Contributor Author

@satoru-takeuchi I've fixed your points, so could you review this PR again? Note that we need to squash my commits before merging this PR, so please do not merge this even if there are no flaws.

Copy link
Contributor

@satoru-takeuchi satoru-takeuchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTGM. Please squash commits.

This commit introduces a functionality of replicating PVC and
MantleBackup resources. Also, it adds some e2e tests to make sure that
the replication works correctly.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
In the current implementation, the ctrl.Result value returned from
MantleBackupReconciler.createRBDSnapshot is useless, because:

- the ctrl.Result value is used only if the err value is not nil.
- the ctrl.Result value equals ctrl.Result{} whenever the err value is
  not nil.

This commit stops returning the value. We can use ctrl.Result{} instead.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
@ushitora-anqou ushitora-anqou force-pushed the support-repl-of-mb-and-pvc-objects branch from 95d7d5c to 17ea4f2 Compare September 12, 2024 07:07
@satoru-takeuchi satoru-takeuchi merged commit ced1d71 into main Sep 12, 2024
3 checks passed
@satoru-takeuchi satoru-takeuchi deleted the support-repl-of-mb-and-pvc-objects branch September 12, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants