Wrap CSI lister access in a nil check

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
This commit is contained in:
Nolan Brubaker
2020-04-16 15:28:29 -04:00
parent b4e18b489c
commit 15d4c11305

View File

@@ -551,18 +551,22 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error {
if features.IsEnabled("EnableCSI") { if features.IsEnabled("EnableCSI") {
selector := labels.SelectorFromSet(map[string]string{velerov1api.BackupNameLabel: backup.Name}) selector := labels.SelectorFromSet(map[string]string{velerov1api.BackupNameLabel: backup.Name})
// TODO(nrb-csi): Only run listers methods if the listers aren't nil, just in case // Listers are wrapped in a nil check out of caution, since they may not be populated based on the
volumeSnapshots, err = c.volumeSnapshotLister.List(selector) // EnableCSI feature flag. This is more to guard against programmer error, as they shouldn't be nil
if err != nil { // when EnableCSI is on.
//TODO: Is this right? if c.volumeSnapshotLister != nil {
backupLog.Error(err) volumeSnapshots, err = c.volumeSnapshotLister.List(selector)
if err != nil {
backupLog.Error(err)
}
} }
// Currently, VSCs are not being labelled in the plugin, so none will be returned here.
volumeSnapshotContents, err = c.volumeSnapshotContentLister.List(selector)
if err != nil {
//TODO: Is this right?
backupLog.Error(err)
if c.volumeSnapshotContentLister != nil {
volumeSnapshotContents, err = c.volumeSnapshotContentLister.List(selector)
if err != nil {
backupLog.Error(err)
}
} }
} }