From d6c60b2dd5cefbe985f69b98d79ef0a66dcf33de Mon Sep 17 00:00:00 2001 From: Adnan Abdulhussein Date: Mon, 10 Jun 2019 10:04:52 -0700 Subject: [PATCH] fix panic when processing DeleteBackupRequest objs without labels (#1556) This fix initialises an empty map if the request object's Labels map is nil, allowing the controller to later add and modify labels on the object. Signed-off-by: Adnan Abdulhussein --- changelogs/unreleased/1556-prydonius | 1 + pkg/controller/backup_deletion_controller.go | 6 ++++++ pkg/controller/backup_deletion_controller_test.go | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/1556-prydonius diff --git a/changelogs/unreleased/1556-prydonius b/changelogs/unreleased/1556-prydonius new file mode 100644 index 000000000..41e4d0ab5 --- /dev/null +++ b/changelogs/unreleased/1556-prydonius @@ -0,0 +1 @@ +fix panic when processing DeleteBackupRequest objects without labels diff --git a/pkg/controller/backup_deletion_controller.go b/pkg/controller/backup_deletion_controller.go index 7c648f3a9..8afac7006 100644 --- a/pkg/controller/backup_deletion_controller.go +++ b/pkg/controller/backup_deletion_controller.go @@ -229,6 +229,12 @@ func (c *backupDeletionController) processRequest(req *v1.DeleteBackupRequest) e return err } + // if the request object has no labels defined, initialise an empty map since + // we will be updating labels + if req.Labels == nil { + req.Labels = map[string]string{} + } + // Update status to InProgress and set backup-name label if needed req, err = c.patchDeleteBackupRequest(req, func(r *v1.DeleteBackupRequest) { r.Status.Phase = v1.DeleteBackupRequestPhaseInProgress diff --git a/pkg/controller/backup_deletion_controller_test.go b/pkg/controller/backup_deletion_controller_test.go index 90b02a40d..12eb9a8b8 100644 --- a/pkg/controller/backup_deletion_controller_test.go +++ b/pkg/controller/backup_deletion_controller_test.go @@ -460,8 +460,10 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) { } require.NoError(t, td.sharedInformers.Velero().V1().VolumeSnapshotLocations().Informer().GetStore().Add(snapshotLocation)) - // Clear out req labels to make sure the controller adds them - td.req.Labels = make(map[string]string) + // Clear out req labels to make sure the controller adds them and does not + // panic when encountering a nil Labels map + // (https://github.com/heptio/velero/issues/1546) + td.req.Labels = nil td.client.PrependReactor("get", "backups", func(action core.Action) (bool, runtime.Object, error) { return true, backup, nil