Skip to content

Commit

Permalink
Check for nil LastMaintenanceTime in dueForMaintenance (vmware-tanzu#…
Browse files Browse the repository at this point in the history
…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 <sseago@redhat.com>

* changelog for PR#2200

Signed-off-by: Scott Seago <sseago@redhat.com>
  • Loading branch information
sseago authored and nrb committed Jan 15, 2020
1 parent b2acd3b commit aa44cf1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelogs/unreleased/2200-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fix: Check for nil LastMaintenanceTime in ResticRepository dueForMaintenance
2 changes: 1 addition & 1 deletion pkg/controller/restic_repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa44cf1

Please sign in to comment.