Skip to content

Commit

Permalink
Merge pull request kubevirt#10903 from fossedihelm/vmclone_fix_override
Browse files Browse the repository at this point in the history
fix(vmclone): avoid override variables with returning obj
  • Loading branch information
kubevirt-bot authored Dec 24, 2023
2 parents e674749 + cacb7b3 commit 465b7ae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/virt-controller/watch/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (ctrl *VMCloneController) createSnapshotFromVm(vmClone *clonev1alpha1.Virtu
snapshot := generateSnapshot(vmClone, vm)
syncInfo.logger.Infof("creating snapshot %s for clone %s", snapshot.Name, vmClone.Name)

snapshot, err := ctrl.client.VirtualMachineSnapshot(snapshot.Namespace).Create(context.Background(), snapshot, v1.CreateOptions{})
createdSnapshot, err := ctrl.client.VirtualMachineSnapshot(snapshot.Namespace).Create(context.Background(), snapshot, v1.CreateOptions{})
if err != nil {
if !errors.IsAlreadyExists(err) {
return snapshot, addErrorToSyncInfo(syncInfo, fmt.Errorf("failed creating snapshot %s for clone %s: %v", snapshot.Name, vmClone.Name, err))
Expand All @@ -368,6 +368,7 @@ func (ctrl *VMCloneController) createSnapshotFromVm(vmClone *clonev1alpha1.Virtu
return snapshot, syncInfo
}

snapshot = createdSnapshot
ctrl.logAndRecord(vmClone, SnapshotCreated, fmt.Sprintf("created snapshot %s for clone %s", snapshot.Name, vmClone.Name))
syncInfo.snapshotName = snapshot.Name

Expand Down Expand Up @@ -419,7 +420,7 @@ func (ctrl *VMCloneController) createRestoreFromVm(vmClone *clonev1alpha1.Virtua
patches := generatePatches(vm, &vmClone.Spec)
restore := generateRestore(vmClone.Spec.Target, vm.Name, vmClone.Namespace, vmClone.Name, snapshotName, vmClone.UID, patches)
syncInfo.logger.Infof("creating restore %s for clone %s", restore.Name, vmClone.Name)
restore, err := ctrl.client.VirtualMachineRestore(restore.Namespace).Create(context.Background(), restore, v1.CreateOptions{})
createdRestore, err := ctrl.client.VirtualMachineRestore(restore.Namespace).Create(context.Background(), restore, v1.CreateOptions{})
if err != nil {
if !errors.IsAlreadyExists(err) {
return addErrorToSyncInfo(syncInfo, fmt.Errorf("failed creating restore %s for clone %s: %v", restore.Name, vmClone.Name, err))
Expand All @@ -428,7 +429,7 @@ func (ctrl *VMCloneController) createRestoreFromVm(vmClone *clonev1alpha1.Virtua
return syncInfo

}

restore = createdRestore
ctrl.logAndRecord(vmClone, RestoreCreated, fmt.Sprintf("created restore %s for clone %s", restore.Name, vmClone.Name))
syncInfo.restoreName = restore.Name

Expand Down

0 comments on commit 465b7ae

Please sign in to comment.