From aa44cf1c32d570db517b7ea285479234c4b6c15f Mon Sep 17 00:00:00 2001 From: Scott Seago Date: Wed, 15 Jan 2020 12:06:16 -0500 Subject: [PATCH] Check for nil LastMaintenanceTime in dueForMaintenance (#2200) * Check for nil LastMaintenanceTime in dueForMaintenance ResticRepository.dueForMaintenance causes a panic in the velero pod ("invalid memory address or nil pointer dereference") if repository.Status.LastMaintenanceTime is nil. This fix returns 'true' if it's nil, so the repository is due for maintenance if LastMaintenanceTime is nil *or* the time elapsed since the last maintenance is greater than repository.Spec.MaintenanceFrequency.Duration Signed-off-by: Scott Seago * changelog for PR#2200 Signed-off-by: Scott Seago --- changelogs/unreleased/2200-sseago | 1 + pkg/controller/restic_repository_controller.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/2200-sseago diff --git a/changelogs/unreleased/2200-sseago b/changelogs/unreleased/2200-sseago new file mode 100644 index 000000000..5b3569d89 --- /dev/null +++ b/changelogs/unreleased/2200-sseago @@ -0,0 +1 @@ +Bug fix: Check for nil LastMaintenanceTime in ResticRepository dueForMaintenance diff --git a/pkg/controller/restic_repository_controller.go b/pkg/controller/restic_repository_controller.go index dce0fa46d..ccc7db630 100644 --- a/pkg/controller/restic_repository_controller.go +++ b/pkg/controller/restic_repository_controller.go @@ -243,7 +243,7 @@ func (c *resticRepositoryController) runMaintenanceIfDue(req *v1.ResticRepositor } func dueForMaintenance(req *v1.ResticRepository, now time.Time) bool { - return req.Status.LastMaintenanceTime.Add(req.Spec.MaintenanceFrequency.Duration).Before(now) + return req.Status.LastMaintenanceTime == nil || req.Status.LastMaintenanceTime.Add(req.Spec.MaintenanceFrequency.Duration).Before(now) } func (c *resticRepositoryController) checkNotReadyRepo(req *v1.ResticRepository, log logrus.FieldLogger) error {