Skip to content

Commit

Permalink
k8s probe: Fix a panic (nil pointer deref) when a cronjob has never b…
Browse files Browse the repository at this point in the history
…een scheduled

in which case cj.Status.LastScheduled is nil.
New behaviour is to omit it from the map (and therefore the display) if it has never been scheduled.
  • Loading branch information
ekimekim committed Aug 1, 2017
1 parent 5744191 commit 1d47a06
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions probe/kubernetes/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ func (cj *cronJob) Selectors() ([]labels.Selector, error) {
}

func (cj *cronJob) GetNode() report.Node {
return cj.MetaNode(report.MakeCronJobNodeID(cj.UID())).WithLatests(map[string]string{
NodeType: "CronJob",
Schedule: cj.Spec.Schedule,
Suspended: fmt.Sprint(cj.Spec.Suspend != nil && *cj.Spec.Suspend), // nil -> false
LastScheduled: cj.Status.LastScheduleTime.Format(time.RFC3339Nano),
ActiveJobs: fmt.Sprint(len(cj.jobs)),
})
latest := map[string]string{
NodeType: "CronJob",
Schedule: cj.Spec.Schedule,
Suspended: fmt.Sprint(cj.Spec.Suspend != nil && *cj.Spec.Suspend), // nil -> false
ActiveJobs: fmt.Sprint(len(cj.jobs)),
}
if cj.Status.LastScheduleTime != nil {
latest[LastScheduled] = cj.Status.LastScheduleTime.Format(time.RFC3339Nano)
}
return cj.MetaNode(report.MakeCronJobNodeID(cj.UID())).WithLatests(latest)
}

0 comments on commit 1d47a06

Please sign in to comment.