-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
5aa69ce
to
07addee
Compare
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>
de0cbae
to
b4a15d8
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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.
labelLocalBackupTargetPVCUID = "local-backup-target-pvc-uid" | ||
labelRemoteBackupTargetPVCUID = "remote-backup-target-pvc-uid" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
|
||
// Call CreateOrUpdatePVC | ||
client := r.primarySettings.Client | ||
respPVC, err := client.CreateOrUpdatePVC( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
respPVC, err := client.CreateOrUpdatePVC( | |
resp, err := client.CreateOrUpdatePVC( |
Because the response of CreateOrUpdatePVC
does not contain PVC's full definition. It only contains uid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0b44995
test/e2e/multik8s/suite_test.go
Outdated
return errors.New("finalizer not found") | ||
} | ||
if mb.Labels == nil || | ||
mb.Labels["local-backup-target-pvc-uid"] != string(secondaryPVC.GetUID()) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mb.Labels["local-backup-target-pvc-uid"] != string(secondaryPVC.GetUID()) && | |
mb.Labels["local-backup-target-pvc-uid"] != string(secondaryPVC.GetUID()) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0b44995
test/e2e/multik8s/suite_test.go
Outdated
return err | ||
} | ||
|
||
mb, err := getMB(secondaryK8sCluster, namespace, backupName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mb, err := getMB(secondaryK8sCluster, namespace, backupName) | |
secondaryMB, err := getMB(secondaryK8sCluster, namespace, backupName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0b44995
internal/controller/replication.go
Outdated
} | ||
|
||
if backupReceived.Labels == nil || backupReceived.Annotations == nil { | ||
return nil, fmt.Errorf("received MantleBackup is invalid: %s: %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0b44995
internal/controller/replication.go
Outdated
// Make sure the remote-uids are equal. | ||
errMsg := "" | ||
if pvc.Annotations == nil { | ||
errMsg = "annotation is nil in pvc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errMsg = "annotation is nil in pvc" | |
errMsg = "annotations field is nil in pvc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0b44995
internal/controller/replication.go
Outdated
if !backup.CreationTimestamp.IsZero() { | ||
errMsg := "" | ||
if backup.Labels == nil { | ||
errMsg = "label not found" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errMsg = "label not found" | |
errMsg = "labes field is in in backup" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0b44995
internal/controller/replication.go
Outdated
} | ||
|
||
if backup.Annotations == nil { | ||
errMsg = "annotation is nil in backup" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errMsg = "annotation is nil in backup" | |
errMsg = "annotation field is nil in backup" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 6cb0005
f0ad64a
to
95d7d5c
Compare
@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. |
There was a problem hiding this 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>
95d7d5c
to
17ea4f2
Compare
No description provided.