Skip to content

Commit

Permalink
Don't crash when upgrading volume attachments after a previous failure
Browse files Browse the repository at this point in the history
Longhorn 6653

Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber authored and PhanLe1010 committed Oct 27, 2023
1 parent 2d14e40 commit a4a8d31
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions upgrade/v14xto150/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ func upgradeVolumeAttachments(namespace string, lhClient *lhclientset.Clientset,
return errors.Wrapf(err, "failed to list all share manager during the Longhorn VolumeAttachment upgrade")
}

// We don't expect any volume attachments to exist when upgrading from v1.4.x to v1.5.0. However, we could be
// walking the upgrade path again after a failure.
volumeAttachmentMap, err := upgradeutil.ListAndUpdateVolumeAttachmentsInProvidedCache(namespace, lhClient, resourceMaps)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "failed to list all existing Longhorn VolumeAttachments during the Longhorn VolumeAttachment upgrade")
}

kubeVAMap := map[string][]storagev1.VolumeAttachment{}
for _, va := range kubeVAList.Items {
if va.Spec.Source.PersistentVolumeName != nil {
Expand All @@ -157,8 +167,11 @@ func upgradeVolumeAttachments(namespace string, lhClient *lhclientset.Clientset,
smMap[sm.Name] = sm
}

volumeAttachments := map[string]*longhorn.VolumeAttachment{}
for _, v := range volumeList.Items {
if _, ok := volumeAttachmentMap[types.GetLHVolumeAttachmentNameFromVolumeName(v.Name)]; ok {
continue // We handled this one on a previous upgrade attempt.
}

va := longhorn.VolumeAttachment{
ObjectMeta: metav1.ObjectMeta{
Name: types.GetLHVolumeAttachmentNameFromVolumeName(v.Name),
Expand All @@ -169,11 +182,9 @@ func upgradeVolumeAttachments(namespace string, lhClient *lhclientset.Clientset,
Volume: v.Name,
},
}
volumeAttachments[va.Name] = &va
volumeAttachmentMap[va.Name] = &va
}

resourceMaps[types.LonghornKindVolumeAttachment] = volumeAttachments

return nil
}

Expand Down

0 comments on commit a4a8d31

Please sign in to comment.